Blending and transitioning images
The cv2.addWeighted() function computes the weighted sum of the two images that we pass in as arguments. This causes them to blend. The following is some code that demonstrates this concept of blending:
import cv2
img1 = cv2.imread('/home/pi/book/dataset/4.2.03.tiff', 1)
img2 = cv2.imread('/home/pi/book/dataset/4.2.05.tiff', 1)
cv2.imshow('Blended Image',
cv2.addWeighted(img1, 0.5, img2, 0.5, 0))
cv2.waitKey(0)
cv2.destroyAllWindows()
In the preceding code, we are passing the following five arguments to the OpenCV cv2.addWeighted() function:
img1: The first imagealpha: The coefficient for the first image (0.5in the preceding example)img2: The second imagebeta: The coefficient for the second image (0.5in the preceding example)gamma: The scalar value (0in the preceding example)
OpenCV uses the following formula to compute the output image:
output image = (alpha *...