Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
522 views
in Technique[技术] by (71.8m points)

visual studio 2008 - 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

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-bit
  • Visual Studio 2008
  • nVidia Quadro 1000M with driver version 301.27
  • OpenCV 2.4.3rc (using the precompiled libs that came with it)
  • CUDA Toolkit 4.2, CUDA SDK.

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.

EDIT November 9th 2012:

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

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.

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.

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;

    }

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 :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

C:opencvuildx86... are without GPU support.

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

C:opencvuildgpux86... are with GPU support.

UPDATE:

Procedure:

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

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.

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)

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

enter image description here

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:

enter image description here

  • 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.

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.

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

  • #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.

Some Additional Info:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...