Ask Your Question
3

ROI, always a rectangle?

asked 2015-01-25 19:16:03 -0600

KansaiRobot gravatar image

updated 2015-10-04 07:57:07 -0600

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 flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
0

answered 2017-07-09 13:43:24 -0600

You must look this : link text

edit flag offensive delete link more
1

answered 2015-10-08 13:35:42 -0600

pklab gravatar image

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

edit flag offensive delete link more
8

answered 2015-01-26 02:36:07 -0600

thdrksdfthmn gravatar image

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 mask = cv::Mat::zeros(image.size(), CV_8UC1);
cv::Point circleCenter(mask.cols / 2, mask.rows / 2);
int radius = std::min(mask.cols, mask.rows);
cv::circle(mask, circleCenter, radius, CV_RGB(255, 255, 255));
cv::Mat imagePart = cv::Mat::zeros(image.size(), image.type());
image.copyTo(imagePart, mask);

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

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-01-25 19:16:03 -0600

Seen: 19,175 times

Last updated: Oct 08 '15