-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
I try to convert model to onnx to deploy by opencv, on pt weight it can detect, but when convert to onnx the detection result shift
this is detect result when i try to detect home button and select folder button of tree size free software
[url=https://anh.moe/view/f8KTwx]https://anh.moe/view/f8KTwx [/url]
`from ultralytics import YOLOv10
import cv2
import glob
import os
model_path = "runs_1/detect/train/weights/best.onnx"
video_path = "Image"
save_video_path = "output/output.avi"
model = YOLOv10(model_path)
label = ["Home", "Select"]
video = True
image = False
path = glob.glob(video_path)
for p in path:
for filename in os.listdir(p):
full_path = os.path.join(p, filename)
print(full_path)
if filename.contains("jpg"):
model.predict(full_path, save= True,conf= 0.5)
frame_Full = cv2.imread(full_path)
frame = cv2.resize(frame_Full, (640, 640))
frame_cp = frame.copy()
# frame_cp = frame_cp[224:868, 520:1140]
w = 640
h=640
results = model(source=frame_cp, conf=0.1)
for r in results:
if r.boxes is None:
print('None')
continue
for result in r.boxes.data:
result = result.cpu().detach().numpy()
boxes = result[:4]
print(boxes)
x, y, bw, bh = boxes
left = int((x+13)1920/640)
top = int(y1080/640)
right = int((x+bw/2)*1920/640)
bottom = int((y+bh/2)1080/640)
print('left, top, right, bottom')
print(filename)
print(left, top, right, bottom)
#left, top, right, bottom = boxes
classes = int(result[5])
scores = result[4]
cv2.rectangle(frame_Full, (int(left), int(top)), (int(right), int(bottom)), color=[255, 255, 0], thickness=2)
cv2.putText(frame_Full, f"{label[classes]}" + "_{:.2f}%".format(scores100), (int(left), int(top)), cv2.FONT_HERSHEY_SIMPLEX, 1, color=[255, 255, 0], thickness=2)
# cv2.imwrite((p[:-4]+'_org.jpg'), frame)
cv2.imwrite("Test/"+filename, frame_Full)
`