我正在尝试学习如何在OpenCV中使用图形处理器程序。我已经用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
发布于 2015-09-08 15:16:56
好吧,我真的不知道问题是什么,但是在CMake中,我把CUDA_GENERATION改成了开普勒,这是我的图形处理器的微架构,然后我重新编译了它,现在代码可以正常工作了。
有趣的是,只有费米和开普勒可供选择,所以我不知道麦克斯韦是否会有问题。
/ Erik
https://stackoverflow.com/questions/32442287
复制相似问题