Reputation: 68
I want to change the color of my mask which is black to any different color.
Here is my mask
and here is my original image
I know that if I use this function
src.copyTo(dst, mask);
it will allow me to use the mask properly and to have a result like this
However whenever I change the mask color to non black it doesn't make anything to dst
Mat.
Is there a way to use a mask with non-black mask?
I don't want to use looping function because I know it'll cost me a lot of processing time.
Thanks
Upvotes: 0
Views: 2971
Reputation: 3071
What you're looking for is a bitwise_and
operation performed on the mask and the original image. If I understand you correctly, there is no reason for changing the color of the mask.
Upvotes: 0
Reputation: 150745
I don't write Java, but you can try in C++:
// assume that origin image has 3 channels
cv::Scalar myColor(255,0,255);
// create dst with background color of your choice
cv::Mat dst(src.size(),src.type(),myColor);
// now copy
src.copyTo(dst, mask);
And the result:
Upvotes: 2