Treat the camera view as part of the model
A detector cannot recover detail that the camera never captured. Choose a view where vehicles remain visible long enough to be detected and tracked, where entry and exit paths are separable, and where headlights, shadows, rain, or gate structures do not dominate the image. Mounting height and angle should minimize severe overlap between vehicles.
Before training or tuning anything, collect representative clips at busy, quiet, day, night, and adverse-weather periods. Mark the intended counting line or polygon on these clips. A technically convenient camera may be unsuitable if vehicles cross in groups or if motorcycles disappear behind larger vehicles.
Separate detection from tracking
The detector answers what appears in each frame. The tracker answers whether an object in the current frame is the same object seen previously. Counting directly from detections usually produces duplicates because the same vehicle appears in many frames. A tracker assigns an identity and maintains it through short occlusions.
Validate tracker behavior in the actual scene. A high detector confidence threshold can cause tracks to break; a low threshold can create false tracks. Track age, matching threshold, and frame rate affect how identities survive. Keep debug overlays that show the box, class, track ID, trajectory, and counting state so errors can be explained.
Define counting as a state transition
A vehicle should be counted when a confirmed track moves through a defined sequence, such as outside zone → gate zone → inside zone. A single line crossing may be enough for a simple lane, but direction and jitter still need handling. Use hysteresis or separate entry and exit regions so a stationary vehicle near the line is not counted repeatedly.
Count only mature tracks that have existed for enough frames. Record the track ID, class, direction, timestamp, and confidence at the event. Keep a short evidence frame or clip only when the business and privacy requirements allow it. This event record makes later comparison with manual counts possible.
Handle class definitions honestly
The business may want cars, motorcycles, trucks, buses, and vans, while the model may use different categories. Create an explicit class mapping and test confusion between visually similar classes. If the deployment requirement is total vehicles, a stable total may be more reliable than promising fine-grained classes in a difficult view.
Use a review set sampled from the site, not only public datasets. Report precision, recall, and count error by period and class where possible. A single headline accuracy number can hide failures during night traffic or heavy occlusion. Document which classes and conditions are accepted at commissioning.
Control compute load and latency
Edge hardware has a fixed thermal and power budget. Resolution, inference size, frame rate, model architecture, decoder load, and video encoding all compete for resources. Measure end-to-end throughput on the target board. Processing every camera frame is not always necessary if the scene changes slowly and tracking remains stable at a lower rate.
Use a bounded queue so delayed frames are dropped rather than processed minutes late. Monitor temperature, memory, inference time, stream reconnects, and skipped frames. A reliable service should restart after a camera or network interruption and expose health information to the dashboard.
Design the data outputs for operations
Publish current counts through a small API or WebSocket and write durable event records to a database or daily CSV. Include a configuration file for camera URL, credentials reference, region geometry, class mapping, thresholds, and output location. Keep secrets outside source control.
Distinguish current occupancy from cumulative entry and exit totals. Occupancy requires an initial state and a reconciliation method when the service restarts or a count is missed. Provide operators with a reset or correction workflow and log adjustments rather than silently changing totals.
Commission against ground truth
Create manual reference counts for selected intervals that include difficult conditions. Compare event by event when possible, not only total by total. Review false positives, missed vehicles, wrong direction, duplicate counts, and class errors. Fix camera geometry and counting logic before reaching for a larger model.
At handover, include the Docker or service configuration, model version, region file, sample footage policy, API description, health checks, performance results, and known limitations. A dependable deployment is a monitored software system around the model, not merely a set of weights.