Skip to main content

Overview

The --test-image flag allows you to test person detection on a static image file before processing live RTSP streams. This is essential for:
  • Validating detection setup – Verify your model files are loaded correctly
  • Tuning parameters – Find optimal confidence and area thresholds
  • Debugging issues – Understand why detections may be failing
  • Testing hardware – Confirm GPU acceleration is working
Test image mode runs a single detection pass and exits. It does not connect to any RTSP streams.

Basic Usage

Output:

Step-by-Step Guide

1

Prepare a test image

Use any JPEG or PNG image containing people. For best results:
  • Resolution: Similar to your RTSP stream resolution
  • Lighting: Similar conditions to your deployment environment
  • Distance: People at similar distances as your camera setup
Example test images:
2

Run detection with default settings

Test with default configuration:
This uses default thresholds from config.cfg:
  • confidence_threshold = 0.5
  • person_area_threshold = 1000
3

Review the annotated output

Open the generated test_result_*.jpg file:
  • Green bounding boxes around detected persons
  • Confidence scores displayed above each box (e.g., “Person 1: 0.87”)
  • Box dimensions correspond to bounding box size in pixels
Check the console output:
Format: (x, y, width, height, confidence)
4

Adjust thresholds if needed

If results aren’t as expected, tune parameters:
5

Test with your production settings

Once you find optimal parameters, test them:
If results look good, use the same settings for live streams.

Understanding the Output

Console Output Breakdown

Bounding box format: (x, y, width, height, confidence) Box area: width × height = 234 × 456 = 106,704 pixels

Annotated Image

The output image test_result_*.jpg shows:
  • Green rectangles – Bounding boxes around detected persons
  • Labels – “Person 1: 0.87”, “Person 2: 0.72”, etc.
  • Original image – Background preserved, detections overlaid
The annotated image is saved with a Unix timestamp in the filename (e.g., test_result_1741528222.jpg) to prevent overwriting previous test runs.

Tuning Detection Parameters

Confidence Threshold Examples

Result:
Interpretation: More detections, including lower-confidence ones. May include false positives (non-person objects).

Area Threshold Examples

Captures small bounding boxes (distant persons, children, partial views).

Troubleshooting Detection Issues

Possible causes:
  1. Thresholds too high – Try lowering them:
  2. Model files missing – Check for HOG fallback warning:
    HOG is less accurate than YOLO. Download proper model files.
  3. Image issues – Verify image loaded correctly:
  4. Poor image quality – Try with a clearer image or better lighting.
Solution: Increase thresholds:
Also check the annotated image – false positives may be objects that resemble humans (mannequins, posters, etc.).
Possible causes:
  1. Confidence too low – Person detected but below threshold
  2. Area too small – Person detected but filtered by area threshold
  3. Model limitations – YOLO/HOG struggle with certain poses or occlusions
Solution: Lower both thresholds:
This shouldn’t happen with test images. If you see incorrect boxes:
  1. Check image format – Use standard JPEG/PNG
  2. Verify model files – Re-download YOLO weights
  3. Check OpenCV version – Ensure opencv-contrib-python is installed
Output:
Solution: Provide the full or correct relative path:
Output:
Possible causes:
  • Corrupted image file
  • Unsupported format
  • File permissions
Solution:

Comparing Detection Methods

YOLOv4 vs YOLOv3 vs HOG

Using Test Results for Production

Finding Optimal Settings

1

Test with multiple images

Capture diverse scenarios from your deployment:
2

Tune for your use case

High-security (minimize false negatives):
High-precision (minimize false positives):
3

Document your findings

Record optimal settings for your environment:
4

Apply to live streams

Use tested settings with RTSP streams:

Advanced Testing

Batch Testing Multiple Images

Run:

Comparing Threshold Ranges

Review all result_conf_*.jpg files to compare detection results.

Testing GPU Acceleration

Verify CUDA is being used:
Expected output:
If you see:
Install CUDA-enabled OpenCV:

Image Mode

Apply tested settings to capture snapshots from live streams

Video Mode

Record MP4 clips with your tuned detection parameters