简体   繁体   English

OpenCV 2.4.3rc和CUDA 4.2:“OpenCV错误:没有GPU支持”

[英]OpenCV 2.4.3rc and CUDA 4.2: “OpenCV Error: No GPU support”

I have uploaded several screenshots in this album: http://imgur.com/a/w4jHc 我在这张专辑中上传了几个截图: http//imgur.com/a/w4jHc

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. 我正在尝试在Visual Studio 2008中启动并运行OpenCV中的GPU。我正在运行其中一个OpenCV GPU示例代码bgfg_segm.cpp。 However, when I compile (with no compile errors) it throws an "OpenCV Error: No GPU suport". 但是,当我编译(没有编译错误)时,它会抛出“OpenCV错误:没有GPU支持”。

  • Windows 7, 32-bit Windows 7,32位
  • Visual Studio 2008 Visual Studio 2008
  • nVidia Quadro 1000M with driver version 301.27 nVidia Quadro 1000M,驱动程序版本为301.27
  • OpenCV 2.4.3rc (using the precompiled libs that came with it) OpenCV 2.4.3rc(使用随附的预编译库)
  • CUDA Toolkit 4.2, CUDA SDK. CUDA Toolkit 4.2,CUDA SDK。

I can run the .exe files in C:\\ProgramData\\NVIDIA Corporation\\NVIDIA GPU Computing SDK 4.2\\C\\bin\\win32\\Release without any errors, so it would seem that CUDA is working. 我可以在C:\\ ProgramData \\ NVIDIA Corporation \\ NVIDIA GPU Computing SDK 4.2 \\ C \\ bin \\ win32 \\ Release中运行.exe文件,没有任何错误,所以看起来CUDA正在工作。

I really hope you can help because I feel I must be missing something obvious here. 我真的希望你可以提供帮助,因为我觉得我必须在这里遗漏一些明显的东西。 Any thoughts or suggestions are highly appreciated. 任何想法或建议都非常感谢。

EDIT November 9th 2012: 编辑2012年11月9日:

I ended up following sgar91's instructions and it seems like things are working now! 我最终遵循了sgar91的指示,现在看来事情正在发挥作用!

One sidenote: When you enter Environment Variables check out the paths for CUDA. 一旁注意:当您进入Environment Variables请查看CUDA的路径。 One of mine had one backslash ( \\ ) too many before bin like this C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v4.2\\\\bin; 我的其中一个在bin之前有一个反斜杠( \\ )太多,比如C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v4.2\\\\bin; . There are three references to CUDA and its SDK, so check them out. 有三个对CUDA及其SDK的引用,请查看它们。 Maybe it was just a one-time fluke. 也许这只是一次性的侥幸。 I am not sure this matters at all. 我不确定这是否重要。

One more sidenote: I installed Visual Studio 2010 Express, and note that sgar91's instructions are meant for Visual Studio 2010 (aka "vc10"). 还有一个旁注:我安装了Visual Studio 2010 Express,并注意到sgar91的说明适用于Visual Studio 2010(又名“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). 它不适用于Visual Studio 2008(又名“vc9”)或Visual Studio 2012(又名“vc11”),因为没有预先构建的lib文件,其中包含OpenCV 2.4.3 for vc9和vc11(仅限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. 此外,请注意,如果您使用的是64位Windows,则应按照其指南更改所有X86路径(32位)到X64(64位),而在Visual Studio中,您需要从Win32更改解决方案平台(调试或发布旁边的顶部,中间的下拉菜单)到x64。

Yet one more sidenote: OpenCV 2.4.3 supports CUDA 4.2 (or rather the libs have been compiled with CUDA 4.2). 还有一个旁注: OpenCV 2.4.3支持CUDA 4.2(或者更确切地说,libs已经用CUDA 4.2编译)。 If you install CUDA 5.0 it will not work. 如果您安装CUDA 5.0,它将无法正常工作。 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. 如果您绝对需要CUDA 5.0,则必须等待OpenCV将其包含在将来的版本中,或者通过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;

    }

