# OpenCV 3.3 with gpu using problem

**URL:** <https://forums.developer.nvidia.com/t/opencv-3-3-with-gpu-using-problem/58330>\
**Category:** Jetson TX1\
**Created:** [February 19, 2018, 12:28pm UTC](https://forums.developer.nvidia.com/t/opencv-3-3-with-gpu-using-problem/58330 "2018-02-19T12:28:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexs66](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Alexs66](https://forums.developer.nvidia.com/u/Alexs66)\
**Post date:** [February 19, 2018, 12:28pm UTC](https://forums.developer.nvidia.com/t/opencv-3-3-with-gpu-using-problem/58330/1 "2018-02-19T12:28:47Z")

</div>

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

```auto
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

```auto
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?

---

<div class="post-metadata">

**Author:** ![WayneWWW](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/waynewww/32/14043_2.png) [@WayneWWW](https://forums.developer.nvidia.com/u/WayneWWW)\
**Post date:** [February 22, 2018, 8:56am UTC](https://forums.developer.nvidia.com/t/opencv-3-3-with-gpu-using-problem/58330/2 "2018-02-22T08:56:07Z")

</div>

Alexs66,

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

---

<div class="post-metadata">

**Author:** ![Honey\_Patouceul](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/honey_patouceul/32/389777_2.png) [@Honey\_Patouceul](https://forums.developer.nvidia.com/u/Honey_Patouceul)\
**Post date:** [February 22, 2018, 3:09pm UTC](https://forums.developer.nvidia.com/t/opencv-3-3-with-gpu-using-problem/58330/3 "2018-02-22T15:09:44Z")

</div>

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

```auto
#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);
	testGpuMat.download(testMat);

	cv::imshow("Test", testMat);
	cv::waitKey(-1);
	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:

```auto
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:

```auto
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/opencv-3.3.0/lib
./testCvGpu

```

---

<div class="post-metadata">

**Author:** ![Alexs66](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Alexs66](https://forums.developer.nvidia.com/u/Alexs66)\
**Post date:** [February 22, 2018, 5:24pm UTC](https://forums.developer.nvidia.com/t/opencv-3-3-with-gpu-using-problem/58330/4 "2018-02-22T17:24:27Z")

</div>

What configuration do you use for compilation opencv on board?

---

<div class="post-metadata">

**Author:** ![Honey\_Patouceul](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/honey_patouceul/32/389777_2.png) [@Honey\_Patouceul](https://forums.developer.nvidia.com/u/Honey_Patouceul)\
**Post date:** [February 22, 2018, 7:13pm UTC](https://forums.developer.nvidia.com/t/opencv-3-3-with-gpu-using-problem/58330/5 "2018-02-22T19:13:54Z")

</div>

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

```auto
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 [https://jkjung-avt.github.io/opencv3-on-tx2/](https://jkjung-avt.github.io/opencv3-on-tx2/).

---

<div class="post-metadata">

**Author:** ![Alexs66](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Alexs66](https://forums.developer.nvidia.com/u/Alexs66)\
**Post date:** [February 22, 2018, 8:58pm UTC](https://forums.developer.nvidia.com/t/opencv-3-3-with-gpu-using-problem/58330/6 "2018-02-22T20:58:02Z")

</div>

Thank you for information. I will check after weekend.

---

<div class="post-metadata">

**Author:** ![Alexs66](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Alexs66](https://forums.developer.nvidia.com/u/Alexs66)\
**Post date:** [March 1, 2018, 8:35am UTC](https://forums.developer.nvidia.com/t/opencv-3-3-with-gpu-using-problem/58330/7 "2018-03-01T08:35:13Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Honey\_Patouceul](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/honey_patouceul/32/389777_2.png) [@Honey\_Patouceul](https://forums.developer.nvidia.com/u/Honey_Patouceul)\
**Post date:** [March 1, 2018, 12:32pm UTC](https://forums.developer.nvidia.com/t/opencv-3-3-with-gpu-using-problem/58330/8 "2018-03-01T12:32:30Z")

</div>

It depends on your application. You would have to bench both.  
Compiler and compiler options can also improve. See: [url][Gcc options for TX2 - Jetson TX2 - NVIDIA Developer Forums](https://devtalk.nvidia.com/default/topic/1028179/%5B/url%5D).

---

<div class="post-metadata">

**Author:** ![TomNVIDIA](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/tomnvidia/32/14181_2.png) [@TomNVIDIA](https://forums.developer.nvidia.com/u/TomNVIDIA)\
**Post date:** [October 18, 2021, 6:58pm UTC](https://forums.developer.nvidia.com/t/opencv-3-3-with-gpu-using-problem/58330/9 "2021-10-18T18:58:14Z")

</div>


