我正在尝试弄清楚如何使用来自 Boost 库的 GIL 在 C++ 中新创建的图像中定位图像。
#define png_infopp_NULL (png_infopp)NULL
#define int_p_NULL (int*)NULL
#include <boost/gil/gil_all.hpp>
#include <boost/gil/extension/io/png_dynamic_io.hpp>
using namespace boost::gil;
int main()
{
rgb8_image_t img(512, 512);
rgb8_image_t img1;
rgb8_image_t img2;
png_read_image("img1.png", img1);//Code for loading an image
png_read_image("img2.png", img2); //Code for loading 2nd image "img2.png"
//loading position of the images to an array or some kind of variable
//passing in images and postions to the function to apply changes on newly created image with the size of 512, 512
png_write_view("output.png", const_view(img)); //saving changes as "output.png"
}
最佳答案
您可以只使用 subimage_view
来定位您的图像,并使用 copy_pixels
来复制它们。
您需要注意输入图像和输出 subview 的大小是否匹配。如果它们不匹配,您还可以使用 resize_view
。
类似的东西:
rgb8_image_t img1;
jpeg_read_image("img1.jpg", img1);
rgb8_image_t img2;
jpeg_read_image("img2.jpg", img2);
rgb8_image_t out_img(512, 512);
copy_pixels (view(img1), subimage_view(view(out_img), x, y, width, height));
copy_pixels (view(img2), subimage_view(view(out_img), x, y, width, height));
png_write_view("output.png", const_view(out_img));
关于c++ - 在 C++ 中使用来自 Boost 的 GIL 在图像中定位图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42722880/