我正在尝试学习如何在OpenCV中使用GPU程序。我用CUDA构建了一切,如果我运行
cout << " Number of devices " << cv::gpu::getCudaEnabledDeviceCount() << endl;
我得到答案1设备,所以至少有些东西似乎有效。但是,我尝试下面的代码安静,它只打印出消息然后没有任何反应。它被卡在了
cv::gpu::cvtColor(input_gpu, output_gpu, CV_BGR2GRAY);
这是代码
#include<iostream>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/gpu/gpu.hpp>
#include <opencv2/opencv.hpp>
using std::cout;
using std::endl;
int main(void){
cv::Mat input = cv::imread("image.jpg");
if (input.empty()){
cout << "Image Not Found" << endl;
return -1;
}
cv::Mat output;
// Declare the input and output GpuMat
cv::gpu::GpuMat input_gpu;
cv::gpu::GpuMat output_gpu;
cout << "Number of devices: " << cv::gpu::getCudaEnabledDeviceCount() << endl;
// Copy the input cv::Mat to device.
// Device memory will be allocated automatically according to the parameters of input image
input_gpu.upload(input);
// Convert the input image to grayScale on GPU
cv::gpu::cvtColor(input_gpu, output_gpu, CV_BGR2GRAY);
//// Copy the result from GPU back to host
output_gpu.download(output);
cv::imshow("Input", input);
cv::imshow("Output", output);
cv::waitKey(0);
return 0;
}
我刚刚发现this问题,这似乎是Maxwell架构的一个问题,但该帖子已有一年多了。还有其他人遇到过同样的问题吗?我使用的是Windows 7,Visual Studio 2013和Nvidia Geforce GTX 770.
/ Erik
答案 0 :(得分:0)
好吧,我真的不知道问题是什么,但在CMake中,我将CUDA_GENERATION更改为Kepler,这是我GPU的微架构,然后我重新编译它,现在代码可以正常工作。
有趣的是,只有Fermi和Kepler可供选择,所以我不知道是否会遇到麦克斯韦的问题。
/ Erik