2013-01-23 93 views
1

执行此代码时:错误的OpenCV

#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; 

}

编译罚款...但我跑,我得到以下错误:

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 

我已经安装了opencv cuda,如图所示。

我的操作系统是Ubuntu Server 10.04。

回答

1

该错误几乎告诉你发生了什么事。您已经安装了未与CUDA支持一起编译的OpenCV版本。

下载OpenCV 2.4.3源代码并自行编译。请记住,在CMD线以下标志传递给cmake的

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

OpenCV has a page解释所有这些标志等等。

然后检查cmake的输出,然后执行make并确保它找到了适合你的机器安装的CUDA版本。输出将显示类似:

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

并在发生故障的情况下,你会看到:

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

您需要下载并安装CUDA Toolkit 4.1(或更新版本)。

+0

这似乎: 其他第三方库: - 使用IPP:NO - 使用TBB:YES(见2.2接口,4001) - 使用的OpenCL:NO - 使用艾根:YES(见2.0.12) 并下载OpenCV 2.4.3:s –

+0

@ChitoWebster您是否在系统上安装了cuda? –

+0

是... Cuda汇编工具,版本4.2,V0.2.1221 –