Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3136

General discussion • using RPI4 model b with YOLO model

$
0
0
I used this code for detection using the yolo model using laptop:

This code can save the image with a border on the detected object

Code:

from ultralytics import YOLO    # Load a pretrained YOLOv11n modelmodel = YOLO("yolo11n.pt")source = "/content/drive/MyDrive/image/02355_resized.jpg"    # Run inference on the sourceresults = model(source) 

And this code to show the image:

Code:

# Access and print detection details for the first image in the batchfor r in results:      boxes = r.boxes  # Bounding boxes      masks = r.masks  # Masks (if segmentation model)      probs = r.probs  # Class probabilities (if classification model)# Plot the results on the imageannotated_image = results[0].plot() # Gets the annotated image as a NumPy array# Display the imageimport cv2from google.colab.patches import cv2_imshowcv2_imshow(annotated_image)# Save the annotated imageimport ossave_path = "/content/drive/MyDrive/image"os.makedirs(save_path, exist_ok=True)  # Create folder if it doesn't exist# Save the imagesave_filename = os.path.join(save_path, "annotated1_MOD.jpg")cv2.imwrite(save_filename, annotated_image)print(f"Image saved to: {save_filename}")
CAN I use like this code on the RPI4? I am asking because I have not RPI4

Statistics: Posted by georgegeorge964 — Sun Jan 25, 2026 7:13 pm



Viewing all articles
Browse latest Browse all 3136

Trending Articles