#!/usr/bin/env python3 """ Example demonstrating the new default postprocess options in the app. This script shows how to use the different postprocessing types: - Fire detection (classification) - YOLO v3/v5 (object detection with bounding boxes) - General classification - Raw output The postprocessing options are built-in to the app and provide text output and bounding box visualization in live view windows. """ import sys import os # Add the project root to Python path sys.path.insert(0, os.path.dirname(__file__)) from core.functions.Multidongle import ( MultiDongle, PostProcessorOptions, PostProcessType, WebcamInferenceRunner ) def demo_fire_detection(): """Demo fire detection postprocessing (default)""" print("=== Fire Detection Demo ===") # Configure for fire detection options = PostProcessorOptions( postprocess_type=PostProcessType.FIRE_DETECTION, threshold=0.5, class_names=["No Fire", "Fire"] ) print(f"Postprocess type: {options.postprocess_type.value}") print(f"Threshold: {options.threshold}") print(f"Class names: {options.class_names}") return options def demo_yolo_object_detection(): """Demo YOLO object detection with bounding boxes""" print("=== YOLO Object Detection Demo ===") # Configure for YOLO v5 object detection options = PostProcessorOptions( postprocess_type=PostProcessType.YOLO_V5, threshold=0.3, class_names=["person", "bicycle", "car", "motorbike", "aeroplane", "bus", "train", "truck"], nms_threshold=0.5, max_detections_per_class=50 ) print(f"Postprocess type: {options.postprocess_type.value}") print(f"Detection threshold: {options.threshold}") print(f"NMS threshold: {options.nms_threshold}") print(f"Class names: {options.class_names[:5]}...") # Show first 5 return options def demo_general_classification(): """Demo general classification""" print("=== General Classification Demo ===") # Configure for general classification options = PostProcessorOptions( postprocess_type=PostProcessType.CLASSIFICATION, threshold=0.6, class_names=["cat", "dog", "bird", "fish", "horse"] ) print(f"Postprocess type: {options.postprocess_type.value}") print(f"Threshold: {options.threshold}") print(f"Class names: {options.class_names}") return options def main(): """Main demo function""" print("Default Postprocess Options Demo") print("=" * 40) # Demo different postprocessing options fire_options = demo_fire_detection() print() yolo_options = demo_yolo_object_detection() print() classification_options = demo_general_classification() print() # Example of how to initialize MultiDongle with options print("=== MultiDongle Integration Example ===") # NOTE: Update these paths according to your setup PORT_IDS = [28, 32] # Update with your device port IDs SCPU_FW = 'fw_scpu.bin' # Update with your firmware path NCPU_FW = 'fw_ncpu.bin' # Update with your firmware path MODEL_PATH = 'your_model.nef' # Update with your model path try: # Example 1: Fire detection (default) print("Initializing with fire detection...") multidongle_fire = MultiDongle( port_id=PORT_IDS, scpu_fw_path=SCPU_FW, ncpu_fw_path=NCPU_FW, model_path=MODEL_PATH, upload_fw=False, # Set to True if you need firmware upload postprocess_options=fire_options ) print(f"✓ Fire detection configured: {multidongle_fire.postprocess_options.postprocess_type.value}") # Example 2: Change postprocessing options dynamically print("Changing to YOLO detection...") multidongle_fire.set_postprocess_options(yolo_options) print(f"✓ YOLO detection configured: {multidongle_fire.postprocess_options.postprocess_type.value}") # Example 3: Get available types available_types = multidongle_fire.get_available_postprocess_types() print(f"Available postprocess types: {[t.value for t in available_types]}") except Exception as e: print(f"Note: MultiDongle initialization skipped (no hardware): {e}") print("\n=== Usage Notes ===") print("1. Fire detection option is set as default") print("2. Text output shows classification results with probabilities") print("3. Bounding box output visualizes detected objects in live view") print("4. All postprocessing is built-in to the app (no external dependencies)") print("5. Exact nodes can configure postprocessing through UI properties") if __name__ == "__main__": main()