Yolo11 Object Detection on Jetson Orin Nano with Live Video

Thanks @Toxite, your suggestion worked. Yolo11 object detection python code is working on Orin Nano Super devkit with JetPack 6.2.1. While code is only half a page long, it streams object detection results and draws bounding boxes in output window extremely fast. Inference time is ~9ms, and the output streaming is smooth and swift.

Code makes use of Ultralytics’ Yolo library for inference (installation for Orin Nano here), and jetson-utils for video input and output. That’s it. The hard part was figuring out the frame data type conversions between Yolo and jetson-utils. A big thanks to @Toxite.

from ultralytics import YOLO 

rom   jetson_utils import videoSource, videoOutput, Log
from   jetson_utils import cudaToNumpy
from   jetson_utils import cudaFromNumpy

# Load YOLO TRT model
model = YOLO("/home/jet/robotics/yolo/networks/yolo11n.engine")

# Jetson_Utils initialize
input  = videoSource()
output = videoOutput()
 
# Run Inference on Video Frames
while True:

    # capture the next image
    frame = input.Capture()

    if frame is None: # timeout
        continue  
        
    # Exit on input/output EOS
    if not input.IsStreaming() or not output.IsStreaming():
        break

    # Convert Jetson Cuda image to Numpy array  
    frame_numpy = cudaToNumpy(frame)

    # Run Yolo Inference
    results = model(frame_numpy)  #, show=True)
 
    for resx in results:
        boxes     = resx.boxes      # Boxes object for bounding box outputs
        masks     = resx.masks      # Masks object for segmentation masks outputs
        keypoints = resx.keypoints  # Keypoints object for pose outputs
        probs     = resx.probs      # Probs object for classification outputs
        obb       = resx.obb        # Oriented boxes object for OBB outputs

        # Display image and bounding box in Jetson_Utils output window
        output.Render(cudaFromNumpy(resx.plot()))

        print(boxes)   # Stream object detection results