Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿช„ Harry Potter Invisibility Cloak

Python OpenCV License PRs Welcome

A real-time invisibility cloak effect using computer vision with OpenCV and Python. Step into the world of Harry Potter and experience magic through the power of programming!

Invisibility Cloak Demo

โœจ Features

  • ๐ŸŽญ Real-time Invisibility Effect - Become invisible in real-time using your webcam
  • ๐ŸŽจ Multiple Color Presets - Support for red, blue, green, and yellow cloaks
  • ๐Ÿ”ง Live HSV Tuning - Real-time color calibration with interactive sliders
  • ๐ŸŽฅ Video Recording - Record your magical moments with timestamps
  • ๐Ÿ“Š Performance Monitoring - Built-in FPS counter and system status
  • ๐ŸŽฎ Interactive Controls - Easy-to-use keyboard shortcuts
  • ๐Ÿ–ฅ๏ธ Cross-Platform - Works on Windows, macOS, and Linux
  • ๐Ÿ“ฑ Smart Background Capture - Intelligent background averaging for stability
  • ๐Ÿ”Š User-Friendly Interface - Clear instructions and visual feedback

๐ŸŽฌ How It Works

The invisibility cloak uses computer vision techniques to create a real-time masking effect:

  1. Background Capture: Records a clean background image by averaging multiple frames
  2. Color Detection: Uses HSV color space to detect the cloak color with high precision
  3. Mask Creation: Creates a binary mask identifying cloak areas using morphological operations
  4. Image Compositing: Seamlessly replaces cloak pixels with the pre-recorded background
  5. Real-time Processing: Applies the effect in real-time at 30+ FPS
Original Frame + Background โ†’ HSV Conversion โ†’ Color Masking โ†’ Morphological Ops โ†’ Final Composite

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.6 or higher
  • Webcam (built-in or external)
  • Good lighting conditions

Installation

  1. Clone the repository
git clone https://github.com/ALLEXCEED360/Invicibility_Cloak.git
cd Invisibility_Cloak
  1. Install dependencies
pip install -r requirements.txt
  1. Run the application
python invisibility_cloak.py
  1. Start the magic!
    • Press 'B' to capture background (step out of frame first!)
    • Put on a red cloth/shirt
    • Watch yourself become invisible! โœจ

๐ŸŽฎ Controls Reference

Key Action Description
B ๐Ÿ“ธ Capture Background Step out of frame and press to record background
R ๐ŸŽฅ Record Video Start/stop recording (saves as MP4 with timestamp)
C ๐ŸŽจ Cycle Colors Switch between red โ†’ blue โ†’ green โ†’ yellow
T ๐Ÿ”ง HSV Tuner Open color calibration window with sliders
S ๐Ÿ’พ Save Settings Save current HSV settings to file
SPACE ๐Ÿ”„ Reset Background Clear current background
Q/ESC ๐Ÿšช Quit Exit the application

๐ŸŽฏ Usage Guide

Step 1: Setup Your Environment

  • Position your camera at eye level
  • Ensure good, even lighting (avoid harsh shadows)
  • Choose a complex background (not a plain wall)

Step 2: Capture Background

# The app will guide you through this process
1. Run: python invisibility_cloak.py
2. Step completely out of camera view
3. Press 'B' key
4. Wait for 3-2-1 countdown
5. Background captured! โœ…

Step 3: Put On Your Cloak

  • Use solid-colored cloth (red works best)
  • Avoid wrinkled or folded materials
  • Cover the body parts you want to make invisible

Step 4: Fine-tune (Optional)

  • Press 'T' to open HSV tuner
  • Adjust sliders until your cloak appears white in the mask
  • Press 'S' to save your custom settings

๐ŸŽจ Color Presets

The application comes with optimized presets for different cloak colors:

Color HSV Range Best Use Case
Red ๐Ÿ”ด H: 0-10, 170-180 Default, works in most lighting
Blue ๐Ÿ”ต H: 100-130 Good for outdoor scenes
Green ๐ŸŸข H: 40-80 Avoid green backgrounds
Yellow ๐ŸŸก H: 20-30 Bright lighting conditions

๐Ÿ› ๏ธ Advanced Usage

Command Line Options

# Basic usage
python invisibility_cloak.py

# Use different camera
python invisibility_cloak.py --cam 1

# Start with blue preset
python invisibility_cloak.py --color blue

# Custom resolution (for performance tuning)
python invisibility_cloak.py --width 640 --height 480

# All options combined
python invisibility_cloak.py --cam 1 --color green --width 1920 --height 1080

Custom Color Configuration

Create your own color presets by modifying the HSV ranges:

# Add to COLOR_PRESETS in the code
"purple": {
    "ranges": [
        (np.array([120, 50, 50]), np.array([150, 255, 255]))
    ],
    "description": "Purple cloth/clothing"
}

Performance Optimization

For older computers or lower-end hardware:

# Reduce resolution
python invisibility_cloak.py --width 640 --height 480

# Or even lower
python invisibility_cloak.py --width 320 --height 240

