Enhanced Detection System Configuration Guide




Overview

This guide covers the configuration options for the enhanced detection system, including background adaptation, YOLO11 compliance improvements, RTSP processing enhancements, and QR code integration.



Environment Variables



Background Adaptation Settings



FASTRTC_BACKGROUND_ADAPTATION

  • Default: true
  • Values: true, false
  • Description: Enable or disable adaptive background modeling for false positive reduction
  • Example: FASTRTC_BACKGROUND_ADAPTATION=true



FASTRTC_BACKGROUND_LEARNING_RATE

  • Default: 0.001
  • Range: 0.00010.1
  • Description: Learning rate for background model adaptation. Lower values = slower adaptation
  • Example: FASTRTC_BACKGROUND_LEARNING_RATE=0.005



FASTRTC_STABILITY_THRESHOLD

  • Default: 0.85
  • Range: 0.10.99
  • Description: Minimum stability score for valid detections. Higher = more strict filtering
  • Example: FASTRTC_STABILITY_THRESHOLD=0.8



FASTRTC_MOTION_THRESHOLD

  • Default: 10.0
  • Range: 1.0100.0
  • Description: Motion magnitude threshold for dynamic regions
  • Example: FASTRTC_MOTION_THRESHOLD=15.0



FASTRTC_MIN_PERSISTENCE

  • Default: 3
  • Range: 110
  • Description: Minimum frames a detection must persist to be considered valid
  • Example: FASTRTC_MIN_PERSISTENCE=2



FASTRTC_BACKGROUND_DEBUG

  • Default: false
  • Values: true, false
  • Description: Enable debug logging for background adaptation
  • Example: FASTRTC_BACKGROUND_DEBUG=true



RTSP Processing Settings



FASTRTC_RTSP_TRANSPORT

  • Default: udp
  • Values: udp, tcp
  • Description: Transport protocol for RTSP connections
  • Example: FASTRTC_RTSP_TRANSPORT=tcp



FASTRTC_RTSP_TIMEOUT

  • Default: 20
  • Range: 560
  • Description: Connection timeout in seconds for RTSP streams
  • Example: FASTRTC_RTSP_TIMEOUT=30



FASTRTC_RTSP_RECONNECT_DELAY

  • Default: 10
  • Range: 5300
  • Description: Delay between reconnection attempts in seconds
  • Example: FASTRTC_RTSP_RECONNECT_DELAY=15



QR Code Processing Settings



FASTRTC_QR_PROCESSING

  • Default: true
  • Values: true, false
  • Description: Enable QR code detection and report service integration
  • Example: FASTRTC_QR_PROCESSING=true



REPORT_SERVICE_URL

  • Default: http://localhost:5270
  • Description: Base URL for the report service
  • Example: REPORT_SERVICE_URL=http://report-service:5270



REPORT_SERVICE_TIMEOUT

  • Default: 30
  • Range: 5120
  • Description: Timeout for report service requests in seconds
  • Example: REPORT_SERVICE_TIMEOUT=45



REPORT_SERVICE_MAX_RETRIES

  • Default: 2
  • Range: 05
  • Description: Maximum retry attempts for report service requests
  • Example: REPORT_SERVICE_MAX_RETRIES=3



REPORT_SERVICE_RETRY_DELAY

  • Default: 1
  • Range: 110
  • Description: Delay between retry attempts in seconds
  • Example: REPORT_SERVICE_RETRY_DELAY=2



YOLO11 and Detection Settings



FASTRTC_TEMPORAL_SMOOTHING

  • Default: true
  • Values: true, false
  • Description: Enable temporal smoothing for stable annotations
  • Example: FASTRTC_TEMPORAL_SMOOTHING=true



FASTRTC_SMOOTHING_FACTOR

  • Default: 0.7
  • Range: 0.10.9
  • Description: Temporal smoothing factor. Higher = more smoothing
  • Example: FASTRTC_SMOOTHING_FACTOR=0.6



FASTRTC_MIN_CONFIDENCE

  • Default: 0.3
  • Range: 0.10.9
  • Description: Minimum confidence threshold for temporal smoothing
  • Example: FASTRTC_MIN_CONFIDENCE=0.4



FASTRTC_CLASS_CONFIG_PATH

  • Default: config/data.yml
  • Description: Path to class configuration file for TensorRT models
  • Example: FASTRTC_CLASS_CONFIG_PATH=/custom/path/classes.yml



Performance and Memory Settings



