Turn yourself invisible in real time using computer vision and a red cloak. This project uses OpenCV and Python to detect a red cloth, remove it from the camera feed, and replace it with a captured background — creating a Harry Potter–style invisibility effect.
Instead of buttons or a GUI, the cloak is controlled using QR codes.
OpenCV Computer Vision Python QR Control
- ⚡ Real-time invisibility effect (typically 30+ FPS)
- 🎨 HSV-based color segmentation for reliable red-cloak detection
- 📱 QR code control:
CLOAK_ON/INVISIBLE→ Activate cloakCLOAK_OFF/VISIBLE→ Deactivate cloakTOGGLE→ Switch state
- 🖼️ Static or dynamic background replacement
- 📊 On-screen HUD with live FPS counter and cloak status
- ⌨️ Keyboard fallbacks (
Cto toggle,ESCto quit)
At startup, the camera records several frames while you are not in front of it. These frames are combined into a clean background image.
- Each frame is flipped horizontally for a mirror-like view
- Blurred slightly to reduce noise
- Converted from BGR to HSV color space
- Two red hue ranges (around 0° and 180°) create a cloak mask
Morphological operations are applied to:
- Remove noise
- Fill gaps
- Smooth cloak edges
Pixels detected as cloak are replaced with pixels from the stored background. All other pixels come from the live camera feed, producing the invisibility illusion.
Each frame is scanned for QR codes. Decoded commands update the cloak state with a cooldown to prevent repeated triggers.
- Python 3.8+
- Webcam
- Red cloth or fabric
- Python packages:
pip install opencv-python numpy pyzbargit clone https://github.com/<your-username>/qr-invisibility-cloak.git
cd qr-invisibility-cloakpip install opencv-python numpy pyzbarpython QRCodeGen.pyOr use the pre-generated QR codes in the QR's Generated folder.
python InvisibilityCloak.py- Remove the red cloth from the camera view
- Wait for background capture (~3 seconds)
- Put on your red cloak
- Show QR codes to control the effect
cloak_on.png→ Activate cloakcloak_off.png→ Deactivate cloaktoggle.png→ Toggle state
C→ Toggle cloakESC→ Exit program
.
├── QR's Generated/
│ ├── cloak_off.png
│ ├── cloak_on.png
│ └── toggle.png
├── InvisibilityCloak.py
├── QRCodeGen.py
└── README.md
Adjust HSV values in InvisibilityCloak.py if detection is noisy:
lower_red1 = np.array([0, 100, 50])
upper_red1 = np.array([10, 255, 255])
lower_red2 = np.array([160, 100, 50])
upper_red2 = np.array([180, 255, 255])- Use uniform lighting
- Avoid pink or orange fabrics
- Tune morphological iterations
- Maintain moderate camera distance
- Color Detection: HSV segmentation
- Image Processing: Morphological operations
- QR Detection: pyzbar
- Performance: 30+ FPS optimized pipeline
- Background: Median-based capture
- 🎮 Gesture-based control
- 👥 Multi-person or multi-color cloaks
- 🎥 OBS virtual camera support
- 🖱️ GUI for live HSV tuning
- 📦 Standalone app with PyInstaller
- 🌍 Custom background images or videos
Fork the project and submit pull requests for improvements.
Built with OpenCV & PythonQR-Controlled Interaction
Made by Justin Thomas