Hi,
I’m trying to do inference on video with a torchscript model. Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(YOLOv5LibTorch)
SET(CMAKE_BUILD_TYPE Release)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV_INCLUDE_DIRS = ${OpenCV_INCLUDE_DIRS}")
message(STATUS "OpenCV_LIBS = ${OpenCV_LIBS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
set(CMAKE_PREFIX_PATH /home/mauro/libtorch)
find_package(Torch REQUIRED)
add_executable(YOLOv5LibTorch src/YOLOv5LibTorch.cpp)
include_directories(
${PROJECT_SOURCE_DIR}/include
${OpenCV_INCLUDE_DIRS}
)
target_link_libraries(YOLOv5LibTorch ${OpenCV_LIBS} ${TORCH_LIBRARIES})
set_property(TARGET YOLOv5LibTorch PROPERTY CXX_STANDARD 17)
When I run cmake … I get this output:
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenCV: /usr (found version "4.5.4")
-- OpenCV_INCLUDE_DIRS = /usr/include/opencv4
-- OpenCV_LIBS = opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_stitching;opencv_video;opencv_videoio;opencv_alphamat;opencv_aruco;opencv_barcode;opencv_bgsegm;opencv_bioinspired;opencv_ccalib;opencv_datasets;opencv_dnn_objdetect;opencv_dnn_superres;opencv_dpm;opencv_face;opencv_freetype;opencv_fuzzy;opencv_hdf;opencv_hfs;opencv_img_hash;opencv_intensity_transform;opencv_line_descriptor;opencv_mcc;opencv_optflow;opencv_phase_unwrapping;opencv_plot;opencv_quality;opencv_rapid;opencv_reg;opencv_rgbd;opencv_saliency;opencv_shape;opencv_stereo;opencv_structured_light;opencv_superres;opencv_surface_matching;opencv_text;opencv_tracking;opencv_videostab;opencv_viz;opencv_wechat_qrcode;opencv_ximgproc;opencv_xobjdetect;opencv_xphoto
-- Found Torch: /home/mauro/libtorch/lib/libtorch.so
-- Configuring done (0.3s)
-- Generating done (0.0s)
-- Build files have been written to: /home/mauro/Desktop/YOLOv5-LibTorch/build
Which point to the correct OpenCV directory, but when I try to do make to create the executable, I get these errors:
/usr/bin/ld: CMakeFiles/YOLOv5LibTorch.dir/src/YOLOv5LibTorch.cpp.o: in function `main':
YOLOv5LibTorch.cpp:(.text.startup+0xdd6): undefined reference to `cv::putText(cv::_InputOutputArray const&, std::string const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'
/usr/bin/ld: YOLOv5LibTorch.cpp:(.text.startup+0xe59): undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
/usr/bin/ld: YOLOv5LibTorch.cpp:(.text.startup+0x10e8): undefined reference to `cv::putText(cv::_InputOutputArray const&, std::string const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'
/usr/bin/ld: YOLOv5LibTorch.cpp:(.text.startup+0x1540): undefined reference to `cv::format(char const*, ...)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/YOLOv5LibTorch.dir/build.make:155: /home/mauro/Desktop/YOLOv5-LibTorch/bin/YOLOv5LibTorch] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/YOLOv5LibTorch.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
In the .cpp I included opencv:
#include <opencv2/opencv.hpp>
What could be the error?