Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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