AI-powered room monitoring system that detects humans and sends instant Telegram alerts with screenshots when someone enters your room.
- π€ AI Human Detection - Uses HOG (Histogram of Oriented Gradients) to detect actual humans
- πΈ High-Quality Screenshots - Captures clear images in 1280x720 resolution
- π± Telegram Alerts - Instant notifications with photos sent to your phone
- π― Motion Detection Backup - Dual detection system for maximum reliability
- ποΈ Live Preview - See what the camera sees in real-time
- π Auto Camera Adjustment - Automatically adjusts to lighting conditions
- β‘ Fast Response - Sends alerts within seconds of detection
- π« Anti-Spam - Configurable cooldown between alerts
- Webcam (built-in laptop camera or USB webcam)
- Computer running Windows/Linux/Mac
- Internet connection for Telegram alerts
- Python 3.7 or higher
- Telegram account
pip install opencv-python numpy requestsOr using requirements.txt:
pip install -r requirements.txt- Open Telegram and search for
@BotFather - Send
/newbotcommand - Follow instructions to create your bot
- Copy the Bot Token (looks like:
123456789:ABCdefGHIjklMNOpqrsTUVwxyz)
- Search for
@userinfoboton Telegram - Send any message or click "Start"
- Copy the number it sends you (your Chat ID)
Open motion_detector.py and update:
TELEGRAM_BOT_TOKEN = "YOUR_BOT_TOKEN_HERE" # Paste your bot token
TELEGRAM_CHAT_ID = "YOUR_CHAT_ID_HERE" # Paste your chat IDpython motion_detector.pyThat's it! The system is now monitoring your room! π
Edit these settings at the top of motion_detector.py:
# Detection sensitivity
MOTION_THRESHOLD = 800 # Lower = more sensitive (default: 800)
MIN_CONTOUR_AREA = 500 # Minimum object size to detect (default: 500)
MIN_TIME_BETWEEN_ALERTS = 8 # Seconds between alerts (default: 8)
# Human detection
DETECT_HUMANS = True # Enable AI human detection (default: True)
MIN_HUMAN_CONFIDENCE = 0.3 # Detection confidence 0.0-1.0 (default: 0.3)
# Visual options
SHOW_PREVIEW = True # Show live camera preview (default: True)
DRAW_DETECTION_BOXES = True # Draw boxes around detections (default: True)python motion_detector.py- Place laptop facing your door before sleeping
- Minimize or hide the preview window
- Get alerts on your phone when someone enters
python motion_detector.py- Keep preview window open
- Walk in front of camera to test
- Check Telegram for alerts
- Adjust sensitivity if needed
Set SHOW_PREVIEW = False in the script for servers or background operation.
-
Camera Initialization
- Opens webcam with optimal settings
- Adjusts to lighting conditions (auto-exposure, auto-focus)
- Captures high-resolution frames (1280x720)
-
Human Detection (Primary)
- Uses HOG + SVM algorithm to detect human shapes
- Analyzes body proportions and features
- Draws red boxes around detected humans
- Calculates confidence score
-
Motion Detection (Backup)
- Background subtraction algorithm
- Frame differencing for sensitivity
- Detects any significant movement
- Draws green boxes around motion
-
Alert System
- Captures screenshot when detection occurs
- Verifies image quality (brightness, file size)
- Sends photo + details to Telegram
- Implements cooldown to prevent spam
Problem: Black screen or "Cannot open webcam"
Solutions:
β
Close other apps using camera (Zoom, Skype, Teams, etc.)
β
Try different USB port (for external webcams)
β
Check Windows Camera app to verify camera works
β
Restart computer
β
Update camera drivers
Problem: Dark/black images sent to Telegram
Solutions:
β
Turn on room lights
β
Adjust camera position
β
Increase MOTION_THRESHOLD value
β
Wait longer for camera auto-exposure (script does this automatically)
Problem: "Telegram connection failed"
Solutions:
β
Verify bot token is correct
β
Verify chat ID is correct (just numbers, no letters)
β
Start your bot (send /start command to it on Telegram)
β
Check internet connection
Problem: Not receiving alerts
Solutions:
β
Check if Telegram notifications are enabled on your phone
β
Verify bot isn't blocked
β
Send /start to your bot
β
Test with send_telegram_message() function first
Problem: Too many false alerts
Solutions:
β
Increase MOTION_THRESHOLD (try 1200, 1500, 2000)
β
Increase MIN_CONTOUR_AREA (try 800, 1000)
β
Enable DETECT_HUMANS = True for better accuracy
β
Increase MIN_HUMAN_CONFIDENCE (try 0.4, 0.5)
β
Position camera to avoid moving objects (curtains, fans, pets)
Problem: Not detecting humans/motion
Solutions:
β
Decrease MOTION_THRESHOLD (try 500, 300)
β
Decrease MIN_CONTOUR_AREA (try 300, 200)
β
Decrease MIN_HUMAN_CONFIDENCE (try 0.2, 0.15)
β
Ensure good lighting in room
β
Test by waving in front of camera
β
Check preview window for visual feedback
The live preview shows:
- π΄ Red boxes - Detected humans
- π’ Green boxes - Motion detection
- π Status text - Current detection state
- π Motion score - Real-time sensitivity indicator
- π€ Human count - Number of people detected
Controls:
- Press
Qto quit preview window - Minimize window to run in background
antispy_bot/
βββ motion_detector.py # Main script
βββ README.md # This file
βββ requirements.txt # Python dependencies
βββ alert_*.jpg # Temporary alert images (auto-deleted)
β οΈ Never share your bot token - It's like a password- π Bot token grants full access to send messages
- π± Only you (your Chat ID) receives alerts
- ποΈ Alert images are auto-deleted after sending
- πΎ No data is stored or uploaded anywhere except Telegram
- π Consider regenerating bot token if accidentally exposed
- Press
Win + R - Type
shell:startup - Create shortcut to
motion_detector.py - Set to run minimized
# Create systemd service
sudo nano /etc/systemd/system/motion-detector.service
# Add service configuration
[Unit]
Description=Room Motion Detector
After=network.target
[Service]
ExecStart=/usr/bin/python3 /path/to/motion_detector.py
Restart=always
User=yourusername
[Install]
WantedBy=multi-user.target
# Enable and start
sudo systemctl enable motion-detector
sudo systemctl start motion-detectorModify line in script:
cap = cv2.VideoCapture(0) # 0 = first camera, 1 = second, etc.Modify the caption in detect_motion() function:
caption = f"π¨ Custom message here!\nπ
{timestamp}"- Windows Camera Lag - First few frames may be slow (fixed with warmup)
- CPU Usage - Can be high with human detection (run on less frames)
- False Positives - Shadows, curtains, pets (adjust thresholds)
Found a bug? Want to improve it?
- Fork the repository
- Make your changes
- Test thoroughly
- Submit pull request
MIT License - Free to use and modify
- π Home Security - Monitor your room while away
- π΄ Sleep Monitoring - Alert when someone enters while sleeping
- π’ Office Security - Monitor empty office spaces
- πΆ Baby Monitor - Enhanced baby room monitoring
- π Pet Monitoring - Check when pets enter restricted areas
- π¦ Package Detection - Alert when deliveries arrive
Having issues?
- Check troubleshooting section above
- Verify all requirements are installed
- Test camera with Windows Camera app
- Test Telegram bot with manual messages
- Check preview window for visual debugging
- Multiple user support
- Discord/WhatsApp integration
- Video recording option
- Cloud storage integration
- Mobile app
- Face recognition
- Sound detection
- Email alerts
Algorithms Used:
- HOG (Histogram of Oriented Gradients) for human detection
- MOG2 (Mixture of Gaussians) for background subtraction
- Frame differencing for motion detection
- Gaussian blur for noise reduction
- Morphological operations (dilation) for better detection
Performance:
- ~30 FPS on modern laptops
- <5% CPU usage (motion only)
- ~15-20% CPU usage (with human detection)
- <50MB RAM usage
- Instant alerts (<2 seconds delay)
Made with β€οΈ for better home security
Stay Safe! π‘οΈs