# ROI, always a rectangle?

Hello

So far I havent had so much luck in people answering my questions ;; let's hope this one gets a reply :(

Quick and simple question. In openCV, ROIs have to be always rectangles??

I would like to use a circle as ROI. Is this not possible?

Thanks a lot in advance to all of you :)

edit retag close merge delete

Sort by » oldest newest most voted

The ROI of a mat is not needed to be always a rectangle, but cv::Mat is always a matrix, or a rectangle image, so you cannot have a round image, but you may have a circle on a black background that contains the information that you want. For having this, you have to use a maks:

cv::Mat image = cv::imread("img.jpg");
cv::Mat imagePart = cv::Mat::zeros(image.size(), image.type());


So, the ROI may be any shape, by using a mask. But if you are refering at the ROI as a submatrix, then you must have a rectangle for defining it (you can use the rectangle that englobes the circle: cv::Rect roi(circleCenter.x - radius, circleCenter.y - radius, 2*radius, 2*radius); but do not forget to do an AND operation, for being sure that it does not get out of the image boundaries: roi = roi & cv::Rect(0, 0, image.cols, image.rows)).

more

my comment from a closed question ....

ROI is a cv::Mat with it's own header while matrix data is shared with a parent cv::Mat than is rectangular by definition. May be could be usefull Optional operation mask used by many functions

more

You must look this : link text

more

Official site

GitHub

Wiki

Documentation