UNeedCryDear / yolov8-opencv-onnxruntime-cpp

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

How can I compile the main.cpp? #6

Closed EXINEF closed 1 year ago

EXINEF commented 1 year ago

Is it possible to compile it from Visual Studio Code? Should I use gcc or cmake? How does it work?

UNeedCryDear commented 1 year ago

You need a cmakelists.txt, but I'm not good at it. I can only write a example for you and I'm not sure if it will work on linux.

CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0)
project(YOLOv8)

SET (OpenCV_DIR path/to/opencv/build)  #opencv root
SET (ONNXRUNTIME_DIR path/to/onnxruntime)

FIND_PACKAGE(OpenCV REQUIRED)
#include_directories("")
ADD_EXECUTABLE(YOLOv8 yolov8.h yolov8_onnx.h yolov8_seg.h yolov8_seg_onnx.h yolov8_utils.h
             main.cpp yolov8.cpp yolov8_onnx.cpp yolov8_seg.cpp yolov8_seg_onnx.cpp yolov8_utils.cpp)

SET(CMAKE_CXX_STANDARD 14)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)

TARGET_INCLUDE_DIRECTORIES(YOLOv8 PRIVATE "${ONNXRUNTIME_DIR}/include")

TARGET_COMPILE_FEATURES(YOLOv8 PRIVATE cxx_std_14)
TARGET_LINK_LIBRARIES(YOLOv8 ${OpenCV_LIBS})

if (WIN32)
    TARGET_LINK_LIBRARIES(YOLOv8 "${ONNXRUNTIME_DIR}/lib/onnxruntime.lib")
endif(WIN32)

if (UNIX)
    TARGET_LINK_LIBRARIES(YOLOv8 "${ONNXRUNTIME_DIR}/lib/libonnxruntime.so")
endif(UNIX)
EXINEF commented 1 year ago

Thank you, how do I link the OnnxRuntime folder, where can I download it?

UNeedCryDear commented 1 year ago

https://github.com/microsoft/onnxruntime or https://github.com/microsoft/onnxruntime/releases