尝试按照GIL的设计指南工作,我bits__用于我的频道数据类型.我经常将外部数据包装到GIL图像视图中.但是,即使使用bits__数据指针的类型,我也必须在我创建图像视图之前添加reinterpret_cast.请使用以下代码
int width = 3;
int height = 2;
boost::gil::bits8 data8[] = {0, 1, 100, 200, 50, 51};
boost::gil::bits8* pBits8 = data8;
boost::gil::gray8_ptr_t pGray8 = pBits8;
boost::gil::gray8_view_t v = interleaved_view(width, height, pGray8, width * sizeof(boost::gil::bits8));
Run Code Online (Sandbox Code Playgroud)
导致第6行的错误"错误C2440:'初始化':无法从'boost :: gil :: bits8*'转换为'boost :: gil :: gray8_ptr_t'1>指向的类型不相关;转换需要reinterpret_cast, C风格演员或功能风格演员阵容"
尽可能多地深入研究源代码,看起来这些类型确实是未发布的.bits8只是unsigned char,但是gray8_ptr_t指向a的指针struct pixel<bits8,gray_layout_t>.这个结构的唯一元素是单个bit8,因此reinterpret_cast看起来很安全.它也适用于我抛出的测试.
但是,我经常将外部数据包装到图像视图中,并且在每个地方都进行reinterpret_cast会产生问题.有没有更安全的方法来构建用于GIL的像素指针?
目前的解决方法:
template<class Dest, class Src>
Dest gil_safe_ptr_cast(Src src)
{
// this cast is unsafe, use reinterpret_cast
BOOST_STATIC_ASSERT(false);
}
template<> boost::gil::gray8_ptr_t gil_safe_ptr_cast(boost::gil::bits8* …Run Code Online (Sandbox Code Playgroud) C++标准库将数据结构与算法分开,例如std::sort:
template< class RandomAccessIterator >
void sort( RandomAccessIterator first, RandomAccessIterator last );
Run Code Online (Sandbox Code Playgroud)
当算法需要中间临时空间时,我想保持算法和数据结构的分离.
考虑到这一目标,我想实现一种图像算法,该算法需要输入和输出图像之间的中间划痕空间.可以在函数调用中分配必要的临时空间,但是由于具有相同大小的图像的这些调用的大小和频率,将严重降低性能.这使得将数据结构与算法分离变得更加困难.
实现此目的的一种可能方法如下:
// Algorithm function
template<typename InputImageView, typename OutputImageView, typename ScratchView>
void algorithm(
InputImageView inputImageView,
OutputImageView outputImageView,
ScratchView scratchView
);
// Algorithm class with scratch space
template<typename DataStructure>
class Algorithm {
public:
template<typename InputImageView,typename OutputImageView>
void operator()(
InputImageView inputImageView,
OutputImageView outputImageView
){
m_scratch.resize(inputImageView.size());
algorithm(inputImageView,outputImageView,makeView(m_scratch));
}
private:
DataStructure m_scratch;
}
Run Code Online (Sandbox Code Playgroud)
上面是一个有效的算法+划痕空间设计可以遵循,还是有更好的方法?
旁注:我正在使用boost :: gil库
我一直在尝试阅读boost :: gil文档,但它介于缺乏和复杂之间.
暂且不谈,我需要一个如何执行以下操作的示例:
创建一个512x512的图像.用红色像素填充.写信给PNG.
在gil的文档中,我找不到任何关于做任何这些的事情.特别是创建图像或用像素部分填充它.
如果有人可以提供帮助,谢谢.
#include <boost/gil/gil_all.hpp>
#include <boost/gil/extension/io/jpeg_io.hpp>
int main()
{
using namespace boost::gil;
rgb8_image_t img;
jpeg_read_image("test.jpg",img);
}
Run Code Online (Sandbox Code Playgroud)
我将$ BOOST_ROOT包含在VS 2010项目属性中 - > C/C++ - >常规 - >其他包含目录.
http://www.richelbilderbeek.nl/CppCompileErrorJpeglibHnoSuchFileOrDirectory.htm中定义了相同的错误, 但声明的解决方案无法解决我的问题.
我需要在(离屏)图像上绘制一些线条.我想使用boost :: gil,因为lib已经集成在我的项目中.
我想在2dim数组中从头到尾绘制一条线
任何人都可以给我一个快速的例子,说明如何使用gil绘制一条线?
谢谢.
所以我看到样本四处都保存到文件中.但我想知道是否可以保存到char*或字符串而不是文件 - 所以说保留在内存中?
我正在尝试转向 Boost GIL 以替换我已经实现的一些类似的功能,这些功能即将结束其可维护的生命周期。
我有使用uint8_t*. 我无法改变这一点,因为相同的接口用于从不同的地方(例如 OpenGL 缓冲区)公开图像,并且已经有很多代码。
因此,我试图以小步骤使用 GIL,首先读取文件并将像素逐字节复制到std::vector<uint8_t>可用于管理存储的 a 中,但仍然uint8_t*通过使用&vector[0].
这可以透明地放在现有接口后面,直到重构有意义为止。
我认为这应该是使用copy_pixels()两个适当构造的视图的简单案例。
我整理了一个最小的、完整的示例,它说明了我通过查看文档和尝试实现的目标的总和:
#include <boost/gil/rgb.hpp>
#include <boost/gil/extension/io/png_dynamic_io.hpp>
#include <stdint.h>
#include <vector>
int main() {
std::vector<uint8_t> storage;
{
using namespace boost::gil;
rgb8_image_t img;
png_read_image("test.png", img);
// what should replace 3 here to be more "generic"?
storage.resize(img.width()*img.height()*3);
// doesn't work, the type of the images aren't compatible.
copy_pixels(const_view(img),
interleaved_view(img.width(), img.height(), &storage[0], 3*img.width()));
}
}
Run Code Online (Sandbox Code Playgroud)
这不编译:
error: cannot …Run Code Online (Sandbox Code Playgroud) 我对GIL语法有点困惑.我想转换
rgb8_image_t
Run Code Online (Sandbox Code Playgroud)
至
rgba8_image_t
Run Code Online (Sandbox Code Playgroud)
并将alpha通道设置为1.是否有任何内置功能.如果不是如何手动执行此操作?
尝试使用Boost :: GIL PNG IO支持编译我的文件时,我总是遇到此错误:
(我正在运行Mac OS X Leopard和Boost 1.42,LibPNG 1.4)
/usr/local/include/boost/gil/extension/io/png_io_private.hpp: In member function 'void boost::gil::detail::png_reader::init()':
/usr/local/include/boost/gil/extension/io/png_io_private.hpp:155: error: 'png_infopp_NULL' was not declared in this scope
/usr/local/include/boost/gil/extension/io/png_io_private.hpp:160: error: 'png_infopp_NULL' was not declared in this scope
/usr/local/include/boost/gil/extension/io/png_io_private.hpp: In destructor 'boost::gil::detail::png_reader::~png_reader()':
/usr/local/include/boost/gil/extension/io/png_io_private.hpp:174: error: 'png_infopp_NULL' was not declared in this scope
/usr/local/include/boost/gil/extension/io/png_io_private.hpp: In member function 'void boost::gil::detail::png_reader::apply(const View&)':
/usr/local/include/boost/gil/extension/io/png_io_private.hpp:186: error: 'int_p_NULL' was not declared in this scope
/usr/local/include/boost/gil/extension/io/png_io_private.hpp: In member function 'void boost::gil::detail::png_reader_color_convert<CC>::apply(const View&)':
/usr/local/include/boost/gil/extension/io/png_io_private.hpp:228: error: 'int_p_NULL' was not declared in this scope …Run Code Online (Sandbox Code Playgroud) 我在搞清楚图像库时遇到了一些麻烦.
我找不到关于如何使用boost :: gil库中包含的interleaved_view函数的任何确切文档.更具体地说,我不确切知道原始数据应该存储在哪种二进制格式中.
我能找到的唯一提到的是在gil教程中:
// Calling with 8-bit RGB data into 16-bit BGR
void XGradientRGB8_BGR16(const unsigned char* src_pixels, ptrdiff_t src_row_bytes, int w, int h,
signed short* dst_pixels, ptrdiff_t dst_row_bytes) {
rgb8c_view_t src = interleaved_view(w,h,(const rgb8_pixel_t*)src_pixels,src_row_bytes);
rgb16s_view_t dst = interleaved_view(w,h,( rgb16s_pixel_t*)dst_pixels,dst_row_bytes);
x_gradient(src,dst);
}
Run Code Online (Sandbox Code Playgroud)
此外,功能原型说
template<typename Iterator>
type_from_x_iterator< Iterator>::view_t
boost::gil::interleaved_view (std::size_t width, std::size_t height, Iterator pixels, std::ptrdiff_t rowsize_in_bytes)
//Constructing image views from raw interleaved pixel data.
Run Code Online (Sandbox Code Playgroud)
我的问题是,gil在二进制格式中期望的格式是什么,以及rowsize_in_bytes应该是什么?
我之前看过交错图像的唯一一次是使用OpenGL,这只是每个像素彼此相邻存储的RGB信息.我认为rowsize_in_bytes只是字面上一行像素的大小,所以我尝试用这样写一个PNG:
void makeImage(const string fileName, const unsigned char * src, const int w, const …Run Code Online (Sandbox Code Playgroud) 我有一个具有透明背景的图像,我想将其复制到另一个图像上,这两个图像都是 png 格式,我尝试使用 boost::gil::rgba8_image_t 但它仍然复制具有灰色背景的透明图像。这就是我用过的
#include <boost/gil.hpp>
#include <boost/gil/extension/io/png.hpp>
#include <boost/gil/extension/numeric/resample.hpp>
#include <boost/gil/extension/numeric/sampler.hpp>
#include <string>
namespace bg = boost::gil;
int main() {
std::string target{"./jail.png"};
std::string picture("./example_in.png");
bg::rgba8_image_t jail;
bg::rgba8_image_t temp;
bg::read_and_convert_image(target, jail, bg::png_tag{});
bg::rgba8_image_t pic(jail.dimensions());
bg::read_and_convert_image(picture, temp, bg::png_tag{});
bg::resize_view(bg::view(temp), bg::view(pic), bg::bilinear_sampler{});
bg::copy_pixels(bg::view(jail), bg::view(pic));
bg::write_view("out.png", bg::view(pic), bg::png_tag{});
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用boost通用图像库将CYMK图像转换为RGB.
以下代码无法编译
// read cmyk image file
cmyk8_image_t img;
jpeg_read_image( "1502-T2-C-PER.jpg", img );
// convert to rgb
rgb8_image_t rgb( img.dimensions() );
copy_pixels(
color_converted_view<rgb8_image_t>(view(img)),
view(rgb));
Run Code Online (Sandbox Code Playgroud)
有人知道怎么修这个东西吗?
我已将此代码基于教程代码
void x_luminosity_gradient(const rgb32fc_view_t& src, const gray8s_view_t& dst) {
gray8_image_t ccv_image(src.dimensions());
copy_pixels(color_converted_view<gray8_pixel_t>(src), view(ccv_image));
Run Code Online (Sandbox Code Playgroud)
这是编译器输出:
1>c:\program files\boost\boost_1_35_0\boost\gil\step_iterator.hpp(164) : error C2664: 'boost::gil::detail::step_iterator_adaptor<Derived,Iterator,SFn>::step_iterator_adaptor(const Iterator &,SFn)' : cannot convert parameter 1 from 'const boost::gil::dereference_iterator_adaptor<Iterator,DFn>' to 'const boost::gil::rgb8_ptr_t &'
1> with
1> [
1> Derived=boost::gil::memory_based_step_iterator<boost::gil::rgb8_ptr_t>,
1> Iterator=boost::gil::rgb8_ptr_t ,
1> SFn=boost::gil::memunit_step_fn<boost::gil::rgb8_ptr_t >
1> ]
1> and
1> [
1> Iterator=boost::gil::cmyk8_ptr_t , …Run Code Online (Sandbox Code Playgroud) 我已经配置了我的环境,以便我可以将适当制作的 .png 文件加载到定义如下的图像中:
boost::gil::rgb8_image_t input;
Run Code Online (Sandbox Code Playgroud)
但如何加载任何典型类型的 png 文件(例如由 GIMP 或 MS Paint 生成的文件)。我认为它需要 boost::gil::any_image 但我不知道我需要配置它的类型。
我试过了:
typedef boost::mpl::vector<
boost::mpl::rgba8_planar_image_t,
boost::mpl::rgba8_image_t,
boost::mpl::rgb8_planar_image_t,
boost::mpl::rgb8_image_t,
boost::mpl::gray8_image_t
> my_img_types;
boost::mpl::any_image<my_img_types> input;
boost::gil::png_read_image(ipath, input);
Run Code Online (Sandbox Code Playgroud)
但这不会加载由 MS Paint 或 GIMP 创建的文件。