I can't get any of the code in C:\\opencv\\samples\\gpu to work. 我无法获得C:\\ opencv \\ samples \\ gpu中的任何代码。 It compiles, but then throws an error. 它编译,但然后抛出一个错误。 But screw it, I'll figure that out somehow :) 但搞砸了,我会以某种方式弄清楚:)

You are using those OpenCV binaries which are compiled without GPU support. 您正在使用那些在没有GPU支持的情况下编译的OpenCV二进制文件。

C:\\opencv\\build\\x86\\... are without GPU support. C:\\opencv\\build\\x86\\...没有GPU支持。

You have to use the binaries and lib files which are present in the build\\gpu folder. 您必须使用build\\gpu文件夹中存在的二进制文件和lib文件。

C:\\opencv\\build\\gpu\\x86\\... are with GPU support. C:\\opencv\\build\\gpu\\x86\\...支持GPU。

UPDATE: 更新:

Procedure: 程序:

In Visual Studio 2010, go to project properties. 在Visual Studio 2010中,转到项目属性。 In the VC++ Directories, you will see the following page: 在VC ++目录中,您将看到以下页面:

Add the path of OpenCV include folder in the Include Directories textbox. 在“ 包含目录”文本框中添加OpenCV include文件夹的路径。 Make sure that multiple paths are separated by a semicolon and there is no space in any of the path. 确保多个路径以分号分隔,并且任何路径中都没有空格。

Similarly add the path of OpenCV lib folders for both the GPU and Non-GPU versions in the Library Directories Textbox. 同样,在Library Directories Textbox中为GPU和非GPU版本添加OpenCV lib文件夹的路径。 (Don't forget the semicolon) (别忘了用分号)

Important: When writing the paths in the box, first write the GPU path and after that, the Non-GPU path. 重要提示:在框中写入路径时,首先写入GPU路径,然后写入非GPU路径。

在此输入图像描述

Next step is adding the path of bin folder of OpenCV. 下一步是添加OpenCV的bin文件夹的路径。 But not in visual studio, but in the Path Environment variable as shown below: 但不是在visual studio中,而是在Path Environment变量中如下所示:

在此输入图像描述

  • Right Click My Computer 右键单击My Computer
  • Go To Properties 转到属性
  • Go to Environment Variables section 转到“ Environment Variables部分
  • Edit the System Variable Path 编辑系统变量Path
  • Append C:\\OpenCV\\build\\gpu\\x86\\vc10\\bin and C:\\OpenCV\\build\\x86\\vc10\\bin to the Path. C:\\OpenCV\\build\\gpu\\x86\\vc10\\bin C:\\OpenCV\\build\\x86\\vc10\\bin附加到路径。 Don't forget to separate different values with semicolon. 不要忘记用分号分隔不同的值。 Also---> GPU Comes First . 另外---> GPU首先出现
  • Save and exit. 保存并退出。

Restart Visual Studio. 重新启动Visual Studio。 The linker and #include directive will now recognize the OpenCV libraries. 链接器和#include指令现在将识别OpenCV库。 As we have added the path of the GPU libraries also, so complete GPU support will be available in OpenCV. 由于我们还添加了GPU库的路径,因此OpenCV中将提供完整的GPU支持。

To use GPU functionality of OpenCV, you just have to do the following: 要使用OpenCV的GPU功能,您只需执行以下操作:

  • #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. 指定opencv_gpu243d.lib的调试配置,或opencv_gpu243.lib在附加依赖领域发布配置Linker->Input项目属性的部分。

Some Additional Info: 一些附加信息:

In Visual Studio, there is an easy way to link libraries instead of specifying them in the project properties. 在Visual Studio中,有一种简单的方法可以链接库,而不是在项目属性中指定它们。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM