Ask Your Question

opencv4.2.0 cuda.hpp

asked 2020-01-13 23:45:51 -0500

efe gravatar image

Hi, I am trying to compile a simple C++ program that I found on the internet, but I am not sure if it is supported by opencv4.2.0 or not, because I couldn't find cuda.hpp in /usr/local/include/opencv4/opencv2. When I comment out the #include "opencv2/cuda.hpp" part, the code seems to work. Here is the code below:

#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[])
    cv::Mat src_host = cv::imread("image.png", IMREAD_GRAYSCALE);
    cv::cuda::GpuMat dst, src;
    cv::cuda::threshold(src, dst, 128.0, 255.0, THRESH_BINARY);
    cv::Mat result_host;;
    cv::imshow("Result", result_host);
catch(const cv::Exception& ex)
    std::cout << "Error: " << ex.what() << std::endl;
return 0;

Does opencv4.2.0 comes with cuda.hpp or is it enough to use cudaarithm.hpp

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2020-01-14 03:11:36 -0500

The OpenCV pre-built binaries are not built with CUDA and do not include the CUDA modules (anything in the cv::cuda namespace).

To use compile the code you found on the internet you will have to build OpenCV 4.2.0 with CUDA yourself first.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2020-01-13 23:45:16 -0500

Seen: 78 times

Last updated: Jan 14