How to use OpenCV3.1 with NVIDIA Nsight?

I have installed OpenCV3.1 on Jetson TX1. OpenCV3.1 works well on Jeston TX1. I copy them to my host computer which is Ubuntu14.04. I want to use them to create a C++ project with NVIDIA Nsight, How can I do these? Anyone can help me?

Hi,

There is a ABI incompatible issue between Ubuntu 16.04 and 14.04.
Since 16.04 use 5.4 compiler, it is required to update your host compiler to 5.x up to make it compatible.

Here is a relevant issue for your reference.
https://devtalk.nvidia.com/default/topic/1002061/jetson-tx1/cross-compile-program-using-opencv-with-jetpack-2-3-1/post/5134815/#5134815.

Thanks.

I got these errors:

16:48:51 **** Incremental Build of configuration Debug for project capture ****
make all 
Building target: capture
Invoking: Cross G++ Linker
aarch64-linux-gnu-g++ -L/home/jack/opencv3.1/lib -L/usr/local/cuda-8.0/targets/aarch64-linux/lib -o "capture"  ./capture.o   -lopencv_core
/home/jack/Desktop/gcc-linaro-5.4.1-2017.05-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/5.4.1/../../../../aarch64-linux-gnu/bin/ld: warning: libz.so.1, needed by /home/jack/opencv3.1/lib/libopencv_core.so, not found (try using -rpath or -rpath-link)
/home/jack/Desktop/gcc-linaro-5.4.1-2017.05-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/5.4.1/../../../../aarch64-linux-gnu/bin/ld: warning: libcudart.so.8.0, needed by /home/jack/opencv3.1/lib/libopencv_core.so, not found (try using -rpath or -rpath-link)
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaHostRegister'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaStreamDestroy'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaStreamWaitEvent'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaGetDeviceCount'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaMemset2D'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `gzeof'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaFree'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaGetDeviceProperties'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaStreamQuery'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaEventSynchronize'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaSetupArgument'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaGetDevice'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `__cudaRegisterFunction'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaEventQuery'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaEventRecord'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaMemset2DAsync'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaDriverGetVersion'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaEventElapsedTime'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaStreamCreate'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaFreeHost'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaConfigureCall'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `gzrewind'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaEventDestroy'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaHostUnregister'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaRuntimeGetVersion'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaMemcpy2D'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaStreamAddCallback'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaEventCreateWithFlags'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaMemcpy2DAsync'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `gzopen'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaHostGetDevicePointer'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaSetDevice'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaMemGetInfo'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaDeviceSynchronize'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaLaunch'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `__cudaUnregisterFatBinary'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaStreamSynchronize'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaHostAlloc'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `gzclose'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `gzgets'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `__cudaRegisterFatBinary'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaMallocPitch'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `gzputs'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaMalloc'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `__cudaRegisterVar'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaGetLastError'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaGetErrorString'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaDeviceReset'
collect2: error: ld returned 1 exit status

Hi,

Could you share more details about you setting.
Do you copy libcudart to host?

Thanks.

Hi,

Thanks for your reply.

