cv2 rectangle fill color opacity

Solutions on MaxInterview for cv2 rectangle fill color opacity by the best coders in the world

showing results for - "cv2 rectangle fill color opacity"
Iker
24 Feb 2020
1import cv2
2import numpy as np
3
4# Load image
5img = cv2.imread('images/paddington.png')
6
7# Initialize black image of same dimensions for drawing the rectangles
8blk = np.zeros(img.shape, np.uint8)
9
10# Draw rectangles
11cv2.rectangle(blk, (5, 5), (100, 75), (255, 255, 255), cv2.FILLED)
12
13# Generate result by blending both images (opacity of rectangle image is 0.25 = 25 %)
14out = cv2.addWeighted(img, 1.0, blk, 0.25, 1)
15
16cv2.imshow('Image', img)
17cv2.imshow('Rects', blk)
18cv2.imshow('Output', out)
19cv2.waitKey(0)
20cv2.destroyAllWindows()