OUTPUT VIDEO 1 OUTPUT VIDEO 2 OUTPUT VIDEO 3 OUTPUT VIDEO 4
A high performance, edge optimised computer vision pipeline for real time tracking and counting of warehouse packages. Built to run efficiently on CPU constrained devices (like Raspberry Pi) while streaming 40 FPS video to a modern web dashboard.
Counting boxes manually on a packing line is error prone and slow. This system automates the process using a custom YOLO object detection model and ByteTrack, ensuring high accuracy even when boxes are stacked, occluded, or temporarily blocked by a worker's hand.
- "Illusion of Speed" Architecture: The backend uses a 3 thread asynchronous pipeline to completely decouple heavy AI inference from the 40 FPS video reading loop, preventing camera lag.
- Spatial State Machine: Custom tracking logic that handles edge cases like box debouncing, removals (take backs), and deep carton occlusion.
- Zero DOM Lag Frontend: The React dashboard receives streaming JPEG frames via WebSockets and paints them directly to an HTML5
<canvas>using hardware acceleration, completely bypassing React's render cycle for zero browser freezing. - Concurrent Logging: SQLite database running in WAL (Write Ahead Logging) mode ensures the AI thread can log count events without blocking the API's read requests.
Backend (Edge AI & API):
- Python 3.10+
- FastAPI & WebSockets
- OpenCV (Headless)
- ONNX Runtime (CPU Execution Provider)
- Roboflow Supervision (ByteTrack)
- SQLite3
Frontend (Dashboard):
- React 18
- Vite
- Tailwind CSS v4
The system is designed specifically for edge hardware limits:
- Thread 1 (Main): Async FastAPI server handling WebSocket broadcasts and REST endpoints.
- Thread 2 (Inference Daemon): Runs the YOLO ONNX model on the latest available frame, dropping stale frames to prevent queue buildup.
- Thread 3 (Video/Tracker Daemon): Reads the camera at a strict 40 FPS(FPS may vary, but targeted FPS are 40), merges YOLO detections with the ByteTrack Kalman filter, manages the Spatial State Machine, logs to SQLite, and pushes annotated frames to the WebSocket.
Ensure you have Python installed. It is recommended to use a virtual environment (like Conda or venv).
# Clone the repository
git clone [https://github.com/yourusername/logistics-vision.git](https://github.com/yourusername/logistics-vision.git)cd logistics-vision# Install backend dependencies
python -m pip install opencv-python-headless fastapi uvicorn onnxruntime supervision numpy websocketsOpen a new terminal window and navigate to the frontend directory
cd Frontend/logistics-dashboard# Install Node dependencies
npm installFrom the root directory, run the FastAPI server:
python main.pyThe server will start on "http://localhost:8000" and look for a webcam at "VIDEO_SOURCE = 0".
From the Frontend/logistics-dashboard directory, start the Vite development server:
npm run devAll core parameters can be tuned in config.py without digging into the logic:
- VIDEO_SOURCE: Change from 0 (webcam) to an RTSP IP camera stream or .mp4 file.
- TARGET_CLASSES: Filter exactly which YOLO classes to track.
- ROI_POLYGON: Adjust the coordinates of the target carton zone.
- EDGE_MARGIN_PIXELS: Tune the occlusion threshold.
If you are not using the webcam feed. Try to store the video files in the assests folder in the root directory.
# If using Webcam feed
python run_counter.py --model models/best.onnx --source 0# Basic run on a video file
python run_counter.py --source "video_path"# Run with specific model
python run_counter.py --model models/best.onnx --source "video_path"# Save annotated output video
python run_counter.py --model models/best.onnx --source "video_path" --save