Reputation: 14615
I want to create a mask operation...
I have two input images, of the same size (do they have to have the same depth/number of channels ? I'd like to be anything, likely 3 channels, CV_32FC3
or gray...) and I created a mask, of the same size (rows and cols)
cv::Mat mask = cv::Mat(image1.rows, image1.cols, CV_8UC1);
The mask is created with areas of black and white.
I would like to create a new cv::Mat, that will have image1 where mask has 1, and image2 where mask has 0.
I looked into cv::filter2D
and copyTo
... Also looked at addWeighted, but I don't want to blend them - the areas for each image should be completely separate. A roi would not help - the mask is likely to not contain a rectangle, but one or more polygons.
I can't find something that does what I want.
Is there any OpenCV function that combines my images based on the mask ? Or do I have to create my own, looping through rows and cols ?
Thank you.
Upvotes: 4
Views: 11160
Reputation: 19333
Just use the bitwise_and()
function and you're set. The references below include a full working example.
References:
Upvotes: 5