2013-01-23 96 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 –