oad the image
frame = cv2.imread(image_path)
Check if the image was successfully loaded
if frame is None:
print(f"Error: Could not load image from {image_path}")
exit(1)
Resize the frame to fit the screen resolution if it’s too large
screen_width = 1280
screen_height = 720
(h, w) = frame.shape[:2]
if w > screen_width or h > screen_height:
scale = min(screen_width / w, screen_height / h)
new_width = int(w * scale)
new_height = int(h * scale)
frame = cv2.resize(frame, (new_width, new_height))
Run YOLO model inference on the frame
results = model(frame)
Annotate the frame with the detection results
annotated_frame = results[0].plot() # Plot detections on the frame
Optionally, display the frame (press ‘q’ to exit)
cv2.imshow(‘YOLOv8 Inference’, annotated_frame)
Wait for the user to press ‘q’ to exit the display
while True:
if cv2.waitKey(1) & 0xFF == ord(‘q’):
break
Release resources
cv2.destroyAllWindows()
this is the detected bounding boxes. Now i want to save the crop from this bouding boxes. Give me solutions