【发布时间】:2021-12-30 15:44:37
【问题描述】:
由于 boost::gil 不支持 BMP 格式的 gray8_view_t 写入,我想将 gray8_view_t 转换为 rgb8_view_t。这是我迄今为止尝试过的。
auto rgb_view = boost::gil::planar_rgb_view(width, height, pixels, pixels, pixels, width);
pixels 包含来自 gray8_view_t 对象的原始像素,所以我让 r=g=b=pixels。但是boost::gil::write_view(ofstream, rgb_view, boost::gil::bmp_tag()) 给了我一个空的图像。有什么想法吗?
更新:
通过使用 sehe 的示例代码http://coliru.stacked-crooked.com/a/daa0735f774b727f,我能够使用color_converted_view<gil::rgb8_view_t> 编译颜色对话。但是当我使用boost::gil::write_view 从color_converted_view<gil::rgb8_view_t> 的返回值创建图像文件时,它不会编译。我的猜测是我必须从返回值创建一个实际的 rgb8_image_t 对象。如何将color_converted_view<gil::rgb8_view_t> 的返回值转换为实际的 rgb8_image_t 对象?谢谢!
#include <boost/gil.hpp>
#include <fstream>
namespace gil = boost::gil;
int main()
{
std::ifstream in("gray8_image_t_sample.jpg", std::ios::binary);
gil::gray8_image_t img;
gil::read_image(in, img, gil::jpeg_tag());
gil::gray8_view_t gv = gil::view(img);
std::ofstream ofs1("test_image.png", std::ios::out | std::ios_base::binary);
gil::write_view(ofs1, gv, gil::png_tag()); // This works
auto rgbv = gil::color_converted_view<gil::rgb8_view_t>(gv);
std::ofstream ofs2("test_image.bmp", std::ios::out | std::ios_base::binary);
gil::write_view(ofs2, rgbv, gil::bmp_tag()); // this does not compile
}
我收到的错误消息之一
\boost\gil\color_base_algorithm.hpp(170,76): error G1A4676F8: no member named 'layout_t' in 'boost::gil::image<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mp11::mp_list<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t>, boost::mp11::mp_list<std::integral_constant<int, 0>, std::integral_constant<int, 1>, std::integral_constant<int, 2>>>>, false, std::allocator<unsigned char>>' [clang-diagnostic-error]
【问题讨论】:
-
你试过什么? coliru.stacked-crooked.com/a/daa0735f774b727f 怎么了?
-
其实我是用
gil::any_image_view<gil::gray8_view_t, gil::rgb8_view_t> image_view;来存储图片数据的。我试过auto rgbv = gil::color_converted_view<gil::rgb8_view_t>(image_view);。但是当参数具有 any_image_view 类型时,gil::color_converted_view 不会编译。如何将 any_image_view 转换为 gray8_view_t?我试过 boost::get(image_view) 但它不起作用 -
这是我收到的错误
boost\gil\extension\dynamic_image\image_view_factory.hpp(160,28): error GB4E3CEB1: excess elements in struct initializer [clang-diagnostic-error] return result_type{color_converted_view<DstP>(src, _cc)}; -
使用 any_image_view 会增加您可能不需要的复杂性。本页详细介绍了如何将其与 GIL 算法一起使用:To perform an algorithm on any_image_view, put the algorithm in a function object and invoke it by calling
apply_operation(runtime_view, algorithm_fn); -
从您的示例代码中,
gil::rgb8_image_t rgbi(rgbv.width(), rgbv.height());不会使用原始像素数据创建 rgb8 图像。如何从color_converted_view<gil::rgb8_view_t>(gv)的返回值实际创建一个具有原始像素图的 rgb8_image_t 对象?谢谢你的帮助!我对 C++ 和 Boost::gil 很陌生