简体   繁体   English

如何确定感兴趣的区域,然后使用OpenCV C ++裁剪图像

[英]How to determine a region of interest and then crop an image using OpenCV c++

I have a sample image as below. 我有一个示例图像如下。 I would like to make the square my Region of Interest and then crop out that part (square) and create a new image with it. 我想将正方形设为“我的关注区域”,然后裁剪出该部分(正方形)并使用它创建一个新图像。 I will be working with different images so the square won't always be at the same location in all images. 我将使用不同的图像,因此正方形在所有图像中都不会始终位于同一位置。 So I will need to somehow detect the edges of the square. 因此,我将需要以某种方式检测正方形的边缘。

I can not post pictures because I have 10 reputations 我有10个声誉,因此无法发布图片

help me please?? 请帮帮我??

Thank you very much 非常感谢你

cvSetImageROI(currentImage,yourSquare);
CvSize size = cvSize(width, height);
IplImage * newImage = cvCreateImage(size,8,3);
cvResize(currentImage,newImage,CV_INTER_AREA);

First you must set your ROI with cvSetImageROI(IplImage*,CvRect). 首先,您必须使用cvSetImageROI(IplImage *,CvRect)设置ROI。 After that you create your new image with the desired width and height. 之后,使用所需的宽度和高度创建新图像。 Finally you can copy your old image to the new one. 最后,您可以将旧图像复制到新图像。 The new image will contain your desired ROI. 新图像将包含您所需的ROI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM