People counting solution

Copyright © Quectel Wireless Solutions Co., Ltd. 2026. All rights reserved.


Built on the Quectel Pi H1 smart single-board computer, this project is a lightweight foot-traffic analytics solution integrating object detection, multi-object tracking, and person re-identification (ReID). Key features include:

  • Real-time pedestrian detection: Localizes and detects human targets across video streams in real time.

  • Robust object tracking: Leverages the ByteTrack algorithm for high-precision, persistent tracking.

  • Smart deduplication: Eliminates duplicate counts based on ReID feature embeddings to identify unique individuals.

  • Multi-source video support: Out-of-the-box compatibility with USB cameras, IP cameras (RTSP), and local video files.

  • Multi-dimensional analytics: Tracks real-time occupancy/headcount, cumulative unique visitor counts, and directional entry/exit flow.

../../../_images/image_M57vbkWVfoOrd1xVwtgcK5EAn3I.webp

Development resource summary

Development accessory list

Note

The following accessories list is for reference only. The actual development environment can be adjusted according to requirements. For example, when you develop via SSH remote connection, the display and USB hub can be omitted. Select a camera according to actual requirements.

Accessory

Quantity

Specifications

Quectel Pi H1 smart single-board computer

1

-

Power adapter

1

Official 45W USB Type-C Power Supply for Raspberry Pi 5, White Color, US Plug

Micro HDMI cable

1

HDMI 2.0; Cable length: 1 m; HDMI-A (male) to HDMI-D (male)

Network cable

1

Length: 1 m; Transmission rate: Gigabit

CPU cooling fan (optional)

1

Raspberry Pi 5 Official Active Cooler with Thermal Pad

USB docking station (optional)

1

UGREEN USB 3.0 multifunction docking station

Network camera

1

Tenda indoor home surveillance camera

OV5693 USB camera module

1

OV5693 5MP USB camera module

HDMI monitor

1

HDMI monitor

Physical reference of accessories

../../../_images/image_Dc3Ub9Xv8oBkVwxlQa7cvbiHnbe.webp

Quick start

Development preparation

The Quectel Pi H1 comes pre-installed with Debian 13, so reflashing the OS image is typically not required. Follow the steps below to get started:

Hardware connection

Complete all hardware connections by following the steps below. The step numbers match the labels in the interface diagram.

../../../_images/image_JCaNbmAN5oNB16xaNKCc93mRneh.webp
  1. Display connection: Connect one end of the Micro HDMI cable to the Micro HDMI port on the board and the other end to the HDMI port on the monitor.

  2. Network connection: Ensure that the router is connected to the internet. Connect one end of the Ethernet cable to the Gigabit Ethernet port on the board and the other end to the Ethernet port on the router.

  3. Input device connection: Connect the USB keyboard, mouse, and OV5693 USB camera module to the USB ports on the docking station. Then connect the docking station to a USB port on the board. If you are using wireless input devices, connect the wireless receiver to a USB port on the docking station.

  4. Power connection: Connect the USB-A end of the USB-A power cable to the output of the power adapter and the USB-C end to the power input on the board (usually labeled POWER IN).

  5. Cooling fan connection: First plug the cooling fan cable into the FAN connector on the board, then secure both sides of the heat sink in the reserved mounting holes on the board.

  6. Network camera connection: Connect the network camera to a power source using its supplied power cable, and ensure that it is on the same local area network as the board.

Complete connection diagram

../../../_images/image_FmKybQlIbonBbUxFbZlckRYmnBh.webp

Model preparation

Object detection model

  • YOLOv8n model: YOLOv8n.pt ;

  • Input resolution: 640 × 640 (H × W)。

Note

All model weights are bundled directly within the project under the src/ directory—no additional downloads required.

Person re-identification (ReID) model

  • **ReID model:**osnet_x0_25_market1501.onnx;

  • Input resolution: 256 × 128 (H × W);

  • Feature dimension: 512-dimensional normalized feature vector.

Note

If you plan to swap in a custom ReID model, ensure the checkpoint is fine-tuned on dedicated re-identification datasets such as Market-1501. Do not use raw ImageNet classification pre-trained models without ReID fine-tuning, as they cannot generate sufficiently discriminative embeddings for identity matching.

Counting logic overview

Count types

  1. Current count: Number of active targets detected in the current video frame.

  2. Total count: Historical cumulative unique headcount deduplicated by unique track_id.

  3. In/ out count: Directional entry/ exit tracking based on a virtual tripwire.

Counting methodology

  • Current count: Directly counts the number of actively tracked targets in the current frame.

  • Total count: Maps each newly generated track_id to a unique individual to ensure cumulative accuracy.

  • In/ out count: Determines movement direction relative to a virtual tripwire (defaults to the horizontal centerline of the frame):

    • In: Target moves downward (Y-coordinate increases).

    • Out: Target moves upward (Y-coordinate decreases).

    • Evaluates crossing direction based on the historical trajectory of the target's centroid.

    • Each track_id is only counted upon its initial crossing to prevent double counting.

Custom tripwire configuration

The current release supports configuring the position and orientation of virtual detection lines using either normalized ratios or absolute pixel coordinates:

  • Horizontal detection line: direction='horizontal', line_position=<specified_y_coordinate>

  • Vertical detection line: direction='vertical', line_position=<specified_x_coordinate>

Parameter details:

  1. Normalized ratio (recommended): Accepts values from 0.0 to 1.0. For example, 0.5 targets the exact center of the frame, while 0.8 corresponds to the 80% mark. This option is resolution-agnostic and will not break if stream resolution changes.

  2. Absolute pixel value: The valid range depends on the camera's actual stream resolution. For instance, at 640 × 360 resolution, the Y-axis spans 0 to 360; at 1080p, the Y-axis spans 0 to 1080.

Crossing direction logic

To ensure accurate counting, the system determines crossing direction based on coordinate shifts of the bounding box centroid (or bottom-center point). The default conventions are defined as follows:

  1. Vertical Detection Line (direction='vertical')
    Target moves horizontally (X-axis) across the vertical line:

    • In: Crosses from left to right (X-coordinate increases, e.g., transitioning from x < line_position to x > line_position).

    • Out: Crosses from right to left (X-coordinate decreases, e.g., transitioning from x > line_position to x < line_position).

  2. Horizontal Detection Line (direction='horizontal')
    Target moves vertically (Y-axis) across the horizontal line:

    • In: Crosses from top to bottom (Y-coordinate increases, e.g., transitioning from y < line_position to y > line_position).

    • Out: Crosses from bottom to top (Y-coordinate decreases, e.g., transitioning from y > line_position to y < line_position).

Deployment guidelines

Camera placement

  • Mount the camera directly overhead or to the side of the pathway, ensuring the field of view (FOV) covers the entire transit zone so individuals remain continuously visible throughout the counting area.

  • The recommended mounting height is 2.2–3.5 m (for ceiling mounts, tilt downward at a 15°–45° angle). Mounting too low increases occlusion and causes truncated lower-body silhouettes.

  • Avoid glass partitions, reflective glass walls, and strong backlighting to prevent severe glare, flare, or visual obstructions.

  • Keep the area surrounding the detection line clear of large pillars, shelving units, or foliage to prevent temporary line-of-sight occlusions.

Orientation and angle recommendations

  • Prioritize a forward-facing, slightly downward perspective with a recommended pitch angle of 15°–45°. An eye-level perspective increases inter-person occlusion, while an overly steep top-down view compresses human bodies into small, low-profile targets.

  • If using a side mount, keep the angle between pedestrian movement and the camera's optical axis as acute as possible to avoid edge-grazing paths that clip target silhouettes.

  • Ensure the camera bracket is rigidly secured to eliminate camera shake from wind or mechanical vibrations. Position the virtual tripwire near the center of the frame where tracking is stable and target silhouettes are fully visible.

