Ask Your Question
6

set ROI in cv::Mat

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

isaacenrique gravatar image

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

Greetings.

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
10

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

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

Comments

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 -0600 )edit
1

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 -0600 )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 -0600 )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 -0600 )edit

Question Tools

Stats

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

Seen: 91,714 times

Last updated: Mar 29 '13