简体   繁体   English

OpenCV-获取图像的一部分

[英]OpenCV - Getting a part of an image

I want to get a part of an image loaded in another image. 我想将一部分图像加载到另一幅图像中。 There are several, easy ways to do that but for example cv::Mat OutImage = Image(cv::Rect(7,47,1912,980)) but- the resulted image is to large For example: 有几种简单的方法可以做到这一点,但是例如cv::Mat OutImage = Image(cv::Rect(7,47,1912,980))但-得到的图像很大例如:
I got an image with 1920 x 1024 pixel. 我得到了1920 x 1024像素的图像。 I want to cut a cv:Rect(7,47,1912,980) from it. 我想从中切出一个cv:Rect(7,47,1912,980)。 I would suggest, that the resulting image has the size (1912 - 7 = 1905) x (980 - 47 = 933) pixel but it has 1912 x 980. It seems, that Opencv is just cutting on the right lower side and keeping the left upper area. 我建议,结果图像的大小为(1912-7 = 1905)x(980-47 = 933)像素,但它的大小为1912 x980。看来,Opencv只是在右下侧切割并保持左上方区域。

The dimension of the image is important, because in the next step I'd like to perform a substraction which is only valid if the Mat object has the same dimension. 图像的尺寸很重要,因为在下一步中,我要执行减法运算,仅当Mat对象具有相同的尺寸时才有效。 I also don't want to use a loop designed by myself, because performance is very important. 我也不想使用我自己设计的循环,因为性能非常重要。

Any ideas? 有任何想法吗?

Regards, Jan 此致Jan

It is actually cv:Rect(x,y,width,height) , so you should set the last two parameters as your willing output width and height. 它实际上是cv:Rect(x,y,width,height) ,因此您应该将最后两个参数设置为您希望的输出宽度和高度。 Mind the range you set or it would cause errors. 请注意您设置的范围,否则可能会导致错误。

I had also dealed with this issue I will just give my example here it is working for me well. 我也已经处理了这个问题,在这里我只举一个例子,它对我很好。 You may also try this one. 您也可以尝试这个。

 Rect const box(100, 295, 400, 185); //this mean the first corner is
                                      //(x,y)=(100,295)
                                     // and the second corner is
                                     //(x + b, y+c )= (100 +400,295+185)

 Mat ROI = frame(box);

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

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