FASTRTC_MEMORY_LIMIT_MB

  • Default: 512
  • Range: 2564096
  • Description: Memory limit for detection processing in MB
  • Example: FASTRTC_MEMORY_LIMIT_MB=1024



FASTRTC_MAX_VIDEO_SIZE_MB

  • Default: 0 (unlimited)
  • Range: 010000
  • Description: Maximum video file size for processing in MB (0 = unlimited)
  • Example: FASTRTC_MAX_VIDEO_SIZE_MB=500



OCR Settings (Existing)



FASTRTC_OCR_ENABLED

  • Default: true
  • Values: true, false
  • Description: Enable OCR text extraction
  • Example: FASTRTC_OCR_ENABLED=true



FASTRTC_OCR_GPU

  • Default: true
  • Values: true, false
  • Description: Use GPU acceleration for OCR
  • Example: FASTRTC_OCR_GPU=false



FASTRTC_LANG

  • Default: en
  • Values: en, ar, ar+en
  • Description: OCR language(s) to use
  • Example: FASTRTC_LANG=ar+en



Configuration Files



Class Configuration (config/data.yml)

Example class configuration for TensorRT models:

# Class names mapping for TensorRT engine models
names:
  0: 'person'
  1: 'bicycle'
  # ... other classes
  44: 'food_label'
  55: 'invoice' 
  80: 'qr_code'

# Additional metadata
model_info:
  input_size: [3840, 2160]  # 4K resolution
  classes: 81
  format: 'tensorrt'
Enter fullscreen mode

Exit fullscreen mode



Camera Configuration (config/ip_camera.yml)

Enhanced camera configuration with RTSP settings:

cameras:
  - name: "4K RTSP Camera"
    rtsp_url: "rtsp://192.168.1.100:554/stream"
    username: "admin"
    password: "password"
    description: "Main 4K camera"
    enabled: true
    settings:
      timeout: 30
      transport: "udp"
      reconnect_delay: 15

camera_settings:
  connection_timeout: 20
  target_fps: 20
  buffer_size: 16777216  # 16MB for 4K streams

fallback:
  use_webcam_fallback: true
  default_webcam_id: 0
Enter fullscreen mode

Exit fullscreen mode



API Configuration



Background Adapter Configuration

from src.core.background_adapter import BackgroundAdapter

# Create with custom parameters
adapter = BackgroundAdapter(
    learning_rate=0.005,          # Faster adaptation
    stability_threshold=0.8,      # Less strict filtering
    motion_threshold=15.0,        # Higher motion sensitivity
    min_detection_persistence=2   # Shorter persistence requirement
)

# Update parameters at runtime
adapter.update_parameters(
    learning_rate=0.001,
    stability_threshold=0.85
)

# Get statistics
stats = adapter.get_background_stats()
Enter fullscreen mode

Exit fullscreen mode



YOLO Detector Configuration

from src.core.detector import YOLOSegmentationDetector

# Create with enhanced settings
detector = YOLOSegmentationDetector(
    model_path="models/best08032025.engine",
    task="segment",
    enable_ocr=True,
    confidence_threshold=0.5,
    enable_tracking=True,
    tracker_type="botsort",
    class_config_path="config/data.yml"
)

# Update confidence threshold
detector.update_confidence_threshold(0.6)

# Get comprehensive stats
stats = detector.get_segmentation_stats()
Enter fullscreen mode

Exit fullscreen mode



Troubleshooting



Background Adaptation Issues



Problem: Too many false positives filtered

Solution: Lower the stability threshold or reduce motion threshold

export FASTRTC_STABILITY_THRESHOLD=0.7
export FASTRTC_MOTION_THRESHOLD=8.0
Enter fullscreen mode

Exit fullscreen mode



Problem: Background adapter consuming too much memory

Solution: Increase learning rate for faster adaptation

export FASTRTC_BACKGROUND_LEARNING_RATE=0.01
Enter fullscreen mode

Exit fullscreen mode



Problem: Background model not adapting to lighting changes

Solution: Increase learning rate and reduce stability requirement

export FASTRTC_BACKGROUND_LEARNING_RATE=0.005
export FASTRTC_STABILITY_THRESHOLD=0.75
Enter fullscreen mode

Exit fullscreen mode



RTSP Connection Issues



Problem: Frequent disconnections

Solution: Switch to TCP transport and increase timeout

export FASTRTC_RTSP_TRANSPORT=tcp
export FASTRTC_RTSP_TIMEOUT=45
Enter fullscreen mode

Exit fullscreen mode



Problem: High latency/buffering

