【问题标题】:Cant get the CUDA-module to work under OpenCV 3.0 Beta无法让 CUDA 模块在 OpenCV 3.0 Beta 下工作
【发布时间】:2015-06-20 15:39:08
【问题描述】:

对于它的生命,我无法让 CUDA 模块在 OpenCV3.0 Beta 下与 Visual Studio 2013 64Bit Professional、CUDA SDK 6.5 和 Win7 64Bit 一起工作。半年前,我使用的示例代码在 OpenCV3.0 Alpha 上完美运行。现在我什至无法让 cv::cuda::flip 工作;该代码一直有效,直到它应该将 Mat 上传到 CUDA,但随后它停止工作。

有人可以提供一个工作示例代码,这样我就可以看到我在哪里忽略了某些东西?

我之前做过的所有步骤:

在使用 CMake 和 MSVC2013 Professional 启用 CUDA 和 OpenGL 构建 OpenCV3.0Beta 后,我在 Debug and Release /X64 Config 中构建了 OpenCV.sln(表示成功构建:每个 266)。之后,我分别在 modules/smaples/include 和 data-folder 的 Debug/Release X64-Config 中构建了 INSTALL.vcxproj,因此它们都被复制到了 install-folder。

在属性 C++ 常规下:

D:\OpenCV\GebautmitCUDAohneTBB\install\include D:\Programme\glew-1.12.0\include D:\Programme\freeglut\include

在属性链接器常规下:

D:\OpenCV\GebautmitCUDAohneTBB\install\x64\vc12\lib D:\Programme\glew-1.12.0\lib\Release\x64 D:\Programme\freeglut\lib\x64

在属性链接器输入下:

通常的 OpenCV 库, glew32.lib, freeglut.lib

这是我的示例代码:

#if defined _MSC_VER && _MSC_VER >= 1400
#pragma warning(disable : 4100)
#endif

#include <iostream>
#include <iomanip>
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/cuda.hpp"
#include "opencv2/cudaimgproc.hpp"
#include "opencv2/cudawarping.hpp"

using namespace std;
using namespace cv;
using namespace cv::cuda;

int main() {
/*
if (getCudaEnabledDeviceCount() == 0)
{
return cerr << "No GPU found or the library is compiled without CUDA  support" << endl, -1;
}

cv::cuda::printShortCudaDeviceInfo(cv::cuda::getDevice());
*/
Mat image, image2, imagedownloaded, demoimage, grayimage;

image = imread("fruits.jpg", 1);

if (image.channels() == 1)
{
    cout << "1 channel";
}
else
{
    cout << "3 channel";
}

cv::cvtColor(image, image, COLOR_BGR2GRAY);

GpuMat image_gpu, gray_gpu, demo_gpu, image_gpu2;

image_gpu2.upload(image);

cv::cuda::demosaicing(image_gpu2, demo_gpu, COLOR_BayerGR2BGR, 3);

demo_gpu.download(demoimage);

if (demoimage.channels() == 1)
{
    cout << "1 channel";
}
else
{
    cout << "3 channel";
}

imshow("bla2", image);
imshow("bla3", demoimage);
waitKey();
return 0;

}

谁能指出我忘记了什么,所以它会再次起作用?

谢谢。

【问题讨论】:

    标签: c++ opencv visual-studio-2012


    【解决方案1】:

    我找到了解决问题的方法: 我发现我的代码和 opencv-gpu-samples 大约 1 分钟都不能工作,但在那之后它工作得完美无缺。所以我在谷歌上搜索了这个问题并发现,这一定是CUDA显然需要在运行时再次编译代码才能让他们的Cubin/PTX文件在gpu上正常工作(我对它的理解)。

    所以我查看了我的 CMake-Configuration(来自 Opencv/Source 的标准配置),它只是使用 Arch-Bins 1.0 - 3.0 构建 OpenCV-CUDA-Config,而我有一个 GTX970,它的计算能力为 5.2。

    在将 CMake-CUDA-Arch-Bin 和 PTX-Setting 更改为 5.0 并再次使用 CUDA 和 OpenGL 构建 OpenCV 后,CUDA 运行良好并以预期的速度运行 :) 此外,使用 CUDA 构建 OpenCV 的时间从 2 小时大幅缩短到 25 分钟(因为只有一个 Arch-Bin/PTX-Build-Setting)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 2018-08-03
      • 2017-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多