UNeedCryDear / yolov8-opencv-onnxruntime-cpp

yolov8 hub,cpp with onnxruntime and opencv
Apache License 2.0
341 stars 60 forks source link

How to use ? #19

Closed EthanAbitbol3 closed 1 year ago

EthanAbitbol3 commented 1 year ago

Hello and thank you for your work !

I am a newcomer to C++ and I've been attempting to comprehend how to use/compile the code, but I haven't been successful. Could you kindly provide guidance on how to utilize your code? Here's some additional information:

Thank you once again for your help!

UNeedCryDear commented 1 year ago

use cmake https://github.com/UNeedCryDear/yolov8-opencv-onnxruntime-cpp/blob/4b90bf0c3d86d67faf1a3683ccace79163b7c16d/CMakeLists.txt#L5

set opencv and opnnxruntime path. If you don't know how to use cmake, please Google it. This is no something that can be explained clearly in just a few words, especially since different IDEs have different configuration schemes. I'm not sure what IDE you're using, I can only tell you about the general purpose.

If you are using VS/VScode, please configure the library path and header file path for opencv and onnxruntime in the project properties (this is not difficult, I believe it will be much simpler than the cmake above, as long as you Google VS to configure opencv and onnxruntime), and then add the source code to the project for compilation.

UNeedCryDear commented 1 year ago

For example of vs2019: (I'm sorry I only have Chinese UI)

  1. File->new ->progect ->win32 Console Application -> Empty project ->next step image

  2. set your peoject name and path,and then create project. image

  3. download src code to project,and then add into project.Right-click the source code option and select Add existing item image

  4. change project to x64 image

  5. Find the Property-Manager-window in the View image

  6. Open the X64 properties page and configure the include paths for opencv and onnxruntime.Note that you are using your own path and version number replacements for opencv and onnxruntime image

  7. add libliry path,Note that you are using your own path and version number replacements for opencv and onnxruntime image 8.Add additional dependencies,include "onnxruntime.lib" and "opencv_worldxxxd.lib",“xxx” is your opencv version image

  8. When everything is configured, you are ready to run. Just replace the models and images with your own path. https://github.com/UNeedCryDear/yolov8-opencv-onnxruntime-cpp/blob/4b90bf0c3d86d67faf1a3683ccace79163b7c16d/main.cpp#L81

EthanAbitbol3 commented 1 year ago

I greatly appreciate your explanations! I'm going to start working on this right away.

EthanAbitbol3 commented 1 year ago

Do I have to use the ONNX Runtime library? Because I can't seem to download it on Windows, and I just want to use OpenCV. I tried downloading it directly through Visual Studio 2019, but I'm not sure if that will work.

I have created the project and imported the files: image

Then I changed the solution platform to x64: image

Next, I located the Property Manager: image

I added the path : image

Then, I modified the additional dependencies: image

Finally, I updated the paths for the models and images as follows: image

To compile, I executed: image

I encountered the following error: image

Thank you again for your time and your help !

UNeedCryDear commented 1 year ago

https://github.com/microsoft/onnxruntime/releases/tag/v1.15.1

UNeedCryDear commented 1 year ago

If you only want opencv to inference, remove the files with “xxxx_onnx.h/.cpp” characters in the file name from your project, and finally remove the relevant "xxx_onn.h" and classes from the main.cpp

EthanAbitbol3 commented 1 year ago

thank you again for thoses informations, unfortunately :

image

image

I forgot to mention that i train on a custom dataset with 2 classes and image size of 512x512

Thank you again !

UNeedCryDear commented 1 year ago

change _ClassNames and _netWidth/_netHeight/_segW/_segH

EthanAbitbol3 commented 1 year ago

Amazing ! Thank you so much for everything !!