c++ - 在 C++ 中使用来自 Boost 的 GIL 在图像中定位图像

标签 c++ boost png gil boost-gil

我正在尝试弄清楚如何使用来自 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"
}

image of what i want to do

最佳答案

您可以只使用 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/

相关文章:

C++:接口(interface)强制定义copy-constr

c++ - 重载运算符。

c++ - 如何在 UML 中对两个 C++ 类(在不同线程中)之间的消息接口(interface)进行建模?

c++ - 我的第一个多线程应用程序 - Boost :Threads? 的奇怪行为

c++ - boost install windows msvc 10.0 -- example.cpp 链接失败

svg - 使用 Imagick 将 SVG 转换为 PNG 会弄乱文本

c++ - 作用域运算符和迭代器

c++ - spirit real_parser ".e"

png - 16位灰度png

使用 alpha channel 打开 PNG 文件