Reputation: 2617
I have built opencv with cuda support using visual studio 2010 on win7 x64. To run a simple opencv cuda program I wrote this code and placed output released exe file to opencv\built\install\x64\vc10\bin
near all lib and dll files.
But when I run the exe file it produce error No CUDA support (The library is compiled without CUDA support)
Here is my code:
#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>
#include <chrono>
#include <ctime>
#include <opencv2/core/cuda.hpp>
using namespace cv;
using namespace cv::cuda;
using namespace std;
string source_image_addr, gray_image_addr="", source_image_name="";
int convert2gray()
{
Mat image;
GpuMat d_image, d_gray_image;
image = imread((char *)source_image_addr.c_str(), IMREAD_COLOR);
if(image.empty())
{
cout<<"Could not open or find the image"<<std::endl;
return -1;
}
CV_Assert(image.depth() != sizeof(unsigned char));
std::chrono::time_point<chrono::system_clock> start, end;
start = chrono::system_clock::now();
d_image.upload(image);
cuda::cvtColor(d_image, d_gray_image, CV_RGB2GRAY);
Mat gray_image(d_gray_image);
end = chrono::system_clock::now();
chrono::duration<double> elapsed = end - start;
cout<<"for image["<<image.cols<<"*"<<image.rows<<"] elapsed = "<<elapsed.count()<<endl;
//namedWindow("Gray Window", WINDOW_AUTOSIZE);
//imshow("Gray Window", gray_image);
imwrite((char *)gray_image_addr.c_str(), gray_image);
}
int main(int argc, char** argv)
{
if(argc >= 2)
{
source_image_addr = argv[1];
source_image_name = source_image_addr.substr(0, source_image_addr.find_last_of("."));
if(argc >= 3)
gray_image_addr = argv[2];
else
gray_image_addr = source_image_name + "-gray.jpg";
if(!convert2gray())
return -1;
}
else
{
cout<<"Usage: convert2gray ImageAddress [gray_image_addr]"<<endl;
return -1;
}
//waitKey(0);
return 0;
}
I have placed opencv_world300.dll
in the same folder.
Edit:
Here is outout for std::cout << cv::getBuildInformation() << std::endl;
:
videoio: Removing WinRT API headers by default
General configuration for OpenCV 3.0.0 =====================================
Version control: 3.0.0
Platform:
Host: Windows 6.1 AMD64
CMake: 2.8.11.2
CMake generator: Visual Studio 11 Win64
CMake build tool: C:/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe
MSVC: 1700
C/C++:
Built as dynamic libs?: YES
C++ Compiler: C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/bin/x86_amd64/cl.exe (ver 17.0.50727.1)
C++ flags (Release): /DWIN32 /D_WINDOWS /W4 /GR /EHa /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /wd4251 /wd4324 /MP8 /MD /O2 /Ob2 /D NDEBUG /Zi
C++ flags (Debug): /DWIN32 /D_WINDOWS /W4 /GR /EHa /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /wd4251 /wd4324 /MP8 /D_DEBUG /MDd /Zi /Ob0 /Od /RTC1
C Compiler: C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/bin/x86_amd64/cl.exe
C flags (Release): /DWIN32 /D_WINDOWS /W3 /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /MP8 /MD /O2 /Ob2 /D NDEBUG /Zi
C flags (Debug): /DWIN32 /D_WINDOWS /W3 /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /MP8 /D_DEBUG /MDd /Zi /Ob0 /Od /RTC1
Linker flags (Release): /machine:x64 /INCREMENTAL:NO /debug
Linker flags (Debug): /machine:x64 /debug /INCREMENTAL
Precompiled headers: YES
Extra dependencies:
3rdparty dependencies: ippicv
OpenCV modules:
To be built: hal core flann imgproc ml photo video imgcodecs shape videoio highgui objdetect superres ts features2d calib3d stitching videostab world
Disabled: -
Disabled by dependency: -
Unavailable: cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev java python2 viz
Windows RT support: NO
GUI:
QT: NO
Win32 UI: YES
OpenGL support: NO
VTK support: NO
Media I/O:
ZLib: build (ver 1.2.8)
JPEG: build (ver 90)
WEBP: build (ver 0.3.1)
PNG: build (ver 1.5.12)
TIFF: build (ver 42 - 4.0.2)
JPEG 2000: build (ver 1.900.1)
OpenEXR: build (ver 1.7.1)
GDAL: NO
Video I/O:
Video for Windows: YES
DC1394 1.x: NO
DC1394 2.x: NO
FFMPEG: YES (prebuilt binaries)
codec: YES (ver 55.18.102)
format: YES (ver 55.12.100)
util: YES (ver 52.38.100)
swscale: YES (ver 2.3.100)
resample: NO
gentoo-style: YES
OpenNI: NO
OpenNI PrimeSensor Modules: NO
OpenNI2: NO
PvAPI: NO
GigEVisionSDK: NO
DirectShow: YES
Media Foundation: NO
XIMEA: NO
Intel PerC: NO
Other third-party libraries:
Use IPP: 8.2.1 [8.2.1]
at: C:/buildslave64/win64_amdocl/master_PackSlave-win64-vc11-shared/opencv/3rdparty/ippicv/unpack/ippicv_win
Use IPP Async: NO
Use Eigen: NO
Use TBB: NO
Use OpenMP: NO
Use GCD NO
Use Concurrency YES
Use C=: NO
Use pthreads for parallel for:
NO
Use Cuda: NO
Use OpenCL: YES
OpenCL:
Version: dynamic
Include path: C:/buildslave64/win64_amdocl/master_PackSlave-win64-vc11-shared/opencv/3rdparty/include/opencl/1.2 C:/Program Files (x86)/AMD/clAmdFft/include C:/Program Files (x86)/AMD/clAmdBlas/include
Use AMDFFT: YES
Use AMDBLAS: YES
Python 2:
Interpreter: c:/python27_x64/python.exe (ver 2.7.5)
Python 3:
Interpreter: NO
Python (for build): c:/python27_x64/python.exe
Java:
ant: C:/Program Files (x86)/apache-ant/bin/ant.bat (ver 1.9.2)
JNI: C:/Program Files/Java/jdk1.6.0_45/include C:/Program Files/Java/jdk1.6.0_45/include/win32 C:/Program Files/Java/jdk1.6.0_45/include
Java wrappers: NO
Java tests: NO
Matlab:
mex: NO
Tests and samples:
Tests: NO
Performance tests: NO
C/C++ Examples: NO
Install path: C:/buildslave64/win64_amdocl/master_PackSlave-win64-vc11-shared/build/install
cvconfig.h is in: C:/buildslave64/win64_amdocl/master_PackSlave-win64-vc11-shared/build/opencv_build
-----------------------------------------------------------------
Could not open or find the image
Upvotes: 0
Views: 3244
Reputation: 20160
OpenCV precomputed binaries are compiled without cuda/GPU support (that's what the error message tells you, too => openCV isn't COMPILED with cuda support).
You have to compile your own OpenCV (it is done quite easily with CMake) to get cuda support (activate WITH_CUDA=ON
and set the cuda toolkit directory path)!
You might have to take care of different cuda platforms, too: http://docs.opencv.org/modules/gpu/doc/introduction.html
with std::cout << cv::getBuildInformation() << std::endl;
you can print your OpenCV build settings during runtime if you aren't certain about how your libraries were compiled.
Upvotes: 2