A real-time computer vision system that automatically counts people entering and exiting retail stores using YOLO object detection and custom tracking algorithms. Features WhatsApp notifications for shop owners and managers.
- Real-time People Detection: Uses YOLO11 for accurate person detection
- Entry/Exit Tracking: Custom tracking algorithm with polygon-based zones
- WhatsApp Notifications: Instant alerts via Twilio integration
- Video Processing: Supports live camera feeds and video files
- Analytics Display: Real-time counters and visual feedback
- Easy Configuration: Simple setup with configurable detection zones
- Python 3.8 or higher
- Webcam or video file
- (Optional) Twilio account for WhatsApp notifications
- Clone the repository
git clone https://github.com/yourusername/smartshop-counter.git
cd smartshop-counter- Create virtual environment
python -m venv yolovenv
# On Windows:
yolovenv\Scripts\activate
# On macOS/Linux:
source yolovenv/bin/activate- Install dependencies
pip install -r requirements.txt- Download YOLO model (automatically downloaded on first run)
# The YOLO11n.pt model will be downloaded automaticallypython object_count.pypython object_count_with_notifications.py- opencv-python
- numpy
- ultralytics
- twilio (for notifications)
The system uses two polygon zones for entry/exit detection:
# Zone 1: Entry detection area
area1 = [(312, 388), (289, 390), (474, 469), (497, 462)]
# Zone 2: Exit detection area
area2 = [(279, 392), (250, 397), (423, 477), (454, 469)]- Create a Twilio account at twilio.com
- Get your Account SID and Auth Token
- Set up environment variables:
# Create .env file
TWILIO_ACCOUNT_SID=your_account_sid
TWILIO_AUTH_TOKEN=your_auth_token
TWILIO_PHONE_NUMBER=your_twilio_phone
TARGET_PHONE_NUMBER=recipient_phone_number- ESC: Exit the application
- R: Reset notification tracking (notifications version only)
- Mouse: Click to get coordinates for zone configuration
- Person Detection: YOLO11 model detects people in the video frame
- Object Tracking: Custom algorithm tracks individuals across frames
- Zone Analysis: Checks if tracked persons cross defined entry/exit zones
- Counting Logic:
- Person enters Zone 2 โ marked as "entering"
- Person from Zone 2 enters Zone 1 โ counted as "entered"
- Person enters Zone 1 โ marked as "exiting"
- Person from Zone 1 enters Zone 2 โ counted as "exited"
- Notifications: Sends WhatsApp alerts for new entries (if enabled)
The system works with:
- Live camera feeds (webcam)
- Video files (MP4, AVI, etc.)
- RTSP streams
To use a different video source, modify the VideoCapture line:
# For webcam
cap = cv2.VideoCapture(0)
# For video file
cap = cv2.VideoCapture("your_video.mp4")
# For RTSP stream
cap = cv2.VideoCapture("rtsp://your-stream-url")The system displays:
- Real-time video feed with bounding boxes
- Entry/exit counters
- Zone visualization
- Person IDs and tracking
- Notification status
# In tracker.py
tracker = Tracker(distance_threshold=25) # Lower = more sensitive# Use different YOLO model
model = YOLO("yolo11s.pt") # or yolo11m.pt, yolo11l.pt, yolo11x.ptUse the mouse callback to get coordinates:
- Run the application
- Move mouse over desired zone corners
- Note the coordinates printed in console
- Update the area1 and area2 arrays
"No module named 'ultralytics'"
pip install ultralytics"Camera not found"
- Check camera permissions
- Try different camera index (0, 1, 2...)
- Verify camera is not used by other applications
"WhatsApp notifications not working"
- Verify Twilio credentials
- Check phone number format (+1234567890)
- Ensure Twilio account has sufficient balance
"Poor detection accuracy"
- Ensure good lighting conditions
- Adjust detection zones
- Try different YOLO model size
humanflow-tracker/
โโโ object_count.py # Basic counting system
โโโ object_count_with_notifications.py # With WhatsApp alerts
โโโ tracker.py # Custom tracking algorithm
โโโ requirements.txt # Python dependencies
โโโ env_example.txt # Environment variables template
โโโ outside_shop.mp4 # Sample video
โโโ yolovenv/ # Virtual environment
โโโ README.md # This file
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Ultralytics for YOLO implementation
- OpenCV for computer vision capabilities
- Twilio for WhatsApp integration
If you encounter any issues or have questions:
- Check the Issues page
- Create a new issue with detailed description
- Include system information and error logs
Made with โค๏ธ for retail businesses