使用OpenCV结合YOLOv5识别效果远差于原生YOLOv5的问题求助
问题:OpenCV调用YOLOv5识别乐高效果远差于detect.py脚本
我尝试用OpenCV通过摄像头识别乐高积木,但识别效果远不如直接运行YOLOv5的detect.py脚本。针对图片识别做了几组实验后,发现OpenCV方案效果依然很差,想请教可能的原因及解决思路。
实验过程
1. 直接运行detect.py的结果
执行命令:
python detect.py --weights runs/train/yolo/weights/best.pt --source legos.jpg
结果图:
2. 使用OpenCV实现的代码及结果
代码实现:
import torch import cv2 import numpy as np model = torch.hub.load('.', 'custom', path='runs/train/yolo/weights/last.pt', source='local') cap = cv2.VideoCapture('legos.jpg') while cap.isOpened(): ret, frame = cap.read() # 执行检测 results = model(frame) cv2.imshow('YOLO', np.squeeze(results.render())) if cv2.waitKey(0) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
结果图:
3. 直接调用模型识别图片的结果
代码实现:
import torch results = model('legos.jpg') results.show()
结果图:
请问有什么解决思路吗?
内容的提问来源于stack exchange,提问作者Haotian Ma
相关产品推荐
相关产品推荐

