I want to cover a image with a transparent solid color overlay in the shape of a black-white mask
Currently I'm using the following java code to implement this.
redImg = new Mat(image.size(), image.type(), new Scalar(255, 0, 0));
redImg.copyTo(image, mask);
I'm not familiar with the python api.
So I want to know if there any alternative api in python. Is there any better implementation?
image:
mask:
what i want:
Now after I deal with all this Python, OpenCV, Numpy thing for a while, I find out it's quite simple to implement this with code:
image[mask] = (0, 0, 255)
-------------- the original answer --------------
I solved this by the following code:
redImg = np.zeros(image.shape, image.dtype)
redImg[:,:] = (0, 0, 255)
redMask = cv2.bitwise_and(redImg, redImg, mask=mask)
cv2.addWeighted(redMask, 1, image, 1, 0, image)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With