код запускается и выдает это в качестве вывода: 0: 192x224 1 aloo methi, 91,7 мс
Код: Выделить всё
from ultralytics import YOLO
import cv2
import numpy as np
# Load YOLO model
model_path = 'D:/Food_Images.v1i.yolov8/runs/detect/train/weights/last.pt'
model = YOLO(model_path)
# ArUco definitions
aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_6X6_250)
parameters = cv2.aruco.DetectorParameters()
detector = cv2.aruco.ArucoDetector(aruco_dict, parameters)
# Predict bounding boxes using YOLO
results = model.predict(source='0', show=True)
for result in results:
boxes = result.boxes
for box in boxes:
x1, y1, x2, y2 = box.xyxy
width = x2 - x1
height = y2 - y1
print(f'Bounding box size: width={width}, height={height}')
# Detect ArUco markers
corners, ids, rejectedImgPoints = detector.detectMarkers()
print(f'ArUco marker corners: {corners}')
print(f'ArUco marker IDs: {ids}')
if ids is not None and len(ids) > 0:
marker_size = 10 # Size of the marker in centimeters (adjust based on actual marker size)
pixel_size = corners[0][0][1][0] - corners[0][0][0][0] # Assuming the marker is a square
cm_per_pixel = marker_size / pixel_size
print(f'cm_per_pixel: {cm_per_pixel}')
object_size = width * height * cm_per_pixel
print(f'Object size: {object_size} cm^2')
# Print YOLO results
print(results)
Подробнее здесь: https://stackoverflow.com/questions/783 ... co-markers