Skip to main content
QIM SDK · Qualcomm
Computer Vision

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.

QIM SDK Team·Aug 3, 2026·← All posts

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

1

Video Capture

A USB camera feed is captured and normalized to a fixed resolution, format, and frame rate before entering the inference branch.
2

YOLOv8 Detection

Frames are preprocessed and passed through a quantized YOLOv8 model on the QNN HTP delegate, producing per-frame bounding box detections.
3

Metadata Delivery

Detection metadata is synchronized with the video stream and delivered to the application through an appsink callback as JSON.
4

Center-ROI Evaluation

Each detection’s centroid is checked against a vertical counting band spanning the full frame height and the middle third of the frame width.
5

Cumulative Tracking

A tracker matches detections to previously seen objects across frames and increments the count only once per confirmed object, supporting re-entry if an object leaves and comes back.
6

Overlay Rendering

The ROI band and running count are drawn onto the display branch alongside the YOLOv8 detection boxes, and the composited frame is shown on the connected display.

Pipeline diagram

Product Counting Pipeline

Elements used in pipeline

How it works

1

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.
2

Detection

The inference branch runs 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.
3

Metadata Delivery

A second 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.
4

Flexible Metadata Parsing

Because the detection-list and bounding-box key names can vary depending on the post-processing module version, the callback normalizes incoming JSON, checking a set of known key aliases for the detection list and for the bounding box, before extracting label, confidence, and rectangle values.
5

Center-ROI Evaluation

The counting logic defines a vertical band covering the full frame height and the middle third of the frame width, then tests whether each detection’s centroid falls inside that band.
6

Cumulative Tracking

A tracker matches each frame’s detections against previously tracked objects using centroid distance, bounding-box overlap, label agreement, and simple motion prediction. It smooths bounding boxes, tolerates brief detection dropouts, and increments the count only once an object is confirmed inside the ROI, while still allowing the same physical slot to be counted again if an object exits and re-enters.
7

Overlay and Display

The display branch is reformatted to BGRA, and cairooverlay draws the ROI rectangle and the current count on top of the qtivoverlay-annotated frame before waylandsink renders the result.

Setup Requirements

Hardware

HW Setup

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.
Check application source code on GitHub: demo_product_counting/main.ccPre-built application on device: /usr/bin/qimsdk_demo_product_counting

Download Required Files

If the downloaded model file is a .zip archive, extract it on your host machine before copying: unzip filename.zip
1

Copy Files to Device

2

Connect a USB camera

Connect a USB (UVC) camera to the target device and verify it is exposed as /dev/video2 (update the --input-config value below if your camera is exposed on a different node).
3

Run the application

The application overlays YOLOv8 detection bounding boxes on the live USB camera feed and displays a running “ROI Objects Counted” total whenever a detected object’s centroid crosses into the defined region of interest.To stop the application, press CTRL + C.

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 appsink callback 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.
Press Ctrl+C to stop the application; the pipeline transitions to the NULL state and releases the camera and display cleanly.

Conclusion

The Product Counting Application demonstrates how an on-device YOLOv8 detector, a simple spatial rule based on a central ROI band, and a lightweight cumulative tracker can transform raw AI metadata into accurate, real-time counts. QNN HTP acceleration enables detection to keep pace with fast-moving objects, making this approach applicable beyond conveyor belts to any use case that requires counting objects as they cross a defined boundary—from retail shelf monitoring to people-flow and footfall analytics.