Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To your second question how to perform a function on the original Image:

By default, OpenCV works with the original Mat when you select a subMat:

Mat mySubmat =  img(myROI); //myROI can be a cv::Rect or use two of cv::Range instead.

Therefore, by calling any OpenCV function that takes cv::InputArray and cv::Outputarray you can simply work on the original ROI by using the SubMat as input and output.

cv::threshold(mySubmat,mySubmat,....);

To your first question. There are probably several ways how to do this: This one works, but there might be faster options:

Mat myMask = Mat::zeros(img.size(), img.type(), );
rectangle(myMask, myROI, Scalar(255,255,255));
img.setTo(cv::Scalar(0,0,0), myMask);

To your second question how to perform a function on the original Image:

By default, OpenCV works with the original Mat when you select a subMat:

Mat mySubmat =  img(myROI); //myROI can be a cv::Rect or use two of cv::Range instead.

Therefore, by calling any OpenCV function that takes cv::InputArray and cv::Outputarray you can simply work on the original ROI by using the SubMat as input and output.

cv::threshold(mySubmat,mySubmat,....);

To your first question. There are probably several ways how to do this: This one works, but there might be faster options:

Mat myMask = Mat::zeros(img.size(), Mat(img.size(), img.type(), Vec3b(255,255,255) );
rectangle(myMask, myROI, Scalar(255,255,255));
myMask(myROI).setTo(Vec3b(0,0,0));
img.setTo(cv::Scalar(0,0,0), myMask);

To your second question how to perform a function on the original Image:

By default, OpenCV works with the original Mat when you select a subMat:

Mat mySubmat =  img(myROI); //myROI can be a cv::Rect or use two of cv::Range instead.

Therefore, by calling any OpenCV function that takes cv::InputArray and cv::Outputarray you can simply work on the original ROI by using the SubMat as input and output.

cv::threshold(mySubmat,mySubmat,....);

To your first question. There are probably several ways how to do this: This one works, but there might be faster options:

Mat myMask = Mat(img.size(), img.type(), Vec3b(255,255,255) );
myMask(myROI).setTo(Vec3b(0,0,0));
img.setTo(cv::Scalar(0,0,0), img.setTo(Vec3b(0,0,0), myMask);

To your second question how to perform a function on the original Image:

By default, OpenCV works with the original Mat when you select a subMat:

Mat mySubmat =  img(myROI); //myROI can be a cv::Rect or use two of cv::Range instead.

Therefore, by calling any OpenCV function that takes cv::InputArray and cv::Outputarray you can simply work on the original ROI by using the SubMat as input and output.

cv::threshold(mySubmat,mySubmat,....);

To your first question. There are probably several ways how to do this: This one works, but there might be faster options:

Mat myMask = Mat(img.size(), img.type(), Vec3b(255,255,255) );
myMask(myROI).setTo(Vec3b(0,0,0));
); //create completely white mask
myMask(myROI).setTo(Vec3b(0,0,0)); //black out roi 
img.setTo(Vec3b(0,0,0), myMask);
myMask); //set all areas of img to black that are within the white area of the mask.

To your second question how to perform a function on the original Image:

By default, OpenCV works with the original Mat when you select a subMat:

Mat mySubmat =  img(myROI); //myROI can be a cv::Rect or use two of cv::Range instead.

Therefore, by calling any OpenCV function that takes cv::InputArray and cv::Outputarray you can simply work on the original ROI by using the SubMat as input and output.

cv::threshold(mySubmat,mySubmat,....);
cv::threshold(mySubmat,mySubmat,....); //BTW: thresholding will only work on image if single channel image

To your first question. There are probably several ways how to do this: This one works, but there might be faster options:

options:
    Mat myMask = Mat(img.size(), img.type(), Vec3b(255,255,255) ); CV_8UC1, 255); //create completely white mask
myMask(myROI).setTo(Vec3b(0,0,0));     myMask(myROI).setTo(0); //black out roi 
roi
    img.setTo(Vec3b(0,0,0), myMask); //set all areas of img to black that are within the white area of the mask.
mask.

To your second question how to perform a function on the original Image:

By default, OpenCV works with the original Mat when you select a subMat:

Mat mySubmat =  img(myROI); //myROI can be a cv::Rect or use two of cv::Range instead.

Therefore, by calling any OpenCV function that takes cv::InputArray and cv::Outputarray you can simply work on the original ROI by using the SubMat as input and output.

cv::threshold(mySubmat,mySubmat,....); //BTW: thresholding will only work on image if single channel image

To your first question. There are probably several ways how to do this: This one works, but there might be faster options: options:

Mat myMask = Mat(img.size(), CV_8UC1, 255); //create completely white mask
 myMask(myROI).setTo(0); //black out roi
 img.setTo(Vec3b(0,0,0), myMask); //set all areas of img to black that are within the white area of the mask.

mask.