This project combines an ESP32-Cam, YOLOv5, and Telegram API to create a smart surveillance system capable of detecting people and sending alerts directly to your phone. The ESP32-Cam streams video to your computer, where YOLOv5 processes it in real time. When a person is detected, the system captures an image, sends it to a Telegram bot, and logs relevant details.
- ESP32-Cam Integration: Configured to act as a video stream server.
- Real-Time Object Detection: Powered by YOLOv5 for accurate and fast person detection.
- Telegram Alerts: Sends detection messages and captured images directly to your Telegram chat.
- Customizable WiFi Modes: Station or Access Point.
- Simple and Modular Code: Easy to extend or modify for your needs.
- ESP32-Cam (LilyGo T-Camera S3 used in this project)
- USB to Serial Adapter for programming the ESP32-Cam
- PlatformIO (for programming the ESP32-Cam):
- Python (3.8 or later)
- Required libraries:
torchopencv-pythonrequestscolorama
- Required libraries:
- Telegram Bot API:
- Follow the Telegram Bot API Documentation to set up a bot.
-
Clone this Repository:
git clone https://github.com/cyprienbf/ESP32_YS.git cd ESP32_YS/ESP32_Camera code- Follow the instructions to install the necessary libraries.
-
Configure the
platformio.iniand thepartitions.csvFile if needed:[platformio] src_dir = src [env:t-cameras3] platform = espressif32@6.9.0 framework = arduino board = esp32s3box board_build.partitions = partitions.csv upload_speed = 921600 monitor_speed = 115200 build_flags = -DBOARD_HAS_PSRAM -DARDUINO_USB_CDC_ON_BOOT=1
-
Flash the Code:
- Adjust the WiFi SSID and password in the
WiFiSettingssection of the code, located in theESP32_Camera.inofile. - Use PlatformIO to upload to the ESP32-Cam.
- Adjust the WiFi SSID and password in the
-
Test the Camera Stream:
- Configure the OV2640 camera via the short URL (e.g.,
http://<ESP32_IP>). - Access the stream via the URL shown in the serial monitor (e.g.,
http://<ESP32_IP>:81/stream).
- Configure the OV2640 camera via the short URL (e.g.,
-
Install Required Libraries:
cd ../YoloSurveillance/ pip3 install -r requirements.txt code -
Install Required Tools
- PyTorch (Ensure compatibility with your CUDA version, e.g., CUDA 12.4).
pip3 install torch torchvision torchaudio
- CUDA Toolkit (if using Nvidia GPU acceleration).
-
Edit
main.py:- Update the following fields:
class Camera: SOURCE = "http://<ESP32_IP>:81/stream" # Replace with your ESP32-Cam stream URL class TelegramAPI: BOT_TOKEN = "<YOUR_TELEGRAM_BOT_TOKEN>" # Replace with your bot token CHAT_ID = "<YOUR_TELEGRAM_CHAT_ID>" # Replace with your chat ID
- Train and use your own model or use YOLOv5's pretrained model (
yolov5sis recommended and as default in this project). Seemodel = torch.hub.load("ultralytics/yolov5", "yolov5s")
- Update the following fields:
-
Run the Python Script:
python main.py
- Point the ESP32-Cam at an area with people.
- The script will detect individuals and send an alert with the following:
- Detection confidence
- Coordinates of the detected object
- Captured image via Telegram.
- Adjust the confidence threshold and detection delay in
main.pyto suit your requirements:class Settings: CONFIDENCE = 0.6 # Adjust confidence threshold DETECTION_DELAY = 0.5 # Adjust delay in seconds
- Detection Targets Accuracy:
- Training your own model or using a better pretrained one.
- Expanding Functionality:
- Add a web dashboard for real-time monitoring.
- Power Management:
- Consider using a battery-powered ESP32-Cam with sleep modes for a portable solution.
This project is open-source and available under the MIT License.