OpenCV 2.4.3rc 和 CUDA 4.2:“OpenCV 错误:不支持 GPU" [英] OpenCV 2.4.3rc and CUDA 4.2: "OpenCV Error: No GPU support"

查看:54
本文介绍了OpenCV 2.4.3rc 和 CUDA 4.2:“OpenCV 错误:不支持 GPU"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个相册上传了几张截图:http://imgur.com/a/w4jHc

I have uploaded several screenshots in this album: http://imgur.com/a/w4jHc

我正在尝试在 Visual Studio 2008 的 OpenCV 中启动并运行 GPU.我正在运行 OpenCV GPU 示例代码之一,bgfg_segm.cpp.但是,当我编译(没有编译错误)时,它会抛出OpenCV 错误:无 GPU 支持".

I am trying to get GPU up and running in OpenCV in Visual Studio 2008. I am running one of the OpenCV GPU example codes, bgfg_segm.cpp. However, when I compile (with no compile errors) it throws an "OpenCV Error: No GPU suport".

  • Windows 7,32 位
  • Visual Studio 2008
  • nVidia Quadro 1000M,驱动程序版本为 301.27
  • OpenCV 2.4.3rc(使用随附的预编译库)
  • CUDA 工具包 4.2,CUDA SDK.

我可以在 C:ProgramDataNVIDIA CorporationNVIDIA GPU Computing SDK 4.2Cinwin32Release 中运行 .exe 文件而没有任何错误,所以看起来 CUDA 正在运行.

I can run the .exe files in C:ProgramDataNVIDIA CorporationNVIDIA GPU Computing SDK 4.2Cinwin32Release without any errors, so it would seem that CUDA is working.

我真的希望你能帮忙,因为我觉得我在这里一定遗漏了一些明显的东西.任何想法或建议都非常感谢.

I really hope you can help because I feel I must be missing something obvious here. Any thoughts or suggestions are highly appreciated.

编辑 2012 年 11 月 9 日:

我最终遵循了 sgar91 的指示,现在似乎一切正常!

I ended up following sgar91's instructions and it seems like things are working now!

旁注:当您输入 Environment Variables 时,请检查 CUDA 的路径.我的一个在 bin 之前有一个反斜杠()太多了,就像这样 C:Program FilesNVIDIA GPU Computing ToolkitCUDAv4.2\bin;.有 3 个对 CUDA 及其 SDK 的引用,因此请查看它们.也许这只是一次侥幸.我不确定这是否重要.

One sidenote: When you enter Environment Variables check out the paths for CUDA. One of mine had one backslash () too many before bin like this C:Program FilesNVIDIA GPU Computing ToolkitCUDAv4.2\bin;. There are three references to CUDA and its SDK, so check them out. Maybe it was just a one-time fluke. I am not sure this matters at all.

另一个旁注:我安装了 Visual Studio 2010 Express,请注意 sgar91 的说明适用于 Visual Studio 2010(又名vc10").它在 Visual Studio 2008(又名vc9")或 Visual Studio 2012(又名vc11")中不起作用,因为没有用于 vc9 和 vc11(仅 vc10)的 OpenCV 2.4.3 的预构建 lib 文件.另外,请注意,如果您使用的是 64 位 Windows,则应该按照他的指南将所有 X86 路径(32 位)更改为 X64(64 位),并且在 Visual Studio 中,您需要将解决方案平台从 Win32 更改为(顶部的下拉菜单,中间在调试或发布旁边)到 x64.

One more sidenote: I installed Visual Studio 2010 Express, and note that sgar91's instructions are meant for Visual Studio 2010 (aka "vc10"). It will not work in Visual Studio 2008 (aka "vc9") or Visual Studio 2012 (aka "vc11"), because there are no prebuilt lib files with OpenCV 2.4.3 for vc9 and vc11 (only vc10). Also, be aware if you are on 64-bit Windows you should change all X86 paths (32-bit) to X64 (64-bit) instead when you follow his guide, and in Visual Studio you need to change the Solution Platform from Win32 (dropdown menu in the top, middle next to Debug or Release) to x64.

还有一个旁注: OpenCV 2.4.3 支持 CUDA 4.2(或者更确切地说,库是用 CUDA 4.2 编译的).如果您安装 CUDA 5.0,它将无法工作.它会抛出错误消息.想不起来哪个了.如果您绝对需要 CUDA 5.0,则必须等待 OpenCV 将其包含在未来版本中,或者通过 CMake 编译您自己的库.

Yet one more sidenote: OpenCV 2.4.3 supports CUDA 4.2 (or rather the libs have been compiled with CUDA 4.2). If you install CUDA 5.0 it will not work. It throws an error message. Can't recall which. If you absolutely need CUDA 5.0 you have to either wait for OpenCV to include it in future versions or compile your own libs via CMake.

我运行了下面的代码(它来自这里,但我不得不更正一个行使其编译)并编译并显示图像,所以我希望这意味着一切正常?

I ran the code below (it's from here, but I had to correct one line in it to make it compile) and it compiled and showed the image, so I would expect that this means things are working?

#ifdef _DEBUG
#pragma comment(lib,"opencv_gpu243d")
#pragma comment(lib,"opencv_core243d")
#pragma comment(lib,"opencv_highgui243d")
#else
#pragma comment(lib,"opencv_core243")
#pragma comment(lib,"opencv_highgui243")
#pragma comment(lib,"opencv_gpu243")
#endif

    #include <iostream>
    #include "opencv2/opencv.hpp"
    #include "opencv2/gpu/gpu.hpp"

    int main (int argc, char* argv[])
    {
        try
        {
            cv::Mat src_host = cv::imread("file.png", 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);
            //cv::Mat result_host = dst;         //old line commented out
            cv::imshow("Result", result_host);   //new line added by me
            cv::waitKey();
        }
        catch(const cv::Exception& ex)
        {
            std::cout << "Error: " << ex.what() << std::endl;
        }
        return 0;

    }

我无法让 C:opencvsamplesgpu 中的任何代码工作.它编译,但随后抛出错误.但是搞砸了,我会以某种方式解决这个问题:)

I can't get any of the code in C:opencvsamplesgpu to work. It compiles, but then throws an error. But screw it, I'll figure that out somehow :)

