在博客上下载了一套源码学习,这个用yolov5的官方权重训练Coco数据集得到的新权重可以用,但是换成自己的数据集,在detect里面可以用,但是放到那个qt界面里就不行了
1条回答 默认 最新
- 「已注销」 2023-04-11 22:31关注
以下内容部分参考ChatGPT模型:
你可以尝试使用OpenCV来可视化yolov5的检测结果。具体步骤如下:
- 在yolov5中添加以下代码,将检测结果保存为一个列表:
results = model(img) predictions = non_max_suppression(results, conf_thres=0.4, iou_thres=0.5) detections = [] for pred in predictions: if pred is not None and len(pred) > 0: detections.extend(pred.cpu().numpy())
- 在OpenCV中读取图像,并将检测结果绘制在图像上:
import cv2 img = cv2.imread('<path_to_image>') for detection in detections: x1, y1, x2, y2, conf, cls = detection cv2.rectangle(img, (int(x1), int(y1)), (int(x2), int(y2)), (0, 0, 255), 2) cv2.putText(img, str(cls.numpy()), (int(x1), int(y1)-10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 0, 255), 2) cv2.imshow('Detection', img) cv2.waitKey(0) cv2.destroyAllWindows()
- 运行代码,即可看到绘制了检测结果的图像。
希望这个思路对你有帮助。
如果我的建议对您有帮助、请点击采纳、祝您生活愉快
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报