Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Python - Eye blink detection project
Next article icon

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 useOpenCV - Pythonto do the same. 
 

Approach:

  1. Import all necessary libraries
  2. Load the images or videos
  3. Resize the images and the videos to the same size
  4. Load the upper and lower BGR values of the green color
  5. Apply the mask and then use bitwise_and
  6. Subtract bitwise_and from the original green screen image
  7. Check for matrix value 0 after subtraction and replace it by the second image
  8. You get the desired results.


Below is the implementation. 

Python3
importcv2importnumpyasnpvideo=cv2.VideoCapture("green.mp4")image=cv2.imread("bg.jpeg")whileTrue: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-resf=np.where(f==0,image,f)cv2.imshow("video",frame)cv2.imshow("mask",f)ifcv2.waitKey(25)==27:breakvideo.release()cv2.destroyAllWindows()

Output: 
 

Screenshot-from-2020-04-21-22-42-28-copy



 


Improve
Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp