opencv/doc/tutorials/dnn
Abduragim Shtanchaev a8d1373919
Merge pull request #25794 from Abdurrahheem:ash/yolov10-support
Add sample support of YOLOv9 and YOLOv10 in OpenCV #25794

This PR adds sample support of  [`YOLOv9`](https://github.com/WongKinYiu/yolov9) and [`YOLOv10`](https://github.com/THU-MIG/yolov10/tree/main)) in OpenCV. Models for this test are located in this [PR](https://github.com/opencv/opencv_extra/pull/1186). 

**Running YOLOv10 using OpenCV.** 
1. In oder to run `YOLOv10` one needs to cut off postporcessing with dynamic shapes from torch and then convert it to ONNX. If someone is looking for ready solution, there is [this forked branch](https://github.com/Abdurrahheem/yolov10/tree/ash/opencv-export) from official YOLOv10.  Particularty follow this proceduce. 

```bash
git clone git@github.com:Abdurrahheem/yolov10.git
conda create -n yolov10 python=3.9
conda activate yolov10
pip install -r requirements.txt
python export_opencv.py --model=<model-name> --imgsz=<input-img-size>
```
By default `model="yolov10s"` and `imgsz=(480,640)`. This will generate file `yolov10s.onnx`, which can be use for inference in OpenCV

2. For inference part on OpenCV.  one can use `yolo_detector.cpp` [sample](https://github.com/opencv/opencv/blob/4.x/samples/dnn/yolo_detector.cpp). If you have followed above exporting procedure, then you can use following command to run the model. 

``` bash
build opencv from source 
cd build 
./bin/example_dnn_yolo_detector --model=<path-to-yolov10s.onnx-file> --yolo=yolov10 --width=640 --height=480 --input=<path-to-image> --scale=0.003921568627 --padvalue=114
```
If you do not specify `--input` argument, OpenCV will grab first camera that is avaliable on your platform. 
For more deatils on how to run the `yolo_detector.cpp` file see this [guide](https://docs.opencv.org/4.x/da/d9d/tutorial_dnn_yolo.html#autotoc_md443) 


**Running YOLOv9 using OpenCV**

1. Export model following [official guide](https://github.com/WongKinYiu/yolov9)of the YOLOv9 repository. Particularly you can do following for converting.

```bash
git clone https://github.com/WongKinYiu/yolov9.git
cd yolov9
conda create -n yolov9 python=3.9
conda activate yolov9
pip install -r requirements.txt
wget https://github.com/WongKinYiu/yolov9/releases/download/v0.1/yolov9-t-converted.pt
python export.py --weights=./yolov9-t-converted.pt --include=onnx --img-size=(480,640) 
```

This will generate <yolov9-t-converted.onnx> file.

2.  Inference on OpenCV.

```bash
build opencv from source 
cd build 
./bin/example_dnn_yolo_detector --model=<path-to-yolov9-t-converted.onnx> --yolo=yolov9 --width=640 --height=480 --scale=0.003921568627 --padvalue=114 --path=<path-to-image>
```

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2024-07-02 18:26:34 +03:00
..
dnn_android Updated Android tutorial for MobileNet-SSD detector 2023-12-12 15:40:36 +03:00
dnn_custom_layers Merge remote-tracking branch 'origin/3.4' into merge-3.4 2023-04-21 10:55:04 +03:00
dnn_face Update documentation 2022-01-10 18:34:39 +03:00
dnn_googlenet Merge pull request #25042 from mshabunin:doc-upgrade 2024-03-05 16:19:45 +03:00
dnn_halide Added TOC to most of tutorials 2020-12-07 19:13:54 +03:00
dnn_halide_scheduling added opencv for openvino tutorial 2022-09-28 12:05:28 +02:00
dnn_javascript Added TOC to most of tutorials 2020-12-07 19:13:54 +03:00
dnn_OCR Merge pull request #25042 from mshabunin:doc-upgrade 2024-03-05 16:19:45 +03:00
dnn_openvino Updated Android tutorial for MobileNet-SSD detector 2023-12-12 15:40:36 +03:00
dnn_pytorch_tf_classification fix 4.x links 2021-12-22 13:24:30 +00:00
dnn_pytorch_tf_detection fix 4.x links 2021-12-22 13:24:30 +00:00
dnn_pytorch_tf_segmentation fix 4.x links 2021-12-22 13:24:30 +00:00
dnn_text_spotting Merge pull request #25042 from mshabunin:doc-upgrade 2024-03-05 16:19:45 +03:00
dnn_yolo Merge pull request #25794 from Abdurrahheem:ash/yolov10-support 2024-07-02 18:26:34 +03:00
images Custom deep learning layers in Python 2018-04-26 09:25:18 +03:00
table_of_content_dnn.markdown Updated Android tutorial for MobileNet-SSD detector 2023-12-12 15:40:36 +03:00