Jan021981
Jan021981

Reputation: 553

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:
I got an image with 1920 x 1024 pixel. I want to cut a cv:Rect(7,47,1912,980) from it. 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.

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. I also don't want to use a loop designed by myself, because performance is very important.

Any ideas?

Regards, Jan

Upvotes: 0

Views: 1092

Answers (2)

Yunus Temurlenk
Yunus Temurlenk

Reputation: 4342

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);

Upvotes: 0

Everley Tseng
Everley Tseng

Reputation: 104

It is actually cv:Rect(x,y,width,height), so you should set the last two parameters as your willing output width and height. Mind the range you set or it would cause errors.

Upvotes: 2

Related Questions