Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save IAmSuyogJadhav/305bfd9a0605a4c096383408bee7fd5c to your computer and use it in GitHub Desktop.
Save IAmSuyogJadhav/305bfd9a0605a4c096383408bee7fd5c to your computer and use it in GitHub Desktop.
Add transparency to rectangles, circles, polgons, text or any shape drawn in OpenCV.
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)
@jonathan-cartica
Copy link

very good very nice!

@idangrady
Copy link

Appreciated!!

@joabnd7
Copy link

joabnd7 commented Dec 18, 2022

Legend!

@Jay4BioPZ
Copy link

You are a hero :)

@WildePizza
Copy link

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment