If you’d like to use, modify, or integrate this Real-Time Object Tracker in your system
(e.g., for CCTV monitoring, vehicle counting, factory automation, or custom analytics dashboards),
📩 Reach out to me directly:
Email: y.india.main@gmail.com
I’d be happy to:
- Help you customize it for your use case
- Integrate it with your camera setup or backend system
- Add new object categories (cars, bikes, people, etc.)
- Provide advanced ML upgrades (YOLOv8, motion tracking, etc.)
💬 Let’s collaborate and build something powerful together.
The Real-Time Object Tracker and Counter is a powerful computer vision system built using OpenCV that can detect, track, and count moving objects in real time from a live camera or video feed.
It supports multiple color, shape, and object categories, making it useful across industries such as traffic monitoring, retail analytics, factory automation, and security systems.
✅ Real-time object detection using color and shape filters
✅ Object counting when crossing a defined line (region of interest)
✅ Supports 30+ predefined colors (from colors.txt)
✅ Detects multiple shapes (circle, rectangle, triangle, etc.)
✅ Extendable to detect cars, bikes, people, and more
✅ Modular design — easily modify settings via .txt files
✅ Saves real-time logs and counts to CSV for reporting
✅ Works with webcam or video files
real_time_object_tracker/
│
├── main.py # main car detection script
├── utils.py # helper functions
├── haarcascade_car.xml # downloaded vehicle cascade
├── colors.txt # color definitions
├── shapes.txt # shape filters
├── objects.txt # object type definitions
├── README.md # documentation
│
└── logs/
└── car_log.csv # saved logs (will be auto-generated)
Author: Yuvraj
Skills: Python, OpenCV, Pandas, NumPy, Matplotlib, Seaborn, Streamlit, scikit-learn
In many industries, manual counting and monitoring of moving objects is inefficient and prone to human error.
This project solves that problem by providing an automated, camera-based system that detects and counts objects accurately — 24/7, in real time.
| Domain | Example Use Case | Benefit |
|---|---|---|
| 🚗 Traffic Monitoring | Count vehicles crossing an intersection | Analyze traffic flow automatically |
| 🏭 Factories | Count products on a conveyor belt | Improve production tracking |
| 🛍️ Retail Stores | Track customer entries/exits | Analyze footfall data |
| 📦 Warehouses | Count boxes moving through gates | Automate inventory movement logs |
| 🚨 Security Systems | Detect movement in restricted areas | Trigger alerts or logs |
| Category | Tools |
|---|---|
| 🐍 Programming Language | Python 3 |
| 👁️ Computer Vision | OpenCV |
| 🔢 Data Handling | NumPy, Pandas |
| 🧠 ML Extensions (future) | YOLOv8, TensorFlow, scikit-learn |
| 💾 Logging | CSV File Output |
| ⚙️ Configuration | Custom .txt files (for easy modification) |
-
Video Capture
- Reads live feed from a webcam (
cv2.VideoCapture(0)) or a video file.
- Reads live feed from a webcam (
-
Color Detection
- Converts frames from BGR → HSV.
- Applies masks using predefined HSV ranges from
colors.txt.
-
Contour Detection
- Finds object boundaries using
cv2.findContours. - Filters noise and small areas using area thresholds.
- Finds object boundaries using
-
Shape Filtering
- Calculates circularity and aspect ratio for each contour.
- Matches parameters from
shapes.txt.
-
Object Counting
- Draws a counting line (
line_y) across the frame. - Counts each object crossing that line once.
- Draws a counting line (
-
Logging & Display
- Real-time visualization with bounding boxes and counters.
- Saves timestamps and counts to
logs/object_counts.csv.
- Contains 30+ color definitions with lower and upper HSV ranges.
- You can add or edit colors easily.
- Example:
red1,0,120,70,10,255,255
blue,90,100,100,130,255,255
gold,20,100,150,30,255,255
- Modify
color_to_detectinmain.pyto switch target color.
- Defines circularity and aspect ratio for each shape.
- Example:
circle,0.7,1.2,0.8,1.2
square,0.7,1.2,0.8,1.2
rectangle,0.5,0.9,1.3,5.0
triangle,0.4,0.7,0.6,1.4
ellipse,0.6,1.3,0.8,1.5
- Modify
shape_to_detectinmain.pyto target a specific shape.
- Lists real-world object categories (car, bike, person, ball, etc.).
- Specifies detection type:
cv(OpenCV) orml(machine learning). - Example:
ball,Detect circular colored objects,cv
car,Detect moving cars using ML or color+motion,ml
bottle,Detect tall rectangular shapes,cv
- Use this file to extend your project with ML models later.
pip install opencv-python numpy pandaspython main.py- Change
color_to_detectandshape_to_detectinmain.py. - Modify
colors.txtandshapes.txtfor custom color and shape definitions. - Modify
objects.txtfor custom object definitions.
Press q to exit the program.