How to set ROI in OpenCV?(如何在 OpenCV 中设置 ROI?)
问题描述
我有两张图片,第一个比另一个小.我需要在第一张图像上复制第二张图像.为此,我需要在第一个图像上设置 ROI,将第二个图像复制到第一个图像上,然后重置 ROI.
I have two images, the first one smaller than the other. I need to copy the second image on the first image. To do so, I need to set the ROI on the first one, copy the second image onto the first one and then reset the ROI.
但是我使用的是 C++ 接口,所以我不知道如何做到这一点.在 C 中,我可以使用 cvSetImageROI,但这在 C++ 接口上不起作用.
However I am using the C++ interface so I have no idea how to do this. In C I could have used cvSetImageROI but this doesn't work on the C++ interface.
那么基本上什么是 cvSetImageROI 的 C++ 替代品?
So basically whats the C++ alternative to cvSetImageROI?
//output is a pointer to the mat whom I want the second image (colourMiniBinMask) copied upon
Rect ROI (478, 359, 160, 120);
Mat imageROI (*output, ROI);
colourMiniBinMask.copyTo (imageROI);
imshow ("Gravity", *output);
推荐答案
我认为您有问题.如果第一个比另一个小,并且您想复制第一个图像中的第二个图像,则不需要 ROI.您只需调整第二张图片的大小,将其复制到第一张即可.
I think you have something wrong. If the first one is smaller than the other one and you want to copy the second image in the first one, you don't need an ROI. You can just resize the second image in copy it into the first one.
但是如果你想在第二个中复制第一个,我认为这段代码应该可以工作:
However if you want to copy the first one in the second one, I think this code should work:
cv::Rect roi = cv::Rect((img2.cols - img1.cols)/2,(img2.rows - img1.rows)/2,img1.cols,img1.rows);
cv::Mat roiImg;
roiImg = img2(roi);
img1.copyTo(roiImg);
这篇关于如何在 OpenCV 中设置 ROI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 OpenCV 中设置 ROI?
基础教程推荐
- 常量变量在标题中不起作用 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
