OpenCV 3.3 with gpu using problem

I use TX1 board with L4T 28.1
I compile opencv on the board with DWITH_CUDA=ON with cuda 8 toolkit
I try to use opencv functions, which use gpu. I try to declare GpuMat

GpuMat TestGpuMat(480, 640, CV_16UC1, 0x55);

and get Segmentation fault during runtime in module cv::cuda::GpuMat::create().
I can allocate the same matrix if I provide the allocated memory before

CudaMallocManaged((void**)MyBuf, 640*480*sizeof(unsigned short));
GpuMat TestGpuMat(480, 640, CV_16UC1, MyBuf)

In that case I receive the fault in cuda::warpAffine function

OpenCVError: Gpu API call (invalid argument) in setTo

What is a reason for that behavior and what is solution?


Could you share your installation steps? I would like to try it as well.

This code works fine on my TX1 R28.1 with opencv-3.3.0 built with cuda8 support:

#include <opencv2/opencv.hpp>

int main(int argc, char** argv) {
	cv::cuda::GpuMat testGpuMat(480, 640, CV_16UC1, 0x55);
	cv::Mat testMat(480, 640, CV_16UC1);;

	cv::imshow("Test", testMat);
	return 0;

If it doesn’t work in your case, it may be using opencv4tegra libs at run time instead of opencv-3.3.0.

I compiled the example above with:

g++ -I/usr/local/opencv-3.3.0/include cv_gpu.cpp -L/usr/local/opencv-3.3.0/lib -lopencv_core -lopencv_highgui -otestCvGpu

as my opencv-3.3.0 is installed in /usr/local, and set LD_LIBRARY_PATH before running:

export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/opencv-3.3.0/lib

What configuration do you use for compilation opencv on board?

Are you still facing the same error message with the example above ?
You may rule out the runtime libraries issue checking with:

ldd ./testCvGpu

As opencv4tegra is installed in /usr, its headers and libs would be found it you don’t specify the location of opencv-3.3.0.

I am away from my TX1 for checking the opencv config, but I use to configure with cmake-gui (using Advanced/Grouped options is better). I use to build in a build directory that is not inside sources tree.
Click on configure and check for any message in red in the cmake-gui console.
Just be sure to disable any opencl* it may enable in group ‘WITH’.
Set CMAKE_INSTALL_PREFIX to your preferred install directory (I use /usr/local/opencv-3.3.0).
It should be enough, but check also that:

  • CUDA is detected and supported (for TX1 arch is 5.3).
  • CMAKE Build type is 'Release.

You may also activate other options, such as v4l2 and gstreamer-1.0 support.
Click on configure and check everything is ok, then click on generate to create the makefiles.
Then build, install, and retest the sample code above.

You may also check

Thank you for information. I will check after weekend.

We succeed to run our application with Opencv 3.3. We work with cross compiler and one of namespaces was incorrect.
Can I expect better performance from opencv3.3 relative to opencv4tegra?

It depends on your application. You would have to bench both.
Compiler and compiler options can also improve. See: