pat
Published © GPL3+

JetBot Mini Sees the World with YOLOv8 (Part 1)

Part 1 focuses on running YOLOv8 inference in Jupyter Notebook (cloud), enabling JetBot Mini to detect objects and gain vision.

IntermediateFull instructions provided6 hours8
JetBot Mini Sees the World with YOLOv8 (Part 1)

Things used in this project

Hardware components

NVIDIA Jetson Nano Developer Kit
NVIDIA Jetson Nano Developer Kit
×1
Camera Module
Raspberry Pi Camera Module
×1

Software apps and online services

NVIDIA JetPack
Jupyter Notebook
Jupyter Notebook
Ultralytics YOLOv8

Hand tools and fabrication machines

Multitool, Screwdriver
Multitool, Screwdriver

Story

Read more

Code

YOLOV8 Inference

Python
import cv2
import numpy as np
from ultralytics import YOLO
from IPython.display import display, clear_output
from IPython.display import Image as IPImage

# Load YOLOv8 model
model = YOLO('models/yolov8n.pt')

# Initialize the webcam
cap = cv2.VideoCapture(1)  

if not cap.isOpened():
    print("Error: Unable to access the webcam.")
    cap.release()
    exit()

try:
    while True:
        # Read a frame from the webcam
        ret, frame = cap.read()
        if not ret:
            print("Error: Failed to capture frame.")
            break

        # Convert the frame to RGB for processing
        frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

        # Run YOLOv8 inference
        results = model(frame_rgb)  # Use the RGB frame for inference

        # Annotate the frame with YOLOv8 results
        annotated_frame = results[0].plot()

        # Convert the annotated frame back to BGR for correct display
        annotated_frame_bgr = cv2.cvtColor(annotated_frame, cv2.COLOR_RGB2BGR)

        # Resize the annotated frame for display in Jupyter Notebook
        annotated_resized = cv2.resize(annotated_frame_bgr, (330, 330)) # (480, 430))

        # Encode the annotated frame as JPEG
        _, encoded_frame = cv2.imencode('.jpg', annotated_resized)
        encoded_frame = encoded_frame.tobytes()

        # Display the annotated frame in the notebook
        clear_output(wait=True)
        display(IPImage(data=encoded_frame))

except KeyboardInterrupt:
    # Stop the feed when interrupted
    print("Live feed stopped.")

finally:
    # Release the webcam and close resources
    cap.release()

Credits

pat
14 projects • 5 followers
AI Convergence Engineering, Software Engineering, ML, deep learning, image processing, computer vision, circuit design, and Edge AI devices.

Comments