I copy all of them to my host. What`s more, I modify the opencv.pc.

I enter the following command at the terminal:

pkg-config --cflags opencv
-I/home/jack/opencv3.1/include/opencv -I/home/jack/opencv3.1/include

pkg-config --libs opencv
-L/home/jack/opencv3.1/lib -lopencv_cudabgsegm -lopencv_cudaobjdetect -lopencv_cudastereo -lopencv_shape -lopencv_stitching -lopencv_cudafeatures2d -lopencv_superres -lopencv_cudacodec -lopencv_videostab -lopencv_cudaoptflow -lopencv_cudalegacy -lopencv_calib3d -lopencv_features2d -lopencv_objdetect -lopencv_highgui -lopencv_videoio -lopencv_photo -lopencv_imgcodecs -lopencv_cudawarping -lopencv_cudaimgproc -lopencv_cudafilters -lopencv_video -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_cudaarithm -lopencv_core -lopencv_cudev

1.CUDA C/C++ Project:

My configuration

NVCC Compiler > Includes > Include paths

/home/jack/opencv3.1/include/opencv
/home/jack/opencv3.1/include

NVCC Linker > Libraries > Libraries

opencv_cudabgsegm
opencv_cudaobjdetect
opencv_cudastereo
.....

NVCC Linker > Library search path

/home/jack/opencv3.1/lib
/usr/local/cuda-8.0/targets/aarch64-linux/lib

When I build project, I got these error:

cannot find -lopencv_cudabgsegm
cannot find -lopencv_cudaobjdetect
cannot find -lopencv_cudastereo

But, I am quite sure that these libs are under the path:/home/jack/opencv3.1/lib

2.A Simple C++ Project:

I have upgraded host cross-compiler to 5.x

https://releases.linaro.org/components/toolchain/binaries/latest-5/aarch64-linux-gnu/

My Cross Settings

Prefix:

aarch64-linux-gnu-

Path:

/home/jack/Desktop/gcc-linaro-5.4.1-2017.05-x86_64_aarch64-linux-gnu/bin

My configuration

Cross G++ Complier > Includes

/home/jack/opencv3.1/include/opencv
/home/jack/opencv3.1/include

\

Cross G++ Linker > Libraries > Libraries

opencv_core

Cross G++ Linker > Libraries > Library search path

/home/jack/opencv3.1/lib
/usr/local/cuda-8.0/targets/aarch64-linux/lib

When I build project, I got these error too:

arch64-linux-gnu-g++ -L/home/jack/opencv3.1/lib -L/usr/local/cuda-8.0/targets/aarch64-linux/lib -o "capture"  ./capture.o   -lopencv_core
/home/jack/Desktop/gcc-linaro-5.4.1-2017.05-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/5.4.1/../../../../aarch64-linux-gnu/bin/ld: warning: libz.so.1, needed by /home/jack/opencv3.1/lib/libopencv_core.so, not found (try using -rpath or -rpath-link)
/home/jack/Desktop/gcc-linaro-5.4.1-2017.05-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/5.4.1/../../../../aarch64-linux-gnu/bin/ld: warning: libcudart.so.8.0, needed by /home/jack/opencv3.1/lib/libopencv_core.so, not found (try using -rpath or -rpath-link)
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaHostRegister'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaStreamDestroy'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaStreamWaitEvent'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaGetDeviceCount'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaMemset2D'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `gzeof'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaFree'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaGetDeviceProperties'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaStreamQuery'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaEventSynchronize'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaSetupArgument'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaGetDevice'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `__cudaRegisterFunction'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaEventQuery'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaEventRecord'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaMemset2DAsync'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaDriverGetVersion'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaEventElapsedTime'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaStreamCreate'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaFreeHost'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaConfigureCall'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `gzrewind'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaEventDestroy'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaHostUnregister'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaRuntimeGetVersion'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaMemcpy2D'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaStreamAddCallback'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaEventCreateWithFlags'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaMemcpy2DAsync'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `gzopen'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaHostGetDevicePointer'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaSetDevice'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaMemGetInfo'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaDeviceSynchronize'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaLaunch'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `__cudaUnregisterFatBinary'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaStreamSynchronize'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaHostAlloc'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `gzclose'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `gzgets'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `__cudaRegisterFatBinary'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaMallocPitch'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `gzputs'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaMalloc'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `__cudaRegisterVar'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaGetLastError'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaGetErrorString'
/home/jack/opencv3.1/lib/libopencv_core.so: undefined reference to `cudaDeviceReset'
collect2: error: ld returned 1 exit status

CUDA C/C++ Project can find lopencv_core and some other usual libs, but can`t find lopencv_cudabgsegm, lopencv_cudaobjdetect… And C++ Project can find these libs, but there are different errors.

Look forward to your reply.

Hi,

Sorry for keeping you waiting.
I tested Nsight with opencv today and it works well.

Here is my procedure:

1. Libraries and headers:

scp -r ubuntu@[device IP]:[opencv source]/release/lib [host folder]
scp -r ubuntu@[device IP]:/usr/local/include [host folder]
scp ubuntu@[device IP]:/usr/local/cuda-8.0/lib64/libcudart.so.8.0.34 [host folder]/lib
scp ubuntu@[device IP]:/usr/lib/aarch64-linux-gnu/libtbb.so.2 [host folder]/lib
scp ubuntu@[device IP]:/lib/aarch64-linux-gnu/libz.so.1.2.8 [host folder]/lib
sudo ln -s [host folder]/lib/libcudart.so.8.0.34 [host folder]/lib/libcudart.so
sudo ln -s [host folder]/lib/libtbb.so.2 [host folder]/lib/libtbb.so
sudo ln -s [host folder]/lib/libz.so.1.2.8 [host folder]/lib/libz.so

2. Create Nsight project
File -> New -> CUDA C/C++ Project
Empty Project -> Generate PTX code=5.3, Generate GPU code=5.3 -> CPU Architecture=AArch64

3. Add configuration (right click -> properties)
Build -> Settings -> Tool Settings
NVCC Compiler -> Includes -> Include paths -> Add “[host folder]/include”
NVCC Linker -> Libraries -> Libraries -> Add “opencv_core”, “cudart”, “tbb”, “z”
NVCC Linker -> Libraries -> Library search path -> Add “[host folder]/lib”

4. Add your source, here is my test code

#include<opencv2/core.hpp>

int main(void)
{
    cv::Mat img;
    return 0;
}

5. Click hammer for compiling.

6. Run -> Run as -> Remote C/C++ Application

I’m very sorry for replying so late.

It works well, thank you!