Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to set a ROI with arbitrary shape?

Hello, the code is here

cv::Mat src = cv::imread("1.bmp", CV_LOAD_IMAGE_UNCHANGED);
cv::Mat mask = cv::Mat::ones(src.size(), CV_8UC1);
mask.row(10).setTo(255);
mask.col(20).setTo(255); // arbitary shape
cv::Mat roi;
src.copyTo(roi, mask); // get the roi

This is 1.bmp

image description

This is mask

image description

This is roi

image description

If I excute roi = roi + 10, the black parts of roi will also add 10, it's not what I want. How to get a roi without the black parts?

Thanks!

How to set a ROI with arbitrary shape?

Hello, the code is here

cv::Mat src = cv::imread("1.bmp", CV_LOAD_IMAGE_UNCHANGED);
cv::Mat mask = cv::Mat::ones(src.size(), CV_8UC1);
mask.row(10).setTo(255);
mask.col(20).setTo(255); // arbitary shape
cv::Mat roi;
src.copyTo(roi, mask); // get the roi

This is 1.bmp

image description

This is mask

image description

This is roi

image description

If I excute roi = roi + 10, the black parts of roi will also add 10, it's not what I want. How to get a roi without the black parts?

Thanks!