# yolov5-opencv **Repository Path**: CodeRex/yolov5-opencv ## Basic Information - **Project Name**: yolov5-opencv - **Description**: 基于yolov5目标检测技术,使用onnx模型检测图片并返回位置信息 - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-08-19 - **Last Updated**: 2024-09-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: YOLOv5, Python, OpenCV ## README # yolov5-opencv ## Prerequisites Make sure you have already on your system: Any modern Linux OS (tested on Ubuntu 20.04) OpenCV 4.5.4+ Python 3.7+ IMPORTANT!!! Note that OpenCV versions prior to 4.5.4 will not work at all. ## Which YOLO version should I use? This repository uses YOLO V5 but it is not the only YOLO version out there. You can read [this article](https://towardsdatascience.com/yolo-v4-or-yolo-v5-or-pp-yolo-dad8e40f7109) to learn more about YOLO versions and choose the more suitable one for you. ## Exporting yolo v5 models to .onnx format Check here: https://github.com/ultralytics/yolov5/issues/251 My commands were: ```bash git clone https://github.com/ultralytics/yolov5 cd yolov5 pip install -r requirements.txt ``` And then to convert the model: ```bash $ python3 export.py --weights yolov5n.pt --img 640 --include onnx export: data=data/coco128.yaml, weights=['yolov5n.pt'], imgsz=[640], batch_size=1, device=cpu, half=False, inplace=False, train=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=12, verbose=False, workspace=4, nms=False, agnostic_nms=False, topk_per_class=100, topk_all=100, iou_thres=0.45, conf_thres=0.25, include=['onnx'] YOLOv5 🚀 v6.0-192-g436ffc4 torch 1.10.1+cu102 CPU Fusing layers... Model Summary: 213 layers, 1867405 parameters, 0 gradients PyTorch: starting from yolov5n.pt (4.0 MB) ONNX: starting export with onnx 1.10.2... /home/user/workspace/smartcam/yolov5/models/yolo.py:57: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! if self.onnx_dynamic or self.grid[i].shape[2:4] != x[i].shape[2:4]: ONNX: export success, saved as yolov5n.onnx (7.9 MB) Export complete (1.33s) Results saved to /home/doleron/workspace/smartcam/yolov5 Visualize with https://netron.app Detect with `python detect.py --weights yolov5n.onnx` or `model = torch.hub.load('ultralytics/yolov5', 'custom', 'yolov5n.onnx') Validate with `python val.py --weights yolov5n.onnx` $ ``` ## References - https://github.com/ultralytics/yolov5/issues/708