了解openCV 2.4中的兴趣区域 [英] Understanding region of interest in openCV 2.4

查看:173
本文介绍了了解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的mage 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.

然后thsi会让我困惑: 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':未找到标识符

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中的兴趣区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