Last Updated : 12 Jul, 2025
Prerequisites: OpenCV Python Tutorial
OpenCV (Open Source Computer Vision) is a computer vision library that contains various functions to perform operations on pictures or videos. This library is cross-platform that is it is available on multiple programming languages such as Python, C++, etc.
Green Screen removal is used in the VFX industry for changing the scenes. Here, we will use OpenCV - Python to do the same.
Below is the implementation.
import cv2
import numpy as np
video = cv2.VideoCapture("green.mp4")
image = cv2.imread("bg.jpeg")
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, image, f)
cv2.imshow("video", frame)
cv2.imshow("mask", f)
if cv2.waitKey(25) == 27:
break
video.release()
cv2.destroyAllWindows()
Output:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4