This project implements a real-time drone detection system using the YOLOv5 model, OpenCV for video processing, Twilio for SMS notifications, and Pygame for audio alerts. It detects drones via a webcam feed, draws bounding boxes with confidence scores and coordinates, and triggers alerts (SMS, looping audio, and video recording) when a drone enters a user-defined restricted area.
- Real-Time Drone Detection: Utilizes a pre-trained YOLOv5 model to detect drones in a live webcam feed.
- Restricted Area Monitoring: Allows users to define a draggable rectangular area to monitor for drone intrusions.
- SMS Notifications: Sends SMS alerts via Twilio when a drone is detected in the restricted area (with a 10-second cooldown).
- Continuous Audio Alerts: Plays a looping audio alert (
alert.mp3) when a drone is detected, stopping when the drone leaves the restricted area. - Video Recording: Records video clips (
drone_alert.mp4) during detections in the restricted area. - Interactive UI: Displays bounding boxes, confidence scores, coordinates, and warning messages ("Enemy Drone Detected!!Warning!!Warning!!") on the video feed.
- Hardware:
- Webcam (default camera, index 0).
- Computer with Python 3.8 or higher.
- Audio output device (e.g., speakers) for alert sounds.
- Software:
- Python libraries:
opencv-python,torch,numpy,pillow,twilio,pygame. - YOLOv5 model weights file (
trained.pt), trained on a drone dataset. - Audio file (
alert.mp3) in the project directory.
- Python libraries:
- Twilio Account:
- Sign up for a free account at Twilio.
- Obtain your Account SID, Auth Token, and a Twilio phone number from the Twilio Console.
- Verify the recipient phone number in the Twilio Console (required for trial accounts).
- Optional:
ffmpegfor converting audio files (ifalert.mp3needs to be converted to WAV).
- Clone the repository:
git clone https://github.com/Programiz-007/CV_Drone_Detection_With_Alert.git
- Inside your project directory, create a virtual environment
python -m venv venv
- Activate the virtual environment
.\venv\Scripts\activate
- Install the required Python libraries:
pip install -m requirements.txt
- Run the script:
python drone_detect.py
-
Enhanced Security Real-time detection of drones for improved security in airports, public events, and restricted areas.
-
Automated Monitoring Reduce manual surveillance by automating the drone detection process using computer vision and machine learning.
-
Customizable and Interactive Define and adjust the detection area using an interactive rectangle for accurate and adaptable detection.
-
Real-time Feedback Instant detection and warning messages provide immediate responses to potential drone threats.
-
Open-source and Extendable You can access the open-source codebase for customization and integration into existing security systems.
-
Scalable and Cost-effective Efficient utilization of resources with a balance of accuracy and performance, resulting in cost savings.
The script will open a live video feed from the default camera.
- To create a rectangle, click and drag the mouse on the video feed to define the four corners of the rectangle.
- The rectangle can be adjusted by dragging the corners.
- A warning message will be displayed whenever a drone is detected inside or near the rectangle.
- Alert/Warning Alarm will also be triggered.
- Alert Notification as an SMS will be received.
- Press 'e' to exit the program.
- Adjust the confidence threshold (
conf) to control the sensitivity of detection. - Try to take this to an IoT project to see real-time sensing with the help of microcontrollers and sensors.
-
Audio Issues:
- Error:
Error playing sound: ...or no sound. - Fix: Ensure
alert.mp3exists in the project root and is valid. Test with a media player. Convert to WAV if needed (ffmpeg -i alert.mp3 alert.wav). Check system audio settings (e.g., speakers enabled). - Alternative: Use a different audio file or library (e.g.,
simpleaudio).
- Error:
-
SMS Issues:
- Error:
SMS failed: ...(e.g., "21614: Number not verified"). - Fix: Verify the recipient number in Twilio Console. Ensure correct phone number format. Check Twilio logs for error codes.
- Cost: Trial accounts are free but limited. Upgrade for production use.
- Error:
-
Model Issues:
- Error: Detection fails or no drones detected.
- Fix: Verify
best.ptis trained on a drone dataset. Adjust confidence threshold (conf > 0.7) in the script if needed. Retrain with a suitable dataset if accuracy is low.
-
Webcam Issues:
- Error: Webcam feed not opening.
- Fix: Ensure the webcam is connected and accessible (test with
cap = cv2.VideoCapture(0); print(cap.isOpened())). Try index 1 or 2 (cv2.VideoCapture(1)).
-
Performance:
- Issue: Lag in video feed.
- Fix: Reduce
size=640tosize=416in the script or lower the frame rate (cv2.waitKey(10)).
Contributions are welcome! To contribute:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/YourFeature). - Commit changes (
git commit -m "Add YourFeature"). - Push to the branch (
git push origin feature/YourFeature). - Open a pull request with a description of your changes.
Please include tests and update documentation for new features.
This project is licensed under the MIT License. See the LICENSE file for details.
- Ultralytics YOLOv5 for the object detection model.
- Twilio for SMS notification services.
- Pygame for audio playback.
- OpenCV for video processing.


