About Lesson
In this Python OpenCV lesson we are going to learn about Python OpenCV Image Blending, So according to OpenCV Documentation image blending is also image addition, but different weights are given to images so that it gives a feeling of blending or transparency.
This is the complete code for this lesson.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import cv2 img1 = cv2.imread("lena_color_512.tif") img2 = cv2.imread("woman.tif") #last one is gamma value result = cv2.addWeighted(img1,0.9,img2,0.5,0) cv2.imshow('Geekscoders.com', result) cv2.waitKey(0) cv2.destroyAllWindows() |
First of we are going to load our two images.
1 2 |
img1 = cv2.imread("lena_color_512.tif") img2 = cv2.imread("woman.tif") |
We can use cv2.addWeighted() for this functionality, first image is given a weight of 0.9 and second image is given 0.5, the last value is the gamma value.
1 |
cv2.addWeighted(img1,0.9,img2,0.5,0) |
Run the complete code and this is the result.