opencv python gpu加速_OpenCV中配置CUDA,实现GPU加速

1、 查看本机配置,查看显卡类型是否支持NVIDIA GPU,本机显卡为NVIDIA GeForce  GT630;

3、 从https://developer.nvidia.com/cuda-toolkit根据本机类型下载相应最新版的CUDA Toolkit6.0 64位,安装,并通过样本程序验证其安装正确;

4、 将C:\ProgramFiles\NVIDIAGPU Computing Toolkit\CUDA\v6.0\bin添加到环境变量中(检查是否已经默认添加);

5、 从http://threadingbuildingblocks.org/下载最新版的TBB4.2,解压缩,并将其bin目录D:\soft\OpenCV2.4.8\TBB\tbb41_20140122oss\bin\ia64\vc10添加到环境变量中,注销或重启;

D:\soft\OpenCV2.4.8文件夹中;

8、打开CMake,在Where isthesource code:中选择D:\soft\OpenCV2.4.6\opencv文件夹,在Where to buildthe binaries:中选择D:/soft/OpenCV2.4.6/vs2010_GPU文件夹,此文件夹为手动创建;

9、点击Configure按钮,在弹出的对话框中选择VisualStudio 10,然后点击Finish;

10、 如果有红色框出现,勾选BUILD_EXAMPLES、WITH_TBB、WITH_CUBLAS、WITH_CUDA、WITH_CUFFT,然后再次点击Configure按钮;

11、如果还有红色框出现,TBB_INCLUDE_DIRS,将其值改为D:\soft\OpenCV2.4.6\TBB\tbb41_20130613oss\include为TBB中include所在的目录,然后再次点击Configure按钮;

12、 如何还有红色框出现,TBB_LIB_DIR、TBB_STDDEF_PATH,再次点击Configure按钮;

13、如果在下方信息框中有:Use TBB: YES(ver 4.1 interface 6105),Use Cuda: YES(ver5.0),证明我们已经将inteltbb和CUDA正确配置;

14、点击Generate按钮,此时会在D:\soft\OpenCV2.4.6\vs2010_GPU文件夹下生成OpenCV.sln文件;

15、以管理员身份,使用vs2010打开OpenCV.sln文件,选择View--> Properties Manager-->分别选中ALL_BUILD中的Debug和Release上的Microsoft.Cpp.Win64.user,依次添加inteltbb和CUDA 的Executable Directories、IncludeDirectories和Library Directories,点击右键-->Properties:

(需要说明的是:opencv里面要选择build文件夹下面的路径才对)

VC++ Directories,IncludeDirectories:

D:\soft\OpenCV2.4.6\TBB\tbb41_20130613oss\include

C:\Program Files\NVIDIAGPU ComputingToolkit\CUDA\v5.0\include

D:\opencv\build\include

D:\opencv\build\include\opencv

D:\opencv\build\include\opencv2

Library Directories:

D:\soft\OpenCV2.4.6\TBB\tbb41_20130613oss\lib\ia64\vc10

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\lib\Win64

D:\opencv\build\x64\vc10\lib

Executable Directories:

D:\soft\OpenCV2.4.6\TBB\tbb41_20130613oss\bin\ia64\vc10

C:\Program Files\NVIDIA GPU ComputingToolkit\CUDA\v5.0\bin

D:\opencv\build\x64\vc10\bin

16、选中modules中的opencv_gpu,点击右键,选择Properties-->Linker-->Input-->IgnoreSpecificDefault Libraries加入libcmtlibcmtd;(可忽视这条)

17、 分别在Debug和Release下,选择SolutionExplorer里的Solution OpenCV,点击右键,运行”Rebuild Solution”。(这个过程比较漫长,win7 64位,4GB内存,大概需要3小时)

18、点击CMakeTargets下的INSTALL—右键—仅本工程build,之后会在D:\soft\OpenCV2.4.3\vs2010\install文件夹下的bin文件夹中存放相应的动态库,在lib文件夹下存放相应的静态库;

补充说明

(1)、安装CUDA Toolkit时最好不要修改其默认的安装目录;

(2)、第17步的重建过程中,如果出现了很异常诡异的行为,有一种调试方式是删除原先配置的文件夹,重新cmake,清空VS2010里面的工程,重新编译,可能会改善。

(3)、为了缩短编译时间,可以通过CMake中改变CUDA_ARCH_BIN、CUDA_ARCH_PTX值进行设置,将BUILD_EXAMPLES的勾选去掉(没有这么做,因为是为了全部编译)

(4)、在编译前最好把360安全卫士和杀毒软件关闭;

(5)、也可不用管理员身份打开OpenCV.sln,第15步的属性配置在不同的电脑上有的必须的,有的可以不需要,最好都加上,免得返工;

(6)、也可以不用修改opencv_gpu模块的属性配置,默认即可,即第16步也不是必须的;