推荐答案

您正在使用那些在没有 GPU 支持的情况下编译的 OpenCV 二进制文件.

You are using those OpenCV binaries which are compiled without GPU support.

C:opencvuildx86... 不支持 GPU.

您必须使用 buildgpu 文件夹中的二进制文件和 lib 文件.

You have to use the binaries and lib files which are present in the buildgpu folder.

C:opencvuildgpux86... 支持 GPU.

更新:

程序:

在 Visual Studio 2010 中,转到项目属性.在 VC++ 目录中,您将看到以下页面:

In Visual Studio 2010, go to project properties. In the VC++ Directories, you will see the following page:

包含目录文本框中添加OpenCVinclude文件夹的路径.确保多个路径之间用分号分隔,并且任何路径中都没有空格.

Add the path of OpenCV include folder in the Include Directories textbox. Make sure that multiple paths are separated by a semicolon and there is no space in any of the path.

同样在库目录文本框中为GPU和非GPU版本添加OpenCVlib文件夹的路径.(不要忘记分号)

Similarly add the path of OpenCV lib folders for both the GPU and Non-GPU versions in the Library Directories Textbox. (Don't forget the semicolon)

重要提示:在框中写入路径时,先写入 GPU 路径,然后再写入非 GPU 路径.

Important: When writing the paths in the box, first write the GPU path and after that, the Non-GPU path.

下一步是添加OpenCV的bin文件夹的路径.但不是在visual studio中,而是在Path环境变量中,如下图:

Next step is adding the path of bin folder of OpenCV. But not in visual studio, but in the Path Environment variable as shown below:

  • 右键单击我的电脑
  • 转到属性
  • 转到环境变量部分
  • 编辑系统变量Path
  • 附加C:OpenCVuildgpux86vc10in C:OpenCVuildx86vc10in 到路径.不要忘记用分号分隔不同的值.还有---> GPU 优先.
  • 保存并退出.
  • Right Click My Computer
  • Go To Properties
  • Go to Environment Variables section
  • Edit the System Variable Path
  • Append C:OpenCVuildgpux86vc10in and C:OpenCVuildx86vc10in to the Path. Don't forget to separate different values with semicolon. Also---> GPU Comes First.
  • Save and exit.

重新启动 Visual Studio.链接器和 #include 指令现在将识别 OpenCV 库.由于我们也添加了 GPU 库的路径,所以 OpenCV 中将提供完整的 GPU 支持.

Restart Visual Studio. The linker and #include directive will now recognize the OpenCV libraries. As we have added the path of the GPU libraries also, so complete GPU support will be available in OpenCV.

要使用 OpenCV 的 GPU 功能,您只需执行以下操作:

To use GPU functionality of OpenCV, you just have to do the following:

  • #include opencv2/gpu/gpu.hpp
  • Linker->Inputopencv_gpu243d.lib,或为发布配置指定opencv_gpu243.lib> 项目属性部分.
  • #include opencv2/gpu/gpu.hpp
  • Specify opencv_gpu243d.lib for Debug Configuration, or opencv_gpu243.lib for Release Configuration in the Additional Dependencies field in the Linker->Input section of project properties.

一些附加信息:

在 Visual Studio 中,有一种简单的方法可以链接库,而不是在项目属性中指定它们.

In Visual Studio, there is an easy way to link libraries instead of specifying them in the project properties.

只需在代码的开头写下这些行:

Just write these lines in the very start of your code:

#ifdef _DEBUG
#pragma comment(lib,"opencv_core243d")
#pragma comment(lib,"opencv_highgui243d")
#else
#pragma comment(lib,"opencv_core243")
#pragma comment(lib,"opencv_highgui243")
#endif

这篇关于OpenCV 2.4.3rc 和 CUDA 4.2:“OpenCV 错误:不支持 GPU"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