Skip to content

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Real-Time Background Replacement using OpenCV

This project performs real-time background subtraction and background replacement using OpenCV and Python.
It detects foreground movement by comparing the current frame with a captured reference background frame and replaces the background with frames from another video source.

Features

  • Real-time foreground extraction
  • Background replacement using video
  • Automatic video looping
  • Manual background recapture
  • Keyboard controls for interaction
  • Works with uploaded video files

Technologies Used

  • Python
  • OpenCV
  • NumPy

How It Works

  1. A reference background frame is captured.
  2. Each incoming frame is compared with the reference frame.
  3. Differences between frames are extracted.
  4. Foreground is separated from the background.
  5. The foreground is combined with another background video frame.

File Requirements

Upload a video file named:

uploaded_video.h264

Or change the filename in the code:

cv2.VideoCapture('your_video_name.mp4')

Installation

Install dependencies:

pip install -r requirements.txt

Run the Project

python Augmented_Reality.py

Keyboard Controls

Key Action
q Capture current frame as background
p Prepare to capture new background
d Exit the program

Project Structure

.
├── Augmented_Reality.py
├── requirements.txt
├── .gitignore
├── uploaded_video.h264
└── README.md

Future Improvements

  • Green screen support
  • Deep learning segmentation
  • Better edge refinement
  • Webcam live support
  • Multiple background options

Example Use Cases

  • Virtual background replacement
  • Motion detection experiments
  • Computer vision learning projects
  • Video effects and editing

Author

Shubh Sharma

About

Real-time background subtraction and replacement using OpenCV with video input support.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages