A YOLOv8-based object detection pipeline that counts products crossing a center region of interest in real time, built with Qualcomm QIM SDK and QNN HTP acceleration.
Introduction
Counting products as they move along a conveyor belt or production line is a common but essential task in manufacturing, packaging, and warehouse environments. Manual counting is difficult to scale, while basic frame-by-frame object detection can easily over-count the same item as it appears across multiple consecutive frames. The Product Counting Application addresses this challenge with a Qualcomm QIM SDK pipeline that combines a YOLOv8 object detector with a center region-of-interest (ROI) counting strategy. Instead of counting every detection in every frame, the application defines a narrow vertical band in the center of the camera view. The count increases only when a tracked object’s centroid passes through this band, similar to how a physical counting gate would operate on a production line. Inference runs fully on-device through the QNN HTP delegate, keeping the YOLOv8 TFLite model off the CPU and allowing the counting logic to keep pace with the live camera stream. Between detection and counting, a lightweight object tracker assigns each item a stable identity across frames, ensuring that each object is counted only once—even if it briefly leaves and re-enters the ROI.Use Case Overview
Video Capture
YOLOv8 Detection
Metadata Delivery
appsink callback as JSON.Center-ROI Evaluation
Cumulative Tracking
Overlay Rendering
Pipeline diagram

Elements used in pipeline
How it works
Capture and Format
v4l2src captures the raw camera feed, which is normalized to a fixed NV12 resolution and frame rate before a tee splits it into an inference branch and a reference branch.Detection
qtimlvconverter to prepare frames, then qtimltflite executes the quantized YOLOv8 model (/etc/models/yolov8_det_w8a8.tflite) via the QNN HTP delegate. qtimlpostprocess, using the yolov8 module, decodes the raw output into bounding boxes, and qtimetamux merges the detections back onto the reference video frame.Metadata Delivery
tee sends the metadata-carrying stream down both a display branch and a metadata branch. The metadata branch parses detections into JSON and hands them to the count_sink appsink callback for every frame.Flexible Metadata Parsing
Center-ROI Evaluation
Cumulative Tracking
Overlay and Display
cairooverlay draws the ROI rectangle and the current count on top of the qtivoverlay-annotated frame before waylandsink renders the result.Setup Requirements
Hardware

Software
Flash your Qualcomm Edge device by following the device setup and flashing instructions here, then install the Python and GStreamer prerequisites (python3, gstreamer1.0, python3-gi) needed to run the pipeline.
The YOLOv8 detection model and its labels are expected at /etc/models/yolov8_det_w8a8.tflite and /etc/labels/yolov8.json respectively.
Try me
Try me
- C++
- Python
demo_product_counting/main.ccPre-built application on device: /usr/bin/qimsdk_demo_product_countingDownload Required Files
.zip archive, extract it on your host machine before copying: unzip filename.zipCopy Files to Device
Connect a USB camera
/dev/video2 (update the --input-config value below if your camera is exposed on a different node).Run the application
Application Function Breakdown
The Product Counting application is organized into a handful of function groups, each responsible for one stage of the detection-to-count flow:- Metadata parsing: normalizes incoming JSON keys and extracts label, confidence, and bounding-box values regardless of which detection-list or bbox key names the post-processing module emits.
- ROI and counting: computes the center ROI band from the frame dimensions and tests whether a detection’s centroid falls inside it.
- Object tracking: a cumulative tracker that assigns stable IDs, matches detections across frames using centroid distance, IoU, label, and motion prediction, smooths bounding boxes, tolerates brief dropouts, and prevents duplicate counts while still supporting re-entry counting.
- Rendering: draws the ROI rectangle and the current count text onto the display branch each frame.
- Callback and pipeline utility: the
appsinkcallback that receives each frame’s metadata, a helper that selects the correct metadata-parser element name at runtime, and setup logic that wires the runtime hooks together before the pipeline starts.
Expected Output
Running the application opens a live view on the connected monitor:- The camera feed is shown with YOLOv8 detection boxes and labels overlaid.
- A green vertical rectangle marks the center counting ROI, spanning the full frame height.
- A running “ROI Objects Counted” total is drawn on screen and increments as tracked objects pass through the ROI.
- Objects that leave and re-enter the ROI are counted again, while objects lingering inside it are not double-counted.
Ctrl+C to stop the application; the pipeline transitions to the NULL state and releases the camera and display cleanly.

