I am doing object detection using yolov8 and sahi algorithms. I am writing a function to test whether some of the objects I detect are round or not, but I can’t send the bounding boxes of the objects I detect to the function.
def is_circle(image, bbox):
img = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
x, y, w, h = bbox
roi = img[y:y + h, x:x + w]
edges = cv.Canny(roi, 50, 150, apertureSize=3)
circles = cv.HoughCircles(edges, cv.HOUGH_GRADIENT, 1, 20, param1=50, param2=30, minRadius=0, maxRadius=0)
return circles is not None
detection_model = AutoDetectionModel.from_pretrained(
model_type='yolov8',
model_path="C:/Users/UGURHANDASDEMIR/PycharmProjects/pythonProject1/best.pt",
confidence_threshold=0.5,
device="cuda:0", # or 'cuda:0'
)
image_dir = "img"
image_paths = [os.path.join(image_dir, image_name) for image_name in os.listdir(image_dir) if image_name.endswith(('.png', '.jpg', '.jpeg'))]
for image_path in image_paths:
image = read_image(image_path)
result = get_sliced_prediction(
image,
detection_model,
slice_height = 1920,
slice_width =1080 ,
overlap_height_ratio = 0.5,
overlap_width_ratio = 0.5
)
for prediction in result.object_prediction_list:
print(prediction.category.name)
if prediction.category.name == 'uap' or prediction.category.name == 'uai' :
bbox = prediction.bbox
is_circle(image,bbox)
else:
inis_durumu=-1
I am getting the following error from this code:
Traceback (most recent call last):
File "C:\Users\UGURHANDASDEMIR\PycharmProjects\pythonProject1\dene.py", line 52, in <module>
is_circle(image,bbox)
File "C:\Users\UGURHANDASDEMIR\PycharmProjects\pythonProject1\dene.py", line 14, in is_circle
x, y, w, h = bbox
^^^^^^^^^^
TypeError: cannot unpack non-iterable BoundingBox object
Please help