OpenCV 3.2 with Cuda Compilation

I tried to compile the current master branch of OpenCV. The compilation runs fine, but for some functions that I want to use I get the following error:

OpenCV Error: Gpu API call (invalid argument) in bindTexture, file /home/nvidia/opencv/modules/core/include/opencv2/core/cuda/common.hpp, line 102
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/nvidia/opencv/modules/core/include/opencv2/core/cuda/common.hpp:102: error: (-217) invalid argument in function bindTexture

This happens when I call

cv::cuda::remap(frameGpu,out,map1,map2,CV_INTER_NN);

I compiled OpenCV with

cmake .. -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DCUDA_ARCH_BIN=6.2

The same code is working on TX1 with same CUDA version and same OpenCV version.

Has anyone compiled a working OpenCV with cuda with the TX2 so far?
Thank you for any suggestions

P.S.: I think there should be a sticky “OpenCV Compilation Guide” in this board.

Just built opencv3.1.0 it works fine for the real time SLAM project I’m fooling with. You might want to follow the directions on this page. I’ve used it to build opencv a few times now with no issues. http://docs.opencv.org/3.2.0/d6/d15/tutorial_building_tegra_cuda.html Also figure out how to get cuda supported opencv libs in ROS. That is a real pain to figure out. If you need to do that this page will guide you. Its in Japanese and the translation screwed up the command lines on my box but if you hover over them with the mouse the correct lines will appear. http://qiita.com/kendemu/items/a805b0b9828b6f6031db I flashed the TX2 without installing opencv4tegra before building opencv3x.

Thank you, I will try with a clean flashed TX2. What CUDA_ARCH_BIN did you use?
Can you build a minimal example that shows remap is working?

This is working on my host but not on TX2:

#include <opencv2/opencv.hpp>
#include <opencv2/cudawarping.hpp>
#include <iostream>

int main()
{
    cv::cuda::GpuMat in(100,100, CV_8U);
    cv::cuda::GpuMat out(100,100, CV_8U);
    cv::cuda::GpuMat m1(100,100, CV_32F);
    cv::cuda::GpuMat m2(100,100, CV_32F);
    cv::cuda::remap(in,out,m1,m2,CV_INTER_NN);
    std::cout << "Success ! " << std::endl;
}

For TX2, CUDA arch is 6.2, so use -DCUDA_ARCH_BIN=6.2.

According to http://docs.opencv.org/trunk/db/d29/group__cudawarping.html#ga0ece6c76e8efa3171adb8432d842beb0,
Remap will perform:

dst(x,y) = src(xmap(x,y) , ymap(x,y))

but are your xmap and ymap initialized elsewhere ?

xmap and ymap was initialized with random values. This was just a minimal example which normally should run fine.

However, I flashed my TX2 using jetpack (opencv4tegra unchecked) and compiled OpenCV again with

cmake .. -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DCUDA_ARCH_BIN=6.2

Now it works.

The problem could be:

  • factory image of the tx2
  • old cuda version 8.0.34
  • messing up the system while trying multiple opencv/cuda combinations

Thank you guys for your fast response.