This project detects motion using OpenCV in Python and sends notifications with photos to a Telegram chat.
- Motion detection using
OpenCVand background subtraction. - Integration with
Telegram Bot APIfor notifications. - Adjustable parameters for motion sensitivity and cooldown periods.
- Python 3.6 or higher
- Requests library (for sending HTTP requests)
- Telegram Bot API credentials (Bot Token and Chat ID)
-
Clone the repository:
git clone https://github.com/arunishrajput/motion-detection.git cd motion-detection -
Install dependencies:
pip install -r requirements.txt
Or install the libraries manually:
pip install opencv-python requests
-
Setup Telegram Bot:
- Create a Telegram bot using BotFather and note down the
Bot Token. - Obtain your
Telegram Chat IDusing userinfobot.
- Create a Telegram bot using BotFather and note down the
-
Configuration:
- Replace placeholders in the script (
TELEGRAM_CHAT_IDandTELEGRAM_BOT_TOKEN) with your actual Telegram credentials.
-
Run the Script:
python main.py
-
Motion Detection:
-
Adjust
cameravariable (0 for default camera) or specify a video file path. -
Customize
initial_delay_seconds,motion_cooldown_seconds, andthresholdas per your requirements.
-
-
Exit:
- Press Esc key to exit the application.
- Captures frames from the camera or video file.
- Defines a smaller square area in the frame for motion detection.
- Sends a Telegram notification with a photo when motion is detected.
- Uses background subtraction and contour detection for motion identification.
- Ensure Python environment and dependencies are correctly installed.
- Verify Telegram credentials and network connectivity for sending notifications.
- Feel free to fork this repository, create a feature branch, and submit a pull request. Contributions, issues, and feature requests are welcome!