当我尝试调整图像视图的大小时,我遇到了一些与使用 boost::gil 库相关的问题。我想在调整大小后访问图像视图的像素内容。但是,这样做时我总是会遇到分段错误。这是我的代码:
boost::gil::rgb8_image_t rgb_image;
//Try to convert image file to raw binary data
try {
boost::gil::read_and_convert_image("/tmp/image.jpg", rgb_image, boost::gil::jpeg_tag());
} catch (...) {
return;
}
boost::gil::rgb8_view_t rgb_view;
boost::gil::rgb8_image_t rgb_image_resize(150, 200);
boost::gil::resize_view(boost::gil::const_view(rgb_image), boost::gil::view(rgb_image_resize), boost::gil::bilinear_sampler());
rgb_view = boost::gil::view(rgb_image_resize);
for (std::uint32_t i = 0; i < 150; i++) {
boost::gil::rgb8_view_t::x_iterator it_image = rgb_view.row_begin(i);
for (size_t width = 0; width < 200; width++) {
if (it_image->at_c_dynamic(0) * 0.299 + it_image->at_c_dynamic(1) * 0.114 + it_image->at_c_dynamic(2) * 0.587 < 80) {//color filter. Trying to execute this line gives me a seg fault
//do something
} else { //white pixel
//do something
}
it_image++;
}
}
你能告诉我我的问题是什么吗?如果我删除 resize_view 函数并直接从 rgb_image 创建视图,它会完美运行。