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
Step-by-Step Guide
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
Run detection with default settings
Test with default configuration:This uses default thresholds from
config.cfg:confidence_threshold = 0.5person_area_threshold = 1000
Review the annotated output
Open the generated Format:
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
(x, y, width, height, confidence)Understanding the Output
Console Output Breakdown
(x, y, width, height, confidence)
| Field | Description | Example |
|---|---|---|
x | Left edge position (pixels) | 145 |
y | Top edge position (pixels) | 89 |
width | Box width (pixels) | 234 |
height | Box height (pixels) | 456 |
confidence | Detection confidence (0.0-1.0) | 0.87 (87%) |
width × height = 234 × 456 = 106,704 pixels
Annotated Image
The output imagetest_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
- Low (0.3) - High Recall
- Default (0.5) - Balanced
- High (0.7) - High Precision
Area Threshold Examples
- Small (500) - Detect Distant Persons
- Medium (2500) - Nearby Persons
- Large (10000) - Close-Up Only
Troubleshooting Detection Issues
No persons detected (0 detections)
No persons detected (0 detections)
Possible causes:
-
Thresholds too high – Try lowering them:
-
Model files missing – Check for HOG fallback warning:
HOG is less accurate than YOLO. Download proper model files.
-
Image issues – Verify image loaded correctly:
- Poor image quality – Try with a clearer image or better lighting.
Too many false positives
Too many false positives
Solution: Increase thresholds:Also check the annotated image – false positives may be objects that resemble humans (mannequins, posters, etc.).
Missing obvious persons
Missing obvious persons
Possible causes:
- Confidence too low – Person detected but below threshold
- Area too small – Person detected but filtered by area threshold
- Model limitations – YOLO/HOG struggle with certain poses or occlusions
Bounding boxes in wrong locations
Bounding boxes in wrong locations
This shouldn’t happen with test images. If you see incorrect boxes:
- Check image format – Use standard JPEG/PNG
- Verify model files – Re-download YOLO weights
- Check OpenCV version – Ensure opencv-contrib-python is installed
Error: Image file not found
Error: Image file not found
Output:Solution: Provide the full or correct relative path:
Error: Could not load image
Error: Could not load image
Output:Possible causes:
- Corrupted image file
- Unsupported format
- File permissions
Comparing Detection Methods
YOLOv4 vs YOLOv3 vs HOG
- YOLOv4 (Recommended)
- YOLOv3 (Fallback)
- HOG (Fallback)
Accuracy: ★★★★★
Speed: ★★★★☆
GPU Support: YesExpected output:Best for production deployments.
Speed: ★★★★☆
GPU Support: Yes
Using Test Results for Production
Finding Optimal Settings
Tune for your use case
High-security (minimize false negatives):High-precision (minimize false positives):
Advanced Testing
Batch Testing Multiple Images
Comparing Threshold Ranges
result_conf_*.jpg files to compare detection results.