opencv/samples
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
..
android Build warning fix in Tutorial4-OpenCL. 2024-01-31 12:51:28 +03:00
cpp Merge pull request #25813 from kaingwade:orbbec-astra 2024-07-01 10:55:35 +03:00
data Merge pull request #24496 from cabelo:yolov3 2023-11-14 09:06:36 +03:00
directx Merge pull request #22462 from Biswa96:fix-directx-check 2022-10-03 08:37:36 +03:00
dnn Merge pull request #25794 from Abdurrahheem:ash/yolov10-support 2024-07-02 18:26:34 +03:00
gdb Merge pull request #21805 from rogday:pretty_fix 2022-04-20 04:55:04 +00:00
gpu Merge pull request #22615 from cudawarped:nvcuvenc 2022-10-28 11:03:51 +03:00
hal build: suppress the warning 2022-07-12 19:42:39 +09:00
install fix 4.x links 2021-12-22 13:24:30 +00:00
java Backport C-API cleanup (imgproc) from 5.x 2023-01-16 23:29:50 +03:00
opencl samples: fix OpenCL events leaks 2020-05-14 17:15:09 +00:00
opengl use findFile in opengl.cpp sample 2023-03-20 15:44:14 +01:00
openvx build: suppress the warning 2022-07-12 19:42:39 +09:00
python Merge pull request #24201 from lpylpy0514:4.x 2023-09-19 15:36:38 +03:00
semihosting fix 4.x links 2021-12-22 13:24:30 +00:00
swift/ios Update tests and samples to work with changes to dynamic build 2020-09-27 21:12:28 +09:00
sycl ocl: fixes for OpenCL multiple contexts support 2020-09-03 20:34:49 +00:00
tapi Merge pull request #19755 from mikhail-nikolskiy:ffmpeg-umat 2021-05-14 16:48:50 +00:00
va_intel samples(va): fix build warnings, use cv::format() 2021-02-19 10:36:26 +00:00
winrt Fix some typos in platforms/, samples/, 3rdparty/. 2022-09-07 16:09:23 +03:00
winrt_universal samples: avoid using of legacy C-like API (part 2) 2018-03-29 14:17:23 +03:00
wp8 Merge pull request #20223 from jogo-:3.4_wp8_samples_typos 2021-06-07 17:32:14 +00:00
_winpack_build_sample.cmd Merge remote-tracking branch 'upstream/3.4' into merge-3.4 2020-05-18 17:50:16 +00:00
_winpack_run_python_sample.cmd samples: add Python 3.12 2023-12-20 21:32:46 +03:00
CMakeLists.example.in cmake: enable C++11 implicitly 2020-02-03 17:45:37 +03:00
CMakeLists.txt build: suppress the warning 2022-07-12 19:42:39 +09:00
samples_utils.cmake imgproc: add IntelligentScissors 2020-12-25 10:57:11 +00:00