import cv2
import numpy as np
import torch
import pandas
import os
# Load the trained model
model = torch.hub.load('ultralytics/yolov5', 'custom', path='C:/Users/ASUS/Desktop/yolov5-fastapi-main/model/best.pt',force_reload=True)
def detect_logo(image):
result = model(image)
labels, cord_thres = result.xyxyn[0][:, -1].numpy(), result.xyxyn[0][:, :-1].numpy()
cropped_images = []
for i,box in enumerate(cord_thres):
x_min = int(box[0])
y_min = int(box[1])
x_max = int(box[2])
y_max = int(box[3])
image2 = image.astype(np.uint8)
cropped_image = image2[y_min:y_max,x_min:x_max]
cropped_images.append(cropped_image)
cv2.imwrite("image.jpg", cropped_images)
return cropped_images
# Read the image and convert it to a NumPy array
image = cv2.imread("C:/Users/ASUS/Desktop/yolov5-fastapi-main/aetna_003.png")
# Detect and crop the coordinates of the detected logos
cropped_images = detect_logo(image)
I want to crop the image that I detected in yolov5 by extracting its coordinates, it's working, but it's not saving the image, where is the error, can you help?