I'm using the below script to replace the green screen of the original video with a background image but the result is not what I expected, I've changed u_green array parameters and also l_green but it only gets worst. In the end, I want to make it transparent which mask should I use?
I'd appreciate any help to fix this.
Python script:
import cv2
import numpy as np
video = cv2.VideoCapture("green.mp4")
image = cv2.imread("bg.jpg")
while True:
ret, frame = video.read()
frame = cv2.resize(frame, (640, 480))
image = cv2.resize(image, (640, 480))
u_green = np.array([104, 153, 70])
l_green = np.array([30, 30, 0])
mask = cv2.inRange(frame, l_green, u_green)
res = cv2.bitwise_and(frame, frame, mask=mask)
f = frame - res
f = np.where(f == 0, f, image)
cv2.imshow("video", frame)
cv2.imshow("mask", f)
if cv2.waitKey(25) == 27:
break
video.release()
cv2.destroyAllWindows()
Update Source video: Link