执行这段代码时:
#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。
最佳答案
该错误几乎可以告诉您发生了什么。您已经安装了未使用 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这解释了所有这些标志和更多内容。
然后在执行 make 之前检查 cmake 的输出,并确保它找到安装在您机器上的合适的 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(或更新版本)。
关于c++ - 在 C++ 中支持 cuda 的错误 opencv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14486533/