Solution: Use UDP transport with optimized buffer size

export FASTRTC_RTSP_TRANSPORT=udp
# Configure buffer size in camera config file
Enter fullscreen mode

Exit fullscreen mode



Problem: Connection fails immediately

Solution: Validate network connectivity and credentials

# Test connection manually
ffmpeg -rtsp_transport udp -i "rtsp://username:password@ip:554/stream" -t 5 -f null -
Enter fullscreen mode

Exit fullscreen mode



QR Code Processing Issues



Problem: QR codes not being processed

Solution: Verify report service connectivity

export FASTRTC_QR_PROCESSING=true
export REPORT_SERVICE_URL=http://correct-service:5270
# Test service manually
curl -X GET $REPORT_SERVICE_URL/health
Enter fullscreen mode

Exit fullscreen mode



Problem: Duplicate QR code processing

Solution: The system automatically prevents duplicates, but you can verify:

# Check processed delivery IDs
print(detector.processed_delivery_ids)
# Clear if needed (testing only)
detector.processed_delivery_ids.clear()
Enter fullscreen mode

Exit fullscreen mode



Performance Issues



Problem: High memory usage during video processing

Solution: Enable memory optimizations and set limits

export FASTRTC_MEMORY_LIMIT_MB=1024
export FASTRTC_MAX_VIDEO_SIZE_MB=500
# Install psutil for memory monitoring
pip install psutil
Enter fullscreen mode

Exit fullscreen mode



Problem: Slow processing on high-resolution streams

Solution: Optimize performance settings

export FASTRTC_TEMPORAL_SMOOTHING=false  # Disable if not needed
export FASTRTC_BACKGROUND_LEARNING_RATE=0.01  # Faster adaptation
Enter fullscreen mode

Exit fullscreen mode



Monitoring and Logging



Enable Debug Logging

export FASTRTC_BACKGROUND_DEBUG=true
# Check logs for background adaptation details
Enter fullscreen mode

Exit fullscreen mode



Performance Monitoring

# Get comprehensive performance stats
stats = detector.get_segmentation_stats()
print(f"FPS: {stats['fps']}")
print(f"Processing time: {stats['processing_time']}ms")

# Background adapter stats
bg_stats = detector.background_adapter.get_background_stats()
print(f"Background learned: {bg_stats['background_learned']}")
print(f"Filtered detections: {bg_stats['frames_processed']}")
Enter fullscreen mode

Exit fullscreen mode



Memory Monitoring

# Monitor memory usage (requires psutil)
import psutil
process = psutil.Process()
memory_mb = process.memory_info().rss / 1024 / 1024
print(f"Current memory usage: {memory_mb:.1f}MB")
Enter fullscreen mode

Exit fullscreen mode



Best Practices



Production Deployment

  1. Background Adaptation: Start with conservative settings and tune based on scene
  2. RTSP Streams: Use TCP for reliability, UDP for performance
  3. Memory Management: Set appropriate limits based on available hardware
  4. QR Processing: Ensure report service is highly available
  5. Monitoring: Enable performance logging and set up alerts



Development and Testing

  1. Debug Mode: Enable debug logging for troubleshooting
  2. Test Environment: Use smaller thresholds for faster iteration
  3. Performance Testing: Use the provided test suites to validate performance
  4. Memory Profiling: Monitor memory usage during long-running tests



Example Production Configuration

# Background adaptation - production settings
export FASTRTC_BACKGROUND_ADAPTATION=true
export FASTRTC_BACKGROUND_LEARNING_RATE=0.001
export FASTRTC_STABILITY_THRESHOLD=0.85
export FASTRTC_MOTION_THRESHOLD=10.0
export FASTRTC_MIN_PERSISTENCE=3

# RTSP - reliable settings
export FASTRTC_RTSP_TRANSPORT=tcp
export FASTRTC_RTSP_TIMEOUT=30

# QR Processing - production service
export FASTRTC_QR_PROCESSING=true
export REPORT_SERVICE_URL=http://report-service:5270
export REPORT_SERVICE_TIMEOUT=30
export REPORT_SERVICE_MAX_RETRIES=2

# Performance - production limits  
export FASTRTC_MEMORY_LIMIT_MB=2048
export FASTRTC_MAX_VIDEO_SIZE_MB=1000

# Disable debug logging
export FASTRTC_BACKGROUND_DEBUG=false
Enter fullscreen mode

Exit fullscreen mode

This configuration provides a robust, production-ready setup with appropriate fail-safes and performance optimizations.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *