Edit
Anybody with a similar problem - I found another SO answer here with a great python solution that exploits the speed of NumPy.
Please consider the following problem:
I have two images, both the same size. One is a red square with varying layers of opacity:
And a second, a blue square, smaller than the red, with no opacity but white surrounding it.
I am using OpenCV's python bindings for this project and so far (after reading about watermarking here I have this:
redSquare = cv2.imread('redSquare.png', cv2.IMREAD_UNCHANGED)
(rH, rW) = redSquare.shape[:2]
blueSquare = cv2.imread('blueSquare.png')
(h, w) = blueSquare.shape[:2]
blueSquare = np.dstack([blueSquare, np.ones((h,w), dtype = 'uint8') * 255])
overlay = np.zeros((h,w,4), dtype = 'uint8')
overlay[0:rH, 0:rW] = redSquare
output = blueSquare .copy()
cv2.addWeighted(overlay, 0.5, output, 0.5, 0, output)
cv2.imwrite('imageAdded.png', output)
Which produces the following output:
However the desired effect is:
Now I understand by using weighted adding, I am using 0.5 of each, when I really want 1.0 of each, however when I try increasing the weighht of both, only one is increased and the other is decreased.
If anyone has some insight into how I can achieve this, preferably in Python, but if you know a way in C++ I am sure I can replicate it.
Thanks.