Latest version of Cuda development Pack download: Click to open link
This article is based on vs2012,pc win7 x64,opencv2.4.9
compiling OPENCV source code
Refer to "How to Build OpenCV 2.2 with GPU" on Windows 7, which is a bit cumbersome, you can see the following
1, installation Cuda Toolkit, official instructions: Click to open the link
Installation process is like ordinary software, the last hint that some modules are not installed successfully, we do not care, as long as the toolkit installed on the line. The above link said to install the SDK, NPP, or something, probably because the old version of Cuda, now 6.0 are integrated in the installation package, once done.
2, CMake compiled OpenCV
Note Three places, indispensable:
(1) Cuda path, as shown in the figure
After the 1th step is installed, CMake will automatically look for it without our setting. If cuda_toolkit_root_dir_nofounded, please go back to the 1th step.
(2) With_cuda, the default is selected.
(3) WITH_TBB, the default is not selected, remember to tick on. TBB needs to be installed on its own, refer to http://www.cnblogs.com/freedomshe/archive/2013/01/11/win7_vs2012_opencv_rebuild.html
Finally, create a. sln 3, vs compile install
VS opens the sln that was just generated, finds the install item, and right-creates it, starts compiling. Please note that the compilation time is long and my machine E3 1250 takes nearly 2 hours, so get ready for a cup of coffee first. After compiling, get a new directory install, all include, Bin, Lib are in it. The whole project folder is about 6G a bit more, more than 2G when there is no cuda. Well, start to enjoy Cuda.
Demo
Attach a simple routine that can be used to verify the success of the Cuda platform:
#include "stdafx.h" #include "opencv2/opencv.hpp" #include "opencv2/gpu/gpu.hpp" int _tmain (int argc, _tchar* argv[]) {
int num_devices = Cv::gpu::getcudaenableddevicecount (); if (num_devices <= 0) {std::cerr<< "there is no device."
<<std::endl;
return-1;
} int enable_device_id =-1;
for (int i=0;i<num_devices;i++) {cv::gpu::D eviceinfo dev_info (i);
if (dev_info.iscompatible ()) {enable_device_id=i;
}} if (enable_device_id < 0) {std::cerr<< "GPU module isn ' t built for GPU" <<std::endl;
return-1;
} cv::gpu::setdevice (enable_device_id);
std::cout<< "GPU is ready, device ID is" <<num_devices<< "\ n";
Cv::mat src_image = cv::imread ("Your Path \\lena.jpg", 1);
Cv::mat Dst_image;
Cv::gpu::gpumat d_src_img (src_image);
Cv::gpu::gpumat d_dst_img;
Cv::gpu::cvtcolor (D_src_img,d_dst_img,cv_bgr2gray);
D_dst_img.download (Dst_image);
Cv::namedwindow ("test", 0);
Cv::imshow ("Test", dst_image);
Cv::waitkey (0);
return 0; }
It is important to note that before all functions that use the GPU module, it is advisable to call the function Gpu::getcudaenableddevicecount, if the function returns a value of 0, and you can see the "CUDA is no support" error on the command line, The description is not compiled successfully, go back to the 1th step to start
------------------------------------------------------Split Line--------------------------------------------------------------
Cuda Module for OpenCV 3.0
Source code compilation: http://blog.csdn.net/kelvin_yan/article/details/48708227
The size of the compilation is 8. Multi g
Changes relative to 2.x
* No longer use the Cv::gpu namespace, instead of Cv::cuda
* Separate reference required in header file
#include "opencv2/core.hpp"
#include "opencv2/cudaarithm.hpp"
#include "opencv2/cudafilters.hpp"
...
Calling different Cuda functions requires referencing the corresponding header files, which refer to the description of these header files: http://blog.csdn.net/kelvin_yan/article/details/48734707
* Some functions have been added and some functions have been removed, changing the usage of some functions
For example, the parameters of Gpu::add, gpu::multiply, gpu::subtract are changed, and the 2.x version is the same when using stream
For example, the invocation of the filter function also changed, first to create a CV::P tr<gpu::filter> object, as a filter, and then call the object's apply method for actual filtering, the following is a Gaussian filter example:
CV::P tr<cv::cuda::filter> gauss = Cv::cuda::creategaussianfilter (cv_32f, cv_32f, Size (one, one), 1.5, 0, Cv::border _DEFAULT,-1); Create Gaussian filter
gauss->apply (src, DST); Gaussian filter
----------END-----------