因为需要用到GPU的一些功能,重新安装一下opencv并做一个记录。
OpenCV下载注意分支对应.OpenCV保存路径:D:\Program Files\opencv430
相关配置:
D:/Program Files/opencv430/opencv-4.3.0
D:/Program Files/opencv430/build
有几个文件下载失败,根据红色部分的提示打开CMakeDownloadLog.txt
里面有下载改文件的地址,下载后将其改名字然后放到相应的目录。
后面还有下载失败的,所以先建个文件夹暂存下载的文件吧。
日志文件:
#do_copy "opencv_videoio_ffmpeg.dll" "3b094c37d270a30f0b20a0bc8d3ecafb" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/3d2e97081683265950316c65a52c2e8858ffba1b/ffmpeg/opencv_videoio_ffmpeg.dll" "D:/Program Files/opencv430/build/3rdparty/ffmpeg"
#missing "D:/Program Files/opencv430/build/3rdparty/ffmpeg/opencv_videoio_ffmpeg.dll"
#check_md5 "D:/Program Files/opencv430/opencv-4.3.0/.cache/ffmpeg/3b094c37d270a30f0b20a0bc8d3ecafb-opencv_videoio_ffmpeg.dll"
#mismatch_md5 "D:/Program Files/opencv430/opencv-4.3.0/.cache/ffmpeg/3b094c37d270a30f0b20a0bc8d3ecafb-opencv_videoio_ffmpeg.dll" "d41d8cd98f00b204e9800998ecf8427e"
#delete "D:/Program Files/opencv430/opencv-4.3.0/.cache/ffmpeg/3b094c37d270a30f0b20a0bc8d3ecafb-opencv_videoio_ffmpeg.dll"
#cmake_download "D:/Program Files/opencv430/opencv-4.3.0/.cache/ffmpeg/3b094c37d270a30f0b20a0bc8d3ecafb-opencv_videoio_ffmpeg.dll" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/3d2e97081683265950316c65a52c2e8858ffba1b/ffmpeg/opencv_videoio_ffmpeg.dll"
#try 1
# timeout on name lookup is not supported
# getaddrinfo(3) failed for raw.githubusercontent.com:443
# Couldn't resolve host 'raw.githubusercontent.com'
# Closing connection 0
#
#do_copy "opencv_videoio_ffmpeg_64.dll" "388ee23a7ca44eef2344e265fafd5940" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/3d2e97081683265950316c65a52c2e8858ffba1b/ffmpeg/opencv_videoio_ffmpeg_64.dll" "D:/Program Files/opencv430/build/3rdparty/ffmpeg"
#missing "D:/Program Files/opencv430/build/3rdparty/ffmpeg/opencv_videoio_ffmpeg_64.dll"
#check_md5 "D:/Program Files/opencv430/opencv-4.3.0/.cache/ffmpeg/388ee23a7ca44eef2344e265fafd5940-opencv_videoio_ffmpeg_64.dll"
#mismatch_md5 "D:/Program Files/opencv430/opencv-4.3.0/.cache/ffmpeg/388ee23a7ca44eef2344e265fafd5940-opencv_videoio_ffmpeg_64.dll" "d41d8cd98f00b204e9800998ecf8427e"
#delete "D:/Program Files/opencv430/opencv-4.3.0/.cache/ffmpeg/388ee23a7ca44eef2344e265fafd5940-opencv_videoio_ffmpeg_64.dll"
#cmake_download "D:/Program Files/opencv430/opencv-4.3.0/.cache/ffmpeg/388ee23a7ca44eef2344e265fafd5940-opencv_videoio_ffmpeg_64.dll" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/3d2e97081683265950316c65a52c2e8858ffba1b/ffmpeg/opencv_videoio_ffmpeg_64.dll"
#try 1
# timeout on name lookup is not supported
# getaddrinfo(3) failed for raw.githubusercontent.com:443
# Couldn't resolve host 'raw.githubusercontent.com'
# Closing connection 0
#
#do_copy "ffmpeg_version.cmake" "ad57c038ba34b868277ccbe6dd0f9602" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/3d2e97081683265950316c65a52c2e8858ffba1b/ffmpeg/ffmpeg_version.cmake" "D:/Program Files/opencv430/build/3rdparty/ffmpeg"
#missing "D:/Program Files/opencv430/build/3rdparty/ffmpeg/ffmpeg_version.cmake"
#check_md5 "D:/Program Files/opencv430/opencv-4.3.0/.cache/ffmpeg/ad57c038ba34b868277ccbe6dd0f9602-ffmpeg_version.cmake"
#mismatch_md5 "D:/Program Files/opencv430/opencv-4.3.0/.cache/ffmpeg/ad57c038ba34b868277ccbe6dd0f9602-ffmpeg_version.cmake" "d41d8cd98f00b204e9800998ecf8427e"
#delete "D:/Program Files/opencv430/opencv-4.3.0/.cache/ffmpeg/ad57c038ba34b868277ccbe6dd0f9602-ffmpeg_version.cmake"
#cmake_download "D:/Program Files/opencv430/opencv-4.3.0/.cache/ffmpeg/ad57c038ba34b868277ccbe6dd0f9602-ffmpeg_version.cmake" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/3d2e97081683265950316c65a52c2e8858ffba1b/ffmpeg/ffmpeg_version.cmake"
#try 1
# timeout on name lookup is not supported
# getaddrinfo(3) failed for raw.githubusercontent.com:443
# Couldn't resolve host 'raw.githubusercontent.com'
# Closing connection 0
#
根据日志中网址下载后改名字:
#放置路径 D:\Program Files\opencv430\opencv-4.3.0\.cache\ippicv
ippicv_2020_win_intel64_20191018_general.zip ====改为hash值的名字===>
879741a7946b814455eee6c6ffde2984-ippicv_2020_win_intel64_20191018_general.zip
#以下三个放置路径 D:\Program Files\opencv430\opencv-4.3.0\.cache\ffmpeg
ffmpeg_version.cmake ====改为hash值的名字===>
ad57c038ba34b868277ccbe6dd0f9602-ffmpeg_version.cmake
opencv_videoio_ffmpeg.dll ====改为hash值的名字===>
3b094c37d270a30f0b20a0bc8d3ecafb-opencv_videoio_ffmpeg.dll
opencv_videoio_ffmpeg_64.dll ====改为hash值的名字===>
388ee23a7ca44eef2344e265fafd5940-opencv_videoio_ffmpeg_64.dll
再次配置就OK了!
OPENCV_EXTRA_MODULES_PATH : D:/Program Files/opencv430/opencv_contrib-4.3.0/modules
如果需要用 SURF,SIFT算法的话把OPENCV_ENABLE_NONFREE
勾上。BUILD_opencv_world
勾上,最后编译的结果为两个,一个debug版本,一个release版本。
configure后依然有文件下载失败,同样打开CMakeDownloadLog.txt
查看:
#use_cache "D:/Program Files/opencv430/opencv-4.3.0/.cache"
#match_hash_in_cmake_cache "OCV_DOWNLOAD_IPPICV_HASH_3rdparty_ippicv_ippicv_2020_win_intel64_20191018_general_zip"
#match_hash_in_cmake_cache "OCV_DOWNLOAD_ADE_HASH_3rdparty_ade_v0_1_1f_zip"
#match_hash_in_cmake_cache "OCV_DOWNLOAD_FFMPEG_HASH_3rdparty_ffmpeg_opencv_videoio_ffmpeg_dll"
#match_hash_in_cmake_cache "OCV_DOWNLOAD_FFMPEG_HASH_3rdparty_ffmpeg_opencv_videoio_ffmpeg_64_dll"
#match_hash_in_cmake_cache "OCV_DOWNLOAD_FFMPEG_HASH_3rdparty_ffmpeg_ffmpeg_version_cmake"
#do_copy "boostdesc_bgm.i" "0ea90e7a8f3f7876d450e4149c97c74f" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm.i" "D:/Program Files/opencv430/build/downloads/xfeatures2d"
#missing "D:/Program Files/opencv430/build/downloads/xfeatures2d/boostdesc_bgm.i"
#cmake_download "D:/Program Files/opencv430/opencv-4.3.0/.cache/xfeatures2d/boostdesc/0ea90e7a8f3f7876d450e4149c97c74f-boostdesc_bgm.i" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm.i"
#try 1
# timeout on name lookup is not supported
# getaddrinfo(3) failed for raw.githubusercontent.com:443
# Couldn't resolve host 'raw.githubusercontent.com'
# Closing connection 0
#
#do_copy "boostdesc_bgm_bi.i" "232c966b13651bd0e46a1497b0852191" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm_bi.i" "D:/Program Files/opencv430/build/downloads/xfeatures2d"
#missing "D:/Program Files/opencv430/build/downloads/xfeatures2d/boostdesc_bgm_bi.i"
#cmake_download "D:/Program Files/opencv430/opencv-4.3.0/.cache/xfeatures2d/boostdesc/232c966b13651bd0e46a1497b0852191-boostdesc_bgm_bi.i" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm_bi.i"
#try 1
# timeout on name lookup is not supported
# getaddrinfo(3) failed for raw.githubusercontent.com:443
# Couldn't resolve host 'raw.githubusercontent.com'
# Closing connection 0
#
#do_copy "boostdesc_bgm_hd.i" "324426a24fa56ad9c5b8e3e0b3e5303e" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm_hd.i" "D:/Program Files/opencv430/build/downloads/xfeatures2d"
#missing "D:/Program Files/opencv430/build/downloads/xfeatures2d/boostdesc_bgm_hd.i"
#cmake_download "D:/Program Files/opencv430/opencv-4.3.0/.cache/xfeatures2d/boostdesc/324426a24fa56ad9c5b8e3e0b3e5303e-boostdesc_bgm_hd.i" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm_hd.i"
#try 1
# timeout on name lookup is not supported
# getaddrinfo(3) failed for raw.githubusercontent.com:443
# Couldn't resolve host 'raw.githubusercontent.com'
# Closing connection 0
#
#do_copy "boostdesc_binboost_064.i" "202e1b3e9fec871b04da31f7f016679f" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_064.i" "D:/Program Files/opencv430/build/downloads/xfeatures2d"
#missing "D:/Program Files/opencv430/build/downloads/xfeatures2d/boostdesc_binboost_064.i"
#cmake_download "D:/Program Files/opencv430/opencv-4.3.0/.cache/xfeatures2d/boostdesc/202e1b3e9fec871b04da31f7f016679f-boostdesc_binboost_064.i" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_064.i"
#try 1
# timeout on name lookup is not supported
# getaddrinfo(3) failed for raw.githubusercontent.com:443
# Couldn't resolve host 'raw.githubusercontent.com'
# Closing connection 0
#
#do_copy "boostdesc_binboost_128.i" "98ea99d399965c03d555cef3ea502a0b" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_128.i" "D:/Program Files/opencv430/build/downloads/xfeatures2d"
#missing "D:/Program Files/opencv430/build/downloads/xfeatures2d/boostdesc_binboost_128.i"
#cmake_download "D:/Program Files/opencv430/opencv-4.3.0/.cache/xfeatures2d/boostdesc/98ea99d399965c03d555cef3ea502a0b-boostdesc_binboost_128.i" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_128.i"
#try 1
# timeout on name lookup is not supported
# getaddrinfo(3) failed for raw.githubusercontent.com:443
# Couldn't resolve host 'raw.githubusercontent.com'
# Closing connection 0
#
#do_copy "boostdesc_binboost_256.i" "e6dcfa9f647779eb1ce446a8d759b6ea" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_256.i" "D:/Program Files/opencv430/build/downloads/xfeatures2d"
#missing "D:/Program Files/opencv430/build/downloads/xfeatures2d/boostdesc_binboost_256.i"
#cmake_download "D:/Program Files/opencv430/opencv-4.3.0/.cache/xfeatures2d/boostdesc/e6dcfa9f647779eb1ce446a8d759b6ea-boostdesc_binboost_256.i" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_256.i"
#try 1
# timeout on name lookup is not supported
# getaddrinfo(3) failed for raw.githubusercontent.com:443
# Couldn't resolve host 'raw.githubusercontent.com'
# Closing connection 0
#
#do_copy "boostdesc_lbgm.i" "0ae0675534aa318d9668f2a179c2a052" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_lbgm.i" "D:/Program Files/opencv430/build/downloads/xfeatures2d"
#missing "D:/Program Files/opencv430/build/downloads/xfeatures2d/boostdesc_lbgm.i"
#cmake_download "D:/Program Files/opencv430/opencv-4.3.0/.cache/xfeatures2d/boostdesc/0ae0675534aa318d9668f2a179c2a052-boostdesc_lbgm.i" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_lbgm.i"
#try 1
# timeout on name lookup is not supported
# getaddrinfo(3) failed for raw.githubusercontent.com:443
# Couldn't resolve host 'raw.githubusercontent.com'
# Closing connection 0
#
#do_copy "vgg_generated_48.i" "e8d0dcd54d1bcfdc29203d011a797179" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_48.i" "D:/Program Files/opencv430/build/downloads/xfeatures2d"
#missing "D:/Program Files/opencv430/build/downloads/xfeatures2d/vgg_generated_48.i"
#cmake_download "D:/Program Files/opencv430/opencv-4.3.0/.cache/xfeatures2d/vgg/e8d0dcd54d1bcfdc29203d011a797179-vgg_generated_48.i" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_48.i"
#try 1
# timeout on name lookup is not supported
# getaddrinfo(3) failed for raw.githubusercontent.com:443
# Couldn't resolve host 'raw.githubusercontent.com'
# Closing connection 0
#
#do_copy "vgg_generated_64.i" "7126a5d9a8884ebca5aea5d63d677225" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_64.i" "D:/Program Files/opencv430/build/downloads/xfeatures2d"
#missing "D:/Program Files/opencv430/build/downloads/xfeatures2d/vgg_generated_64.i"
#cmake_download "D:/Program Files/opencv430/opencv-4.3.0/.cache/xfeatures2d/vgg/7126a5d9a8884ebca5aea5d63d677225-vgg_generated_64.i" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_64.i"
#try 1
# timeout on name lookup is not supported
# getaddrinfo(3) failed for raw.githubusercontent.com:443
# Couldn't resolve host 'raw.githubusercontent.com'
# Closing connection 0
#
#do_copy "vgg_generated_80.i" "7cd47228edec52b6d82f46511af325c5" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_80.i" "D:/Program Files/opencv430/build/downloads/xfeatures2d"
#missing "D:/Program Files/opencv430/build/downloads/xfeatures2d/vgg_generated_80.i"
#cmake_download "D:/Program Files/opencv430/opencv-4.3.0/.cache/xfeatures2d/vgg/7cd47228edec52b6d82f46511af325c5-vgg_generated_80.i" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_80.i"
#try 1
# timeout on name lookup is not supported
# getaddrinfo(3) failed for raw.githubusercontent.com:443
# Couldn't resolve host 'raw.githubusercontent.com'
# Closing connection 0
#
#do_copy "vgg_generated_120.i" "151805e03568c9f490a5e3a872777b75" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_120.i" "D:/Program Files/opencv430/build/downloads/xfeatures2d"
#missing "D:/Program Files/opencv430/build/downloads/xfeatures2d/vgg_generated_120.i"
#cmake_download "D:/Program Files/opencv430/opencv-4.3.0/.cache/xfeatures2d/vgg/151805e03568c9f490a5e3a872777b75-vgg_generated_120.i" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_120.i"
#try 1
# timeout on name lookup is not supported
# getaddrinfo(3) failed for raw.githubusercontent.com:443
# Couldn't resolve host 'raw.githubusercontent.com'
# Closing connection 0
#
#do_copy "face_landmark_model.dat" "7505c44ca4eb54b4ab1e4777cb96ac05" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/8afa57abc8229d611c4937165d20e2a2d9fc5a12/face_landmark_model.dat" "D:/Program Files/opencv430/build/testdata/cv/face/"
#missing "D:/Program Files/opencv430/build/testdata/cv/face//face_landmark_model.dat"
#cmake_download "D:/Program Files/opencv430/opencv-4.3.0/.cache/data/7505c44ca4eb54b4ab1e4777cb96ac05-face_landmark_model.dat" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/8afa57abc8229d611c4937165d20e2a2d9fc5a12/face_landmark_model.dat"
#try 1
# timeout on name lookup is not supported
# getaddrinfo(3) failed for raw.githubusercontent.com:443
# Couldn't resolve host 'raw.githubusercontent.com'
# Closing connection 0
#
根据日志文件提示分别放入
#文件夹需要自己根据路径建
D:\Program Files\opencv430\build\downloads\xfeatures2d
D:\Program Files\opencv430\build\testdata\cv\face
再次configure,就OK了。
我感觉上一步也可以这样,不用改名字,放在missing路径下就OK
configure
成功后,Generate
生成vs工程文件。 之后直接Open Project
,则会使用前面选择的vs版本打开工程。
在菜单栏上选择:生成 ->批生成。可同时编译debug版本和release版本。
编译完后,把build/install文件夹放到opencv430文件夹下就OK。
这个就是平时遇到的操作了。
环境变量配置:此电脑右键属性–>高级系统设置–>环境变量–>系统变量–>Path–>新建
D:\Program Files\opencv430\install\x64\vc15\bin
打开VS新建一个工程,新建属性表opencv430x64d.props
D:\Program Files\opencv430\install\include
D:\Program Files\opencv430\install\include\opencv2
D:\Program Files\opencv430\install\x64\vc15\lib
opencv_img_hash430d.lib
opencv_world430d.lib
新建属性表opencv430x64r.props
D:\Program Files\opencv430\install\include
D:\Program Files\opencv430\install\include\opencv2
D:\Program Files\opencv430\install\x64\vc15\lib
opencv_img_hash430.lib
opencv_world430.lib
然后将属性表拷贝到安装目录,以便后续查找。
#include
#include
#include
#include
#include
using namespace cv;
using namespace std;
int main()
{
Mat src = imread("F:/vs_test/lena.jpg");
if (src.data == NULL)
{
cout << "No exist" << endl;
return -1;
}
namedWindow("input image", WINDOW_AUTOSIZE);
namedWindow("output image", WINDOW_AUTOSIZE);
imshow("input image", src);
Ptr<Feature2D> sift = xfeatures2d::SIFT::create(400); //括号参数越大越精确,自定
vector <KeyPoint> keypointsa;
Mat a;
sift->detectAndCompute(src, noArray(), keypointsa, a); //得到特征点和特征点描述
drawKeypoints(src, keypointsa, src);//画出特征点
//显示
imshow("output image", src);
waitKey();
return 0;
}
不带CUDA版本的opencv方便拷贝到其他电脑使用,同时拷贝install
文件夹和属性表,按照安装目录放置就OK,只需要配置一个环境变量就可以直接使用了,很方便。但是带CUDA的版本就不一样了,需要CUDA版本相同,稍微麻烦一点,同时为了降低出错率,选择分开编译。
将上面编译好的文件夹opencv430
复制一份,并改名为opencv430withCUDA
。将build
文件夹里面的testdata
与downloads
保留,其他的删除,将opencv-4.3.0\.cacha\ffmpeg
与ippicv
保留,其他的删除,保留的就是上面自己下载的文件。
打开CMake
,点击File-->Delete Cache
重新输入路径。
D:/Program Files/opencv430withCUDA/opencv-4.3.0
D:/Program Files/opencv430withCUDA/build
D:/Program Files/opencv430withCUDA/opencv_contrib-4.3.0/modules
需要勾选的选项有:
BUILD_opencv_world
OPENCV_ENABLE_NONFREE
WITH_CUDA
MKL_WITH_OPENMP #这是一个并行加速库,可以不选,只是我需要用
OPENCV_DNN_CUDA
WITH_TBB #默认情况下是OFF、勾选可以获得并行处理支持
CUDA_ARCH_BIN 6.1 #删除其他的数字,这个6.1是显卡计算力,根据自己的显卡填写,就是这里十分耗时
按照上面的流程走一遍,下载失败的文件都已经下载了,只要CUDA安装没出错就比较快 ,带CUDA 的编译好慢!!流程上没什么大问题,就是VS编译很慢。
configure
完成后,Open Project
打开工程:生成–>批生成。把install文件夹拷贝出来。
环境变量配置:此电脑右键属性–>高级系统设置–>环境变量–>系统变量–>Path–>新建
D:\Program Files\opencv430withCUDA\install\x64\vc15\bin
注销一下电脑,或者全部配置完后再注销。
4.2.1.debug x64
打开VS新建一个工程,新建属性表opencv430x64d.props
D:\Program Files\opencv430WithCUDA\install\include
D:\Program Files\opencv430withCUDA\install\include\opencv2
D:\Program Files\opencv430withCUDA\install\x64\vc15\lib
如果前面没有勾选BUILD_opencv_world
,库文件会比较多,此时库文件的名称可以使用命令行获取,区别于Linux的命令行,Windows的脚本可以使用后缀名为**.bat
的文件:
cd D:\Program Files\opencv430withCUDA\install\x64\vc15\lib
dir /b *430d.lib >DebugLibName.txt && move "DebugLibName.txt" "D:\Program Files\opencv430withCUDA\DebugLibName.txt"
dir /b *430.lib >ReleaseLibName.txt && move "ReleaseLibName.txt" "D:\Program Files\opencv430withCUDA\ReleaseLibName.txt"
双击运行后在D:\Program Files\opencv430withCUDA\
中打开txt文档复制就好。
opencv_img_hash430d.lib
opencv_world430d.lib
4.2.2.release x64
新建属性表opencv430x64r.props
D:\Program Files\opencv430WithCUDA\install\include
D:\Program Files\opencv430withCUDA\install\include\opencv2
D:\Program Files\opencv430withCUDA\install\x64\vc15\lib
opencv_img_hash430.lib
opencv_world430.lib
最后将属性表拷贝到安装目录,以便后续查找。
安装好后可以删除opencv430
和opencv430withCUDA
下的build文件夹。很大。注销一下电脑,进行测试,不需要重启。
#include
#include "opencv2/opencv_modules.hpp"
#include "opencv2/core.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/cudafeatures2d.hpp"
#include "opencv2/xfeatures2d/cuda.hpp"
using namespace std;
using namespace cv;
using namespace cv::cuda;
int main()
{
GpuMat img1, img2;
img1.upload(imread("1.bmp", IMREAD_GRAYSCALE));
img2.upload(imread("2.bmp", IMREAD_GRAYSCALE));
cv::cuda::printShortCudaDeviceInfo(cv::cuda::getDevice());
SURF_CUDA surf;
// detecting keypoints & computing descriptors
GpuMat keypoints1GPU, keypoints2GPU;
GpuMat descriptors1GPU, descriptors2GPU;
surf(img1, GpuMat(), keypoints1GPU, descriptors1GPU);
surf(img2, GpuMat(), keypoints2GPU, descriptors2GPU);
cout << "FOUND " << keypoints1GPU.cols << " keypoints on first image" << endl;
cout << "FOUND " << keypoints2GPU.cols << " keypoints on second image" << endl;
// matching descriptors
Ptr<cv::cuda::DescriptorMatcher> matcher = cv::cuda::DescriptorMatcher::createBFMatcher(surf.defaultNorm());
vector<DMatch> matches;
matcher->match(descriptors1GPU, descriptors2GPU, matches);
// downloading results
vector<KeyPoint> keypoints1, keypoints2;
vector<float> descriptors1, descriptors2;
surf.downloadKeypoints(keypoints1GPU, keypoints1);
surf.downloadKeypoints(keypoints2GPU, keypoints2);
surf.downloadDescriptors(descriptors1GPU, descriptors1);
surf.downloadDescriptors(descriptors2GPU, descriptors2);
// drawing the results
Mat img_matches;
drawMatches(Mat(img1), keypoints1, Mat(img2), keypoints2, matches, img_matches);
namedWindow("matches", 0);
imshow("matches", img_matches);
waitKey(0);
return 0;
}
安装完测试时报错,无法定位程序输入点于动态库上:
很显然库没找到!在路径D:\Program Files\opencv430withCUDA\install\x64\vc15
下有两个文件夹,一个bin
,一个lib
,从前面的配置可以看到,bin
文件路径是添加到环境变量的,lib
路径是添加到属性表里面的。其中bin
里面是动态库dll
和可执行文件exe
,lib
里面就是静态库。所以,如果是lib
库没找到,那就是库目录,和库名称的问题;如果是动态库dll
文件没找到,那就是环境变量的问题。但是环境变量已经设置了,那就真像只有一个,环境变量的顺序问题!!因为前面已经添加了不带CUDA版本的环境变量,这次添加的环境变量在其之后,故找错了库所以报错。
顺便查了一下可执行文件在运行时寻找和调用dll文件的路径搜索顺序。一般是:
编译多个版本可能就会存在动态库查找顺序的问题,自己得清楚版本之间的差别在哪儿,遇到报错能反应过来。enjoy.