Skip to content

First version #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: CI

on: [push, pull_request]

jobs:
tue-ci:
name: TUe CI - ${{ github.event_name }}
runs-on: ubuntu-latest
steps:
- name: TUe CI
uses: tue-robotics/tue-env/ci/main@master
with:
package: ${{ github.event.repository.name }}
64 changes: 44 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,61 @@
cmake_minimum_required(VERSION 3.5)
project(yolo_onnx_ros)

set(PROJECT_NAME Yolov8OnnxRuntimeCPPInference)
project(${PROJECT_NAME} VERSION 0.0.1 LANGUAGES CXX)
add_compile_options(-Wall -Werror=all)
add_compile_options(-Wextra -Werror=extra)

# -------------- Support C++17 for using filesystem ------------------#
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
#set(CMAKE_INCLUDE_CURRENT_DIR ON)

# -------------- OpenCV ------------------#
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

find_package(catkin REQUIRED
COMPONENTS
onnxruntime_ros
)


# ------------------------------------------------------------------------------------------------
# CATKIN EXPORT
# ------------------------------------------------------------------------------------------------

catkin_package(
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME}
CATKIN_DEPENDS
DEPENDS OpenCV
)

# ------------------------------------------------------------------------------------------------
# BUILD
# ------------------------------------------------------------------------------------------------

include_directories(
include
SYSTEM
${OpenCV_INCLUDE_DIRS}
${catkin_INCLUDE_DIRS}
)

# -------------- ONNXRuntime ------------------#
set(ONNXRUNTIME_VERSION 1.21.0)
set(ONNXRUNTIME_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../onnxruntime-linux-x64-gpu-1.21.1")
include_directories(${ONNXRUNTIME_ROOT}/include)

# -------------- Cuda ------------------#
add_definitions(-DUSE_CUDA=1)
include_directories(/usr/local/cuda/include)

set(PROJECT_SOURCES
src/main.cpp
src/yolo_inference.cpp
add_library(${PROJECT_NAME}
src/yolo_inference.cpp
)
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBRARIES} ${catkin_LIBRARIES})

add_executable(${PROJECT_NAME} ${PROJECT_SOURCES})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc)

# Link OpenCV libraries along with ONNX Runtime
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS} ${ONNXRUNTIME_ROOT}/lib/libonnxruntime.so)
add_executable(test_${PROJECT_NAME}
src/main.cpp
)
target_link_libraries(test_${PROJECT_NAME} ${PROJECT_NAME} ${OpenCV_LIBRARIES} ${catkin_LIBRARIES})

# For Windows system, copy onnxruntime.dll to the same folder of the executable file
if (WIN32)
Expand All @@ -46,9 +70,9 @@ endif ()
configure_file(data/coco.yaml ${CMAKE_CURRENT_BINARY_DIR}/coco.yaml COPYONLY)

# Copy yolov8n.onnx file to the same folder of the executable file
configure_file(model/yolo11m.onnx ${CMAKE_CURRENT_BINARY_DIR}/yolo11m.onnx COPYONLY)
# configure_file(model/yolo11m.onnx ${CMAKE_CURRENT_BINARY_DIR}/yolo11m.onnx COPYONLY)

# Create folder name images in the same folder of the executable file
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/images
)
# # Create folder name images in the same folder of the executable file
# add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/images
# )
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <vector>
#include <cstdio>
#include <opencv2/opencv.hpp>
#include "onnxruntime_cxx_api.h"
#include <onnxruntime_cxx_api.h>

#ifdef USE_CUDA
#include <cuda_fp16.h>
Expand Down Expand Up @@ -92,4 +92,4 @@ class YOLO_V8
float rectConfidenceThreshold;
float iouThreshold;
float resizeScales;//letterbox scale
};
};
29 changes: 29 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<?xml-model
href="http://download.ros.org/schema/package_format3.xsd"
schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>yolo_onnx_ros</name>
<version>0.0.0</version>
<description>Yolo inference</description>

<maintainer email="[email protected]">Iason Theodorou</maintainer>

<license>ToDo</license>

<buildtool_depend>catkin</buildtool_depend>

<build_depend>libopencv-dev</build_depend>
<exec_depend>libopencv-dev</exec_depend>
<build_depend>onnxruntime_ros</build_depend>
<exec_depend>onnxruntime_ros</exec_depend>

<test_depend>catkin_lint_cmake</test_depend>

<doc_depend>doxygen</doc_depend>

<export>
<rosdoc config="rosdoc.yaml" />
</export>

</package>
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <iostream>
#include <iomanip>
#include "yolo_inference.h"
#include "yolo_onnx_ros/yolo_inference.h"
#include <filesystem>
#include <fstream>
#include <random>
Expand Down Expand Up @@ -192,4 +192,4 @@ int main()
{
DetectTest();
//ClsTest();
}
}
4 changes: 2 additions & 2 deletions src/yolo_inference.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "yolo_inference.h"
#include "yolo_onnx_ros/yolo_inference.h"
#include <regex>

#define benchmark
Expand Down Expand Up @@ -383,4 +383,4 @@ char* YOLO_V8::WarmUpSession() {
#endif
}
return RET_OK;
}
}
Loading