Forked from IAmSuyogJadhav/Transparent drawings in OpenCV.py
Created
April 26, 2020 07:22
-
-
Save NISH1001/18e18cda10ca5b6f0fe0fb6059713c75 to your computer and use it in GitHub Desktop.
Add transparency to rectangles, circles, polgons, text or any shape drawn in OpenCV.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
image = cv2.imread('test.jpg') | |
overlay = image.copy() | |
x, y, w, h = 10, 10, 10, 10 # Rectangle parameters | |
cv2.rectangle(overlay, (x, y), (x+w, y+h), (0, 200, 0), -1) # A filled rectangle | |
alpha = 0.4 # Transparency factor. | |
# Following line overlays transparent rectangle over the image | |
image_new = cv2.addWeighted(overlay, alpha, image, 1 - alpha, 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment