How mchockalingam/computervision works
Project type and purpose
• This is a command-line Python application for video-based object detection, tracking and counting of vehicles.
• It uses Ultralytics YOLOv8 for detection, OpenCV for video I/O, Supervision (with ByteTrack under the hood) for tracking and annotation, and Numpy/TQDM for filtering and progress display.
File structure
• Top-level scripts
– app.py → Main entry point: orchestrates video loading, detection, tracking, counting, annotation, and output
– model-names.py → Utility to list class names from a YOLOv8 model
– run.sh, setup.sh → Shell scripts to bootstrap the environment and launch the application
• Supporting files
– requirements.txt → Python dependencies
– readme.md → Project overview, usage, and configuration instructions
• No deep subdirectories; all core logic lives in app.py with imports from external libraries
Key insights from README
• Workflow: download or reference a video → read frames → detect vehicles → filter by class IDs → track across frames → count when crossing predefined line zones → annotate and write output video
• All configuration (model file path, class IDs, line coordinates) lives in app.py
• Dependencies: Ultralytics, OpenCV-Python, Supervision (and ByteTrack), Numpy, TQDM; optional yt-dl + ffmpeg for YouTube ingestion
Main components and interactions
a. Video Source
• Local video file OR YouTube via youtube-dl.py + ffmpeg
b. Frame Reader (OpenCV VideoCapture)
↓
c. Detection Module (YOLOv8 loaded via Ultralytics API)
• Inputs: frame
↓
d. Filter Module (NumPy)
• Keeps only selected vehicle classes (car, motorcycle, bus, truck)
↓
e. Tracking & Annotation (Supervision + ByteTrack)
• Assigns persistent IDs to objects
• Defines LineZone(s) for counting
• Counts when a tracked object crosses a line
↓
f. Video Writer (OpenCV or Supervision helper)
• Writes annotated frames to output file
g. Stats & Progress (TQDM)
• Displays processing progress and final counts
Architectural patterns and design principles
• Pipeline pattern: sequential processing of frames through modular stages
• Single responsibility: app.py coordinates modules; each library handles its domain (detection, tracking, I/O, annotation)
• Configurable constants: class IDs, line coordinates, model paths defined up-front for easy customization
Details not to miss
• Runtime environment setup (setup.sh → virtualenv & requirements.txt) feeding into app.py
• Configuration inputs: model file path, class ID array, line coordinates