Hailo Raspberry Pi AI Kit and Python code examples

Hello

Thanks you for this long awaited news, m’y question,IS it possible to use a webcam on https://github.com/hailo-ai/Hailo-Application-Code-Examples/blob/main/runtime/python/detection_with_tracker/detection_with_tracker.pyinstead of videos

Hey @mAty1901,

I suggest you take a look at our streaming example here:

Below is a general example (untested, but should give you a basic idea) of how you could set up webcam input for object detection and tracking. You can easily modify what to do with the video frames afterward.

import cv2
import numpy as np
from your_object_detection_module import YourObjectDetector  # Replace with actual detector import
from your_tracker_module import YourTracker  # Replace with actual tracker import

def main():
    # Initialize webcam input (0 for default camera)
    cap = cv2.VideoCapture(0)

    if not cap.isOpened():
        print("Error: Could not open webcam.")
        return

    # Initialize the detector and tracker
    detector = YourObjectDetector()
    tracker = YourTracker()

    while True:
        # Capture the frame
        ret, frame = cap.read()
        if not ret:
            print("Error: Could not read frame from webcam.")
            break

        # Perform object detection
        detections = detector.detect(frame)

        # Update tracker with detections
        tracked_objects = tracker.update(detections)

        # Draw bounding boxes and IDs on tracked objects
        for obj in tracked_objects:
            cv2.rectangle(frame, (obj.x, obj.y), (obj.x + obj.width, obj.y + obj.height), (0, 255, 0), 2)
            cv2.putText(frame, f'ID: {obj.id}', (obj.x, obj.y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2)

        # Display the tracking result
        cv2.imshow('Webcam Tracking', frame)

        # Exit on 'q' key press
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    # Cleanup
    cap.release()
    cv2.destroyAllWindows()

if __name__ == '__main__':
    main()

Feel free to modify how the video frames are processed after detection. Hope this helps!

1 Like

Thanks you for your respone,
Can you explain to me wich detector and tracker module to use please

Model Selection for Object Detection and Tracking

The examples provided use the Yolox_s_leaky model, but you have the flexibility to choose from a variety of models based on your specific needs and the results you’re aiming for. Hailo offers a range of both proprietary and public models that you can explore:

  1. Hailo-specific Models:
    For models developed or optimized by Hailo, visit:
    hailo_model_zoo/docs/HAILO_MODELS.rst at master · hailo-ai/hailo_model_zoo · GitHub

  2. Public Models:
    For a selection of publicly available models supported by Hailo, check:
    hailo_model_zoo/docs/PUBLIC_MODELS.rst at master · hailo-ai/hailo_model_zoo · GitHub

When selecting a model, consider factors such as:

  • Detection accuracy
  • Processing speed
  • Hardware compatibility
  • Specific object classes you need to detect

Review the performance metrics and specifications of different models to find the one that best suits your application. Remember that you may need to adjust your pipeline configuration based on the model you choose.

Regards

Hello,
Thanks you for your respone, in this part of code

[quote=“omria, post:2, topic:3467”]

from your_object_detection_module import YourObjectDetector  # Replace with actual detector import
from your_tracker_module import YourTracker  # Replace with actual tracker import

[/quote] you can give me an example? I could not create a class to manage the detection and the tracker

Hey @mAty1901

For your use case, I recommend checking out the detection_with_tracker example. This example integrates object detection and tracking using Hailo’s API. It includes classes that handle detection with the Hailo runner and feed the results into a tracker, making it a great fit for combining object detection with tracking on your Raspberry Pi AI Kit. You can use this as a guide to set up your detection and tracking logic.