Skip to content

Sort segmentation model masks in top-down fashion (HTR) #16149

Answered by johnlockejrr
johnlockejrr asked this question in Q&A
Discussion options

You must be logged in to vote

Right answer, I shoud sort the bboxes by y1:

from ultralytics import YOLO
import cv2
import numpy as np
from pathlib import Path

image_path = "/home/incognito/yolov8/datasets/sam_v1/images/a34e234a-76be-5392-9b39-4abdcd051719.jpg"

# Load the YOLOv8 model
model = YOLO('/home/incognito/yolov8/runs/segment/train/weights/best.pt')

# Perform inference on an image
results = model(image_path)
img = cv2.imread(image_path)
img_name = Path(image_path).stem

# Extract bounding boxes, classes, names, and confidences
boxes = results[0].boxes.xyxy.tolist()
classes = results[0].boxes.cls.tolist()
names = results[0].names
confidences = results[0].boxes.conf.tolist()

bboxes = []
# Iterate through the …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@glenn-jocher
Comment options

Answer selected by johnlockejrr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants