Skip to content

cypriennn/ESP32_YS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ESP32-Cam Surveillance System with YOLOv5 and Telegram Integration

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.


Features

  • 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.

Requirements

Hardware

  • ESP32-Cam (LilyGo T-Camera S3 used in this project)
  • USB to Serial Adapter for programming the ESP32-Cam

Software

  1. PlatformIO (for programming the ESP32-Cam):
  2. Python (3.8 or later)
    • Required libraries:
      • torch
      • opencv-python
      • requests
      • colorama
  3. Telegram Bot API:

Installation and Setup

Step 1: Set Up ESP32-Cam

  1. 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.
  2. Configure the platformio.ini and the partitions.csv File 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
  3. Flash the Code:

    • Adjust the WiFi SSID and password in the WiFiSettings section of the code, located in the ESP32_Camera.ino file.
    • Use PlatformIO to upload to the ESP32-Cam.
  4. 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).

Step 3: Configure the Python Script

  1. Install Required Libraries:

    cd ../YoloSurveillance/
    pip3 install -r requirements.txt
    code
  2. Install Required Tools

    • PyTorch (Ensure compatibility with your CUDA version, e.g., CUDA 12.4).
    pip3 install torch torchvision torchaudio
  3. 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 (yolov5s is recommended and as default in this project). See model = torch.hub.load("ultralytics/yolov5", "yolov5s")
  4. Run the Python Script:

    python main.py

Step 4: Test the System

  1. Point the ESP32-Cam at an area with people.
  2. The script will detect individuals and send an alert with the following:
    • Detection confidence
    • Coordinates of the detected object
    • Captured image via Telegram.
  3. Adjust the confidence threshold and detection delay in main.py to suit your requirements:
    class Settings:
        CONFIDENCE = 0.6  # Adjust confidence threshold
        DETECTION_DELAY = 0.5  # Adjust delay in seconds

Usage Notes

  • 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.

References

  1. YOLOv5 GitHub Repository
  2. ESP32-Cam GitHub Repository
  3. Telegram Bot API Documentation

License

This project is open-source and available under the MIT License.

About

ESP32-YOLO Surveillance: AI-Powered Smart Camera System

Topics

Resources

License

Stars

Watchers

Forks

Contributors