how to inlcude Opencv on sampleFasterRCNN

I’m currently working on sampleFasterRCNN that jetsonTX2 provides
and I want to add some opencv code on sampleFasterRCNN code
actually I know how to run opencv with Cmakelists.txt but
the sampleFasterRCNN runs with Makefile
and I can’t figure out how to run Makefile with adding opencv or
cmakelists.txt with adding Makefile

====
This is how i did by making Cmakelists.txt including Makefile

cmake_minimum_required(VERSION 2.8)

project(sampleFasterRCNN)

find_package(OpenCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS} /usr/include/)

SET(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -std=c++11 -pthread”)

add_executable(sampleFasterRCNN sampleFasterRCNN.cpp common.h /usr/local/cuda-9.0/targets/aarch64-linux/include/cuda_runtime_api.h)

target_link_libraries(sampleFasterRCNN ${OpenCV_LIBS} /usr/lib/libueye_api.so)

add_custom_target(COMMAND make run

	  WORKING_DIRECTORY ${CMAKE_CURRENT_DIR}/<subdir>

)

Hi,

Here is a sample for your reference:

cmake_minimum_required(VERSION 2.8)

project(TensorRT-sample)

set(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(
	CUDA_NVCC_FLAGS
	${CUDA_NVCC_FLAGS}; 
	-O3 
	-gencode arch=compute_53,code=sm_53
	-gencode arch=compute_62,code=sm_62
)

find_package(CUDA)
find_package(OpenCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS} /usr/local/cuda/include /usr/include/aarch64-linux-gnu)
link_directories(/usr/lib/aarch64-linux-gnu)

add_executable(sample_fasterRCNN sampleFasterRCNN.cpp)

target_link_libraries(sample_fasterRCNN nvcaffe_parser nvinfer_plugin nvinfer ${OpenCV_LIBS})

You can find some information in our jetson_inference sample:

And OpenCV tutorial:

Thanks.

thanks!!
it did help a lot!!
Still i got these problems…

– The C compiler identification is GNU 5.4.0
– The CXX compiler identification is GNU 5.4.0
– Check for working C compiler: /usr/bin/cc
– Check for working C compiler: /usr/bin/cc – works
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Detecting C compile features
– Detecting C compile features - done
– Check for working CXX compiler: /usr/bin/c++
– Check for working CXX compiler: /usr/bin/c++ – works
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Detecting CXX compile features
– Detecting CXX compile features - done
– Looking for pthread.h
– Looking for pthread.h - found
– Looking for pthread_create
– Looking for pthread_create - not found
– Looking for pthread_create in pthreads
– Looking for pthread_create in pthreads - not found
– Looking for pthread_create in pthread
– Looking for pthread_create in pthread - found
– Found Threads: TRUE
– Found CUDA: /usr/local/cuda (found version “9.0”)
– Found OpenCV: /usr (found version “3.3.1”)
– Configuring done
– Generating done
– Build files have been written to: /home/nvidia/tensorrt/samples/sampleFasterRCNN/build
Scanning dependencies of target sample_fasterRCNN
[ 50%] Building CXX object CMakeFiles/sample_fasterRCNN.dir/sampleFasterRCNN.cpp.o
[100%] Linking CXX executable sample_fasterRCNN
/usr/bin/ld: CMakeFiles/sample_fasterRCNN.dir/sampleFasterRCNN.cpp.o: undefined reference to symbol ‘cudaFree@@libcudart.so.9.0
//usr/local/cuda-9.0/targets/aarch64-linux/lib/libcudart.so.9.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/sample_fasterRCNN.dir/build.make:111: recipe for target ‘sample_fasterRCNN’ failed
make[2]: *** [sample_fasterRCNN] Error 1
CMakeFiles/Makefile2:67: recipe for target ‘CMakeFiles/sample_fasterRCNN.dir/all’ failed
make[1]: *** [CMakeFiles/sample_fasterRCNN.dir/all] Error 2
Makefile:83: recipe for target ‘all’ failed
make: *** [all] Error 22

so I tried to fix CMakelists like this…
link_directories(/usr/lib/aarch64-linux-gnu /usr/local/cuda-9.0/targets/aarch64-linux)
and it still doesn’t work .I guess this is not the way…

Do you have /usr/local/cuda/lib64 in your link dirs ? You may also set LD_LIBRARY_PATH environment variable having this path.
If it is not enough, you may also add -lcudart into your link options.

After editing my CMakelists and taking your advice,

It worked perfectly !! Thanks a lot !!