Ask Your Question

set ROI in cv::Mat

asked 2013-03-29 09:56:33 -0500

isaacenrique gravatar image

updated 2020-11-30 03:02:30 -0500


I need to set the region of interest or ROI in an image cv::Mat. I have seen that there are functions for IplImage images, but I could not find the equivalent functions for cv::Mat.

Also, I have the following questions:

Is it possible to set an ROI with a customized form, ie other than a rectangle?

Thanks in advance for any responses and / or comments.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-03-29 10:05:41 -0500

Simply done by:

Mat image = imread("");
Rect region_of_interest = Rect(x, y, w, h);
Mat image_roi = image(region_of_interest);

There you go :)

edit flag offensive delete link more


And probably you can adjust the roi code to use other forms, but no experience in that :)

StevenPuttemans gravatar imageStevenPuttemans ( 2013-03-29 10:06:59 -0500 )edit

Custom size only works by using a mask. And to answer your question: yes, either by cv::Rect or using cv::Range (e.g. image roi = image(Range(y,y+h), Range(x,x+w));

Guanta gravatar imageGuanta ( 2013-03-29 12:10:32 -0500 )edit

I think there should be a way to create an irregular roi, simply a mask. Is there a way to thresholded mask as a roi, I mean for the rest of the operations, I want for example non-zero pixels to be processed.

telepinu gravatar imagetelepinu ( 2014-05-16 09:12:51 -0500 )edit

nothing easier than that: cv::Mat mask = ( input_mat != 0); all elements which are not 0 are set to 255.

Guanta gravatar imageGuanta ( 2014-05-18 08:45:01 -0500 )edit

Question Tools


Asked: 2013-03-29 09:56:33 -0500

Seen: 89,583 times

Last updated: Mar 29 '13