Ask Your Question

Revision history [back]

Cmake error OpenCV contrib CUDA

Hi,

I am trying to run a sample code of opencv in my Jetson Nano that uses the cudaarithm contribution module. The code is simple, just do a threshold in the gpu:

/* OpenCV: Thresholding using GPU */
#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/cuda.hpp"
#include "opencv2/cudaarithm.hpp"

using namespace cv;

int main (int argc, char* argv[])
{
    try
    {
        cv::Mat src_host = cv::imread("Oak_Tree.png", IMREAD_GRAYSCALE);
        cv::cuda::GpuMat dst, src;
        src.upload(src_host);

        cv::cuda::threshold(src, dst, 128.0, 255.0, THRESH_BINARY);

        cv::Mat result_host;
        dst.download(result_host);
        cv::imshow("Result", result_host);
        cv::waitKey();
    }
    catch(const cv::Exception& ex)
    {
        std::cout << "Error: " << ex.what() << std::endl;
    }
    return 0;
}

I have installed OpenCV and build other project previously, I just can't find how to link in cmake the cuda:

cmake_minimum_required(VERSION 3.0)
project( opencvgpu )

find_package( OpenCV 4.3 REQUIRED)
find_package(CUDA REQUIRED)


include_directories( ${OpenCV_INCLUDE_DIRS} ${CUDA_INCLUDE_DIRS} )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} ${CUDA_LIBRARIES} )

And I always get the same error:

felipevw@felipevw-desktop:~/opencvgpu$ cmake .
-- Found CUDA: /usr/local/cuda (found suitable exact version "10.0") 
-- Found OpenCV: /usr/local (found suitable version "4.3.0", minimum required is "4.3") 
-- Found CUDA: /usr/local/cuda (found version "10.0") 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/felipevw/opencvgpu
felipevw@felipevw-desktop:~/opencvgpu$ make
Scanning dependencies of target DisplayImage
[ 50%] Building CXX object CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o
/home/felipevw/opencvgpu/DisplayImage.cpp:5:10: fatal error: opencv2/cuda.hpp: No such file or directory
 #include "opencv2/cuda.hpp"
          ^~~~~~~~~~~~~~~~~~
compilation terminated.
CMakeFiles/DisplayImage.dir/build.make:62: recipe for target 'CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o' failed
make[2]: *** [CMakeFiles/DisplayImage.dir/DisplayImage.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/DisplayImage.dir/all' failed
make[1]: *** [CMakeFiles/DisplayImage.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

If someone could help me find out what I am missing I would be very grateful. I run in: - Ubuntu 18.04 - Opencv 4.3.0 - CUDA 10.0

Thank you