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".
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.
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 Files\NVIDIA GPU Computing Toolkit\CUDA\v4.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:\opencv\samples\gpu to work. 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.
C:\opencv\build\x86\...
are without GPU support.
You have to use the binaries and lib files which are present in the build\gpu
folder.
C:\opencv\build\gpu\x86\...
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.
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:
My Computer
Environment Variables
sectionPath
C:\OpenCV\build\gpu\x86\vc10\bin
and C:\OpenCV\build\x86\vc10\bin
to the Path. Don't forget to separate different values with semicolon. Also---> GPU Comes First.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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With