How to add opencv lib when using tensorRT inference?

Hi,

I want to use opencv to read jpg image so that I can get the input data for tensorRT inference.
But when compiling, I got the following errors. Any help would be welcome.

I added the linker code in Makefile.config:

LIBS += -lopencv_imgcodecs  -I"/usr/include"
Linking: ../../bin/sample_SSH_debug
../../bin/dchobj/sampleSSH.o: In function `readJPGFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, void*)':
/home/zhangjing/download/TensorRT-5.1.5.0/samples/sampleSSH/sampleSSH.cpp:314: undefined reference to `cv::imread(cv::String const&, int)'
/home/zhangjing/download/TensorRT-5.1.5.0/samples/sampleSSH/sampleSSH.cpp:315: undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
/home/zhangjing/download/TensorRT-5.1.5.0/samples/sampleSSH/sampleSSH.cpp:324: undefined reference to `cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)'
../../bin/dchobj/sampleSSH.o: In function `readJPGFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, void*)':
/usr/local/include/opencv2/core.hpp:366: undefined reference to `cv::noArray()'
../../bin/dchobj/sampleSSH.o: In function `readJPGFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, void*)':
/home/zhangjing/download/TensorRT-5.1.5.0/samples/sampleSSH/sampleSSH.cpp:327: undefined reference to `cv::subtract(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::_InputArray const&, int)'
../../bin/dchobj/sampleSSH.o: In function `cv::String::~String()':
/usr/local/include/opencv2/core/cvstd.hpp:648: undefined reference to `cv::String::deallocate()'
../../bin/dchobj/sampleSSH.o: In function `cv::String::operator=(cv::String const&)':
/usr/local/include/opencv2/core/cvstd.hpp:656: undefined reference to `cv::String::deallocate()'
../../bin/dchobj/sampleSSH.o: In function `cv::Mat::~Mat()':
/usr/local/include/opencv2/core/mat.inl.hpp:774: undefined reference to `cv::fastFree(void*)'
../../bin/dchobj/sampleSSH.o: In function `cv::Mat::release()':
/usr/local/include/opencv2/core/mat.inl.hpp:886: undefined reference to `cv::Mat::deallocate()'
../../bin/dchobj/sampleSSH.o: In function `cv::String::String(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/local/include/opencv2/core/cvstd.inl.hpp:81: undefined reference to `cv::String::allocate(unsigned long)'
collect2: error: ld returned 1 exit status
../Makefile.config:165: recipe for target '../../bin/sample_SSH_debug' failed
make: *** [../../bin/sample_SSH_debug] Error 1

Hi Amy, can you see if something like this fixes your issue?

Thanks,
NVIDIA Enterprise Support

Hi NVES_R,

My issue is fixed refer to your url. Thanks a lot.

Best Regards,
Amy

No problem!