i had added transparency to the whole image, but later i also added rectangle and aligned it by center. How to delete transparency in rectangle area?
Code:
import cv2
image = cv2.imread('test.jpeg')
overlay = image.copy()
print(image.shape)
x, y, w, h = 0, 0, image.shape[1], image.shape[0] # Rectangle parameters
cv2.rectangle(overlay, (x, y), (x+w, y+h), (500, 500, 500), -1) # A filled rectangle
Y, X = overlay.shape[0], overlay.shape[1]
print(X, Y)
cv2.rectangle(overlay, pt1=((X // 2) - 150,(Y // 2) - 150), pt2=((X // 2) + 150,(Y // 2) + 150), color=(0,0,0), thickness=5)
alpha = 0.5 # Transparency factor.
# Following line overlays transparent rectangle over the image
image_new = cv2.addWeighted(overlay, alpha, image, 1 - alpha, 0)
cv2.imshow('frame', image_new)
cv2.waitKey(0) # waits until a key is pressed
cv2.destroyAllWindows()