Lighting recommendations

  • Use even, diffused frontal lighting. As a rule of thumb, ensure human silhouettes are clearly distinguishable with no heavy, trailing ground shadows.

  • Minimize backlighting, harsh sidelight, and direct sunlight. Prevent direct sunlight from entering the camera lens, as lens flare and extreme contrast degrade detection and tracking accuracy.

  • Add supplemental fill lighting or infrared (IR) illuminators for low-light conditions. Maintain stable ambient illumination to eliminate flicker and rapid brightness fluctuations.

  • Underexposed scenes, excessive contrast, or blown-out highlights significantly increase false-negative (missed detections) and false-positive rates.

Video input source selection and sourcing guidelines

  • USB cameras: Connected locally to the host device, offering minimal latency and consistent feed stability. Ideal for real-time edge processing and on-site debugging.

  • IP cameras: Highly dependent on network bandwidth, video codecs, packet loss, and compression artifacts. Low resolutions, aggressive bitrates, or unstable framerates will degrade detection and tracking performance.

  • Local video files: Best suited for algorithmic validation, bench testing, and offline benchmarking. Note that differences in decoding pipelines, frame pacing, and playback mechanisms mean pre-recorded files may not perfectly replicate live-stream production environments.

Project deployment

Network camera configuration

When using the network camera for the first time, first connect the phone to the same Wi-Fi network, and then use the Tenda app to add the camera and complete the network configuration.

Note

Ensure that the Quectel Pi H1 smart single-board computer and the network camera are on the same local area network; otherwise, the camera's RTSP video stream cannot be retrieved.

Obtain project code

  1. Open a terminal and run the following commands to install Git and clone the project code:

sudo apt update
sudo apt install -y git
git clone https://github.com/Quectel-Pi/demo-people-counting-device.git
  1. Set directory permissions:

sudo chmod -R 755 ~/demo-people-counting-device
  1. Install project dependencies:

cd demo-people-counting-device
pip install --upgrade pip
pip install -r requirements.txt

Camera parameter configuration (optional)

Note

The IP address of the network camera can be obtained from the device information page in the Tenda app.

On the board, open the Firefox browser and enter the "IP address of the webcam". Use the default username: admin and password: admin123456 to enter the backend and set the video encoding type to H.264 and the audio encoding type to AAC.

Launch application

Enter the project source code directory and run the corresponding script:

cd /src
# Run IP camera version
python3 ip_camera_main.py
# Or run USB camera version
python3 usb_camera_main.py
# Or run local video test version
python3 local_video_main.py --video ../assets/street.mp4
  • --video: Specify the video file path (required)

  • --model: Specify the YOLO model path (optional; defaults to yolov8n.pt)

Application demo

people-counting-device

Troubleshooting

Q1: Camera fails to open

Resolution:

  • Add the current user to the video group:

sudo usermod -aG video $USER  # Applies to local USB cameras only
  • Re-login to the session for group permissions to take effect.

  • Check whether the camera device is locked by another process:

sudo lsof /dev/video*

Q2: Model loading failure

Resolution:

  • Ensure you run the script from the src/ directory (all model files reside here).

  • Do not switch out of the working directory; execute the launch command directly within src/.

Q3: IP camera connection failure

Resolution:

  • Test network reachability: ping <camera_ip>.

  • Verify that the camera's ONVIF service is enabled.

Q4: System performance degradation/ lag

Resolution:

  • Disable ReID prior to launch: export BYTETRACK_USE_REID=0 (or pass it inline: BYTETRACK_USE_REID=0 python3 ...).

  • Lower the display window resolution.

Technical support and contributions

If you encounter any issues during use, please submit technical inquiries on the Quectel Official Forum. Our technical support team will respond promptly.

Project open-source repository: https://github.com/Quectel-Pi/demo-people-counting-device

Welcome to submit an issue to report a problem or a pull request to improve the code.