(7)、编译过程中会弹出数次对话框,如出现宏对话框则点击Cancel选项,其它则选择Yes选项;

(8)、编译成功后的库也可以直接应用于OpenCV中的OpenCL模块。

Debug过程

编译错误解决:

1、无法加载宏: C:/Users/XXX/Documents/Visual Studio 2010Projects/VSMacros80/ Samples/ Samples.vsmacros

解决方法:

把这个附件放在上述目录里面:附件

2、错误:

CMakeFiles/example_gpu_driver_api_multi.dir/driver_api_multi.cpp.o: Infunction `destroyContexts()':

driver_api_multi.cpp:(.text._Z15destroyContextsv+0xc): undefined referenceto `cuCtxDestroy_v2'

driver_api_multi.cpp:(.text._Z15destroyContextsv+0x1c): undefinedreference to `cuCtxDestroy_v2'

CMakeFiles/example_gpu_driver_api_multi.dir/driver_api_multi.cpp.o: Infunction `Worker::operator()(int) const':

driver_api_multi.cpp:(.text._ZNK6WorkerclEi+0x19): undefined reference to`cuCtxPushCurrent_v2'

driver_api_multi.cpp:(.text._ZNK6WorkerclEi+0x6bf): undefined reference to`cuCtxPopCurrent_v2'

解决方法:

Only two example will affect by this bug,"example_gpu_driver_api_multi" and"example_gpu_driver_api_stereo_multi"

Modify line 39

target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS}${OPENCV_GPU_SAMPLES_REQUIRED_DEPS})

to

target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS}${OPENCV_GPU_SAMPLES_REQUIRED_DEPS} cuda)

in "opencv-2.4.6.1/samples/gpu/CMakeLists.txt" can easily fixthis problem

3、错误:dllmain重复定义,opencv_world246.dll不存在等错误

解决方法:cmake的时候不要勾选build_world选项,这个重建也不是必须的

4、错误37374error LNK1104:无法打开文件“..\..\lib\Debug\opencv_superres248d.lib”D:\opencv\opencv248GPU\modules\superres\LINKopencv_test_superres

分析:是链接库链接不上造成的,添上这些库就可以了。

解决办法:第15步中务必把opencv的include\bin\lib目标都加进去,而且是build目录下的,如果还有问题,那么重新cmake,或者清除VS2010的缓存就可以了。

5、错误

Unable to cast COM object of type'System.__ComObject' to interface type 'EnvDTE.DTE'.

解决办法:可能是这个或者可以放在这里不解决,继续编译可以没有问题

The exception seems to indicate the crashwas caused due to an interface not being found.  This indicates thatsomething's wrong with proxy/stubs on the machine.

At leastIServiceProvider is failing. IE is usually the owner of the IServiceProviderproxy.

From the dump, it showed devenv.exe process crashed shortly afterloading:  C:\Windows\SysWOW64\actxprxy.dll andC:\Windows\System32\mssprxy.dll

The issue turned out to be brokenregistration for IServiceProvider. The proxy-stub CLSID was wrong (it wasreferring to actxprxy.dll instead of ieproxy.dll on Windows

7 x64). Registeringieproxy.dll from an elevated cmd prompt resolved the issue.  regsvr32 "C:\Program Files (x86)\Internet Explorer\ieproxy.dll"

On x86 systems,  regsvr32"C:\Program Files\Internet Explorer\ieproxy.dll"

新编译的opencv使用方法

1、打开vs2010,新建一个控制台应用程序,为vs2010配置OpenCV环境:选择View-->Properties Manager-->分别选中Debug和Release上的Microsoft.Cpp.Win64.user,点击右键-->Properties:VC++ Directories,Include Directories:D:\Soft\OpenCV2.4.6\vs2010_GPU\install\include;D:\Soft\OpenCV2.4.6\vs2010_GPU\install\include\opencv;D:\Soft\OpenCV2.4.6\vs2010_GPU\install\include\opencv2;Library

Directories:D:\Soft\OpenCV2.4.6\vs2010_GPU\install\lib;

2、选中工程-->Properties-->Configuration Properties-->Linker-->Input-->AdditionalDependencies:Debug和Release,添加相应的.lib库;

3、将D:\soft\OpenCV2.4.6\vs2010_GPU\install\bin加入到windows系统环境变量Path中,重启。(也可以将install文件夹全部拷贝出来,作为一个新的opencv版本存在,里面应该包括include\bin\lib这个几个主要目录)

4、示例如下,如果iDevicesNum结果非0,说明安装配置正确。

1.#include "stdafx.h"

2.#include 

3.#include 

4.

5.using namespace cv;

6.using namespace cv::gpu;

7.

8.int_tmain(int argc, _TCHAR* argv[])

9.{

10.   int iDevicesNum = getCudaEnabledDeviceCount();

11.

12.   cout<

13.

14.   return 0;

15.}

参考文献

你可能感兴趣的:(opencv,python,gpu加速)