了解 openCV 2.4 中的兴趣区域

Understanding region of interest in openCV 2.4(了解 openCV 2.4 中的兴趣区域)
本文介绍了了解 openCV 2.4 中的兴趣区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在 OpenCV 2.1 中我们有一个函数来设置 ROI:cvSetImageROI(),但是这样的函数在 2.4 中不存在(或者至少我在它的手册和帮助部分找不到它.)

I know that in OpenCV 2.1 we had a function to set ROI: cvSetImageROI(), but such a function does not exist in 2.4 (or at least I cant find it in its manuals and help section.)

然而,这是我能找到的唯一有用的代码,它使用 opencv 2.4 进行法师 ROI,但我无法理解它:

however here is the only helpful code I could find which uses opencv 2.4 for mage ROI, but I am having trouble understanding it:

// define image ROI
cv::Mat imageROI;
imageROI= image(cv::Rect(385,270,logo.cols,logo.rows));
// add logo to image 
cv::addWeighted(imageROI,1.0,logo,0.3,0.,imageROI);

在这里,他们想在原始图像右下角的大图像中添加一个非常小的日志.

Here they want to add a very small log to a big image at the bottom right of the original image.

所以我从这里了解到的是,创建了另一个矩阵来保存 ROI.它的尺寸使用 rect 函数给出,大小等于他们想要添加的小徽标的尺寸.

So what I understand from here is that another matrix is created to hold the ROI. Its dimensions given using the rect function, and size is given equal to that of the small logo they want to add.

然后这就是让我困惑的地方:cv::addWeighted(imageROI,1.0,logo,0.3,0.,imageROI); 这里 addWeighted 的源 1 是 ROI 维度集,源 2是徽标,目的地也是 ROI 维度集.这个对吗?还是我遗漏了什么?

Then thsi is what confuses me: cv::addWeighted(imageROI,1.0,logo,0.3,0.,imageROI); here the source 1 of addWeighted is the ROI dimensions set, source 2 is the logo and the destination is also the ROI dimensions set. Is this correct? or am I missing something?

在此之后,结果显示为将徽标添加到大图像中.这些命令中包含大图像的位置.

After this the result is shown with the logo added to the big image. Where in these commands was the big image included.

此外,在问这里之前,我想自己尝试一下代码,以帮助澄清情况.但我收到此错误,因为无法识别 image():'image': identifier not found

Also before asking here I wanted to try the code myself to maybe help clarify the situation. but I get this error, as the image() is not recognized: 'image': identifier not found

int _tmain(int argc, _TCHAR* argv[])
{
Mat src1, imageROI, logo;

logo = imread("c:\car1.jpg", -1);

imageROI= image(Rect(385,270,logo.cols,logo.rows));

addWeighted(imageROI,1.0,logo,0.3,0.,imageROI);


namedWindow("meh", CV_WINDOW_AUTOSIZE);
imshow("meh", imageROI);
waitKey(0);


return 0;

}

推荐答案

cv::Mat imageROI;
imageROI= image(cv::Rect(385,270,logo.cols,logo.rows));

以矩形为参数的 cv::Mat 构造函数:

The cv::Mat constructor wich takes a rectangle as a parameter:

Mat::Mat(const Mat& m, const Rect& roi)

返回一个矩阵,该矩阵指向原始图像的 ROI,位于矩形指定的位置.所以 imageROI 实际上是原始图像图像"的感兴趣区域(或子图像/子矩阵).如果你修改 imageROI,它会相应地修改原始的、更大的矩阵.

returns a matrix that is pointing to the ROI of the original image, located at the place specified by the rectangle. so imageROI is really the Region of Interest (or subimage/submatrix) of the original image "image". If you modify imageROI it will consequently modify the original, larger matrix.

至于您的示例,问题在于您从不存在的对象(图像)调用构造函数.你应该更换:

As for your example, the problem is that you are calling the constructor from an object which does not exists (image). You should replace:

imageROI= image(Rect(385,270,logo.cols,logo.rows));

作者:

imageROI= src1(Rect(385,270,logo.cols,logo.rows));

假设 src1 是您要插入徽标的大图像"(徽标为 car1.jpg).顺便说一句,您不应该忘记先阅读您的大图像!

assuming that src1 is your "big image" that you want to insert the logo into (the logo being car1.jpg). You should not forget to first read your big image, by the way!

这篇关于了解 openCV 2.4 中的兴趣区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)