Chito Webster
Chito Webster

Reputation: 83

error opencv with cuda support in c++

when executing this code:

#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/gpu/gpu.hpp"

int main (int argc, char* argv[]){
try
{

    cv::Mat src_host = cv::imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
    cv::gpu::GpuMat dst, src;
    src.upload(src_host);

    cv::gpu::threshold(src, dst, 128.0, 255.0, CV_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;

}

compiles fine ... but I run and I get the following error:

OpenCV Error: Unknown error code -216 (The library is compiled without CUDA support) in copy, file /home/cbib/Descargas/OpenCV-2.4.3/modules/core/src/gpumat.cpp, line 736

I have installed opencv cuda and as shown in all sides.

my OS is Ubuntu Server 10.04.

Upvotes: 2

Views: 2864

Answers (1)

karlphillip
karlphillip

Reputation: 93410

The error pretty much tells you what's going on. You've installed an OpenCV version that wasn't compiled with CUDA support.

Download OpenCV 2.4.3 source code and compile it yourself. Remember to pass the following flag on the cmd-line to cmake:

-D WITH_CUDA=YES -D CUDA_TOOLKIT_ROOT_DIR="/path/to/cuda/toolkit"

OpenCV has a page that explains all these flags and more.

Then check cmake's output before executing make and make sure it found a suitable CUDA version installed on your machine. The output will show something like:

--   Other third-party libraries:
--     Use IPP:                     NO
--     Use TBB:                     NO
--     Use Cuda:                    YES
--     Use OpenCL:                  NO
--     Use Eigen:                   YES (ver 3.1.2)

And in case of failure you would see:

-- Could NOT find CUDA: Found unsuitable version "4.0", but required is at least "4.1" (found /usr/local/cuda)

You need to download and install CUDA Toolkit 4.1 (or newer).

Upvotes: 1

Related Questions