I am having some problems related to using boost::gil library when I try to resize an image view. I would like to access the pixels content of a image view after resizing it. However, I always obtain a segmentation fault when doing this. Here is my code:
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++;
}
}
Could you please indicate me what is my problem? If I delete the resize_view function and create the view directly from the rgb_image, it works perfectly.