This project implements a Harry Potter-style Invisibility Cloak using Python and OpenCV. It uses real-time video processing to detect a specific color (e.g., black) in a video feed and replaces it with a previously captured background, creating the illusion of invisibility.
- Real-time cloak detection using color segmentation.
- Supports user-defined cloak colors (e.g., black, red, blue).
- Works with any webcam or connected camera.
- Implements background subtraction and image masking.
- The program captures a static background image without the user in the frame.
- It detects the user’s cloak using the HSV color space and creates a mask for that specific color.
- The cloak area is replaced with the captured background using image masking techniques, making the cloak appear invisible.
Ensure you have the following installed:
- Python 3.7 or higher
- pip (Python package manager)
- OpenCV library
git clone https://github.com/hpishwe/magic-cloak.git
cd magic-cloak
pip install -r requirements.txt
python cloak_detection.py
Follow the instructions:
- Stand out of the frame for a few seconds to let the program capture the background.
- Once the background is captured, step into the frame wearing your cloak (black color in this version).
The script will detect the black cloak and replace it with the background, making it appear invisible in real-time.
The project uses the following Python libraries:
- OpenCV: For image processing and video handling.
- NumPy: For array operations and mask creation.
These dependencies are included in the requirements.txt
file.
- Edges of the cloak are visible: Adjust the HSV range to ensure complete color coverage.
- Cloak detection is inconsistent: Improve lighting and avoid shadows or wrinkles on the cloth.
- Script not working: Ensure you’ve installed all dependencies and your webcam is functional.
- Allow dynamic color selection for the cloak.
- Use deep learning models for more robust and precise segmentation.
- Add support for multiple cloaks in the same frame.