๐Ÿ“ Project Structure

invisibility-cloak/
โ”œโ”€โ”€ ๐Ÿ“„ invisibility_cloak.py    # Main application
โ”œโ”€โ”€ ๐Ÿ“„ requirements.txt         # Python dependencies
โ”œโ”€โ”€ ๐Ÿ“„ README.md               # This file
โ”œโ”€โ”€ ๐Ÿ“„ camera_test.py          #Test your webcam 
โ”œโ”€โ”€ ๐Ÿ“„ run_demo.py             #Run Project using optimal settings 
โ”œโ”€โ”€ ๐Ÿ“„ .gitignore             # Git ignore rules
โ”œโ”€โ”€ ๐Ÿ“„ LICENSE                # MIT license
โ”œโ”€โ”€ ๐Ÿ“‚ Demo Gif/              # Demo materials
โ”‚   โ”œโ”€โ”€ ๐ŸŽฌ im-invisible-invisible.gif

๐Ÿ”ง Troubleshooting

Common Issues and Solutions

๐Ÿšซ "Cannot open camera"

# Try different camera indices
python invisibility_cloak.py --cam 1
python invisibility_cloak.py --cam 2

# Check available cameras
python test_setup.py

๐Ÿ“‰ Low FPS / Poor Performance

# Use lower resolution
python invisibility_cloak.py --width 640 --height 480

# Close other applications using the camera
# Ensure good lighting to reduce processing load

๐ŸŽญ Cloak Not Detected Properly

  1. Lighting: Ensure even lighting without harsh shadows
  2. Color: Use solid, vibrant colors (avoid patterns)
  3. Tuning: Press 'T' to open HSV tuner and adjust
  4. Material: Avoid shiny or reflective materials

๐Ÿ–ฅ๏ธ ImportError for OpenCV or NumPy

# Reinstall dependencies
pip uninstall opencv-python opencv-contrib-python
pip install opencv-python

# For conda users
conda install opencv numpy

๐ŸŽฅ Video Recording Issues

  • Ensure you have write permissions in the directory
  • Check available disk space
  • Try different video codecs if issues persist

System Requirements

Minimum:

  • Python 3.6+
  • 2GB RAM
  • Basic webcam (480p)
  • 1 GHz processor

Recommended:

  • Python 3.8+
  • 4GB+ RAM
  • HD webcam (720p+)
  • Multi-core processor
  • Good lighting setup

๐ŸŽ“ Educational Value

This project demonstrates several important computer vision concepts:

  • Color Space Conversion (BGR โ†” HSV)
  • Image Masking and Bitwise Operations
  • Morphological Operations (Opening, Dilation)
  • Real-time Video Processing
  • Background Subtraction Techniques
  • Contour Detection and Filtering

Perfect for:

  • ๐Ÿ“š Computer Vision students
  • ๐Ÿ‘ฉโ€๐Ÿ’ป OpenCV beginners
  • ๐ŸŽญ Interactive art projects
  • ๐ŸŽƒ Halloween enthusiasts
  • ๐Ÿ“น Content creators

๐Ÿค Contributing

We welcome contributions! Here's how you can help:

๐Ÿ› Bug Reports

  • Use the issue tracker to report bugs
  • Include Python version, OS, and camera details
  • Provide steps to reproduce the issue

๐Ÿ’ก Feature Requests

  • Suggest new features or improvements
  • Explain the use case and expected behavior
  • Check existing issues to avoid duplicates

๐Ÿ”ง Pull Requests

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes with proper documentation
  4. Test thoroughly across different environments
  5. Submit a pull request with clear description

๐Ÿ’ญ Ideas for Contributions

  • ๐ŸŒˆ Additional visual effects (color changing, transparency)
  • ๐Ÿ“ฑ Mobile app version (Android/iOS)
  • ๐ŸŒ Web-based version using WebRTC
  • ๐Ÿค– Machine learning-based color detection
  • ๐Ÿ‘ฅ Multiple person support
  • ๐Ÿ–๏ธ Hand gesture controls
  • ๐ŸŽต Audio-reactive effects

๐Ÿ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • ๐Ÿ“š OpenCV Community - For the amazing computer vision library
  • ๐Ÿ Python Foundation - For the versatile programming language
  • โšก NumPy Developers - For efficient numerical computing
  • ๐Ÿช„ J.K. Rowling - For inspiring the magic of invisibility cloaks
  • ๐ŸŽ“ Computer Vision Researchers - For foundational algorithms
  • ๐ŸŒŸ Open Source Community - For making this possible

๐ŸŽฌ Showcase

Share your creations! Tag us on social media:

Use hashtags: #InvisibilityCloak #OpenCV #Python #ComputerVision #HarryPotter


Made with โค๏ธ and a touch of magic โœจ

โญ Star this repo | ๐Ÿด Fork it

About

๐Ÿช„ Real-time Harry Potter invisibility cloak using OpenCV and Python. Become invisible with computer vision magic! โœจ

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages