平台:Windows 10 20H2
Visual Studio 2015
opencv_contrib-3.4.12
参考文章:
添加OpenCV_contrib库至OpenCV3.1.0中(Windows 64位 环境下编译OpenCV3.1.0和OpenCV_contrib)—— MICHAEL_LIU
opencv_contrib安装笔记 —— weijifen000
Releases - OpenCV上的OpenCV所包含的库只有基础内容,而人脸识别、matlab调用、RGB加工、深层神经网络等内容则需要安装opencv_contrib。
Github:opencv/opencv_contrib
使用cmake的时候需使用python 2.7,否则之后貌似会有警告。
使用Anaconda3建立环境后,进入python 2.7环境。
在python 2.7环境下打开cmake
Where is the source code内填入opencv解压目录下的 sources 文件夹路径
Where to build the binaries内填入输出路径
选择所用的Visual Studio版本和系统平台
确认下方框内无红色警告
若有警告,打开警告位置的日志文件
查找cmake_download字符串,其后第一个路径是文件放置位置,第二个网址是下载地址
缺的文件会由于下载失败变成0kb的文件
下载后改成相同的名字将其替换
之后再次点击Configure,确认上下方都没红色警告,且提示Configuring done
之后点击Generate,出现Generating done
在 search 对话框中输入 OPENCV_EXTRA_MODULES_PATH,找到OPENCV_EXTRA_MODULES_PATH后在value中填入opencv_contrib解压目录下的modules路径,反斜杠\要改成正斜杠/
在 search 对话框中输入 OPENCV_ENABLE_NONFREE ,在value值中勾选以允许使用已申请专利的算法,之后再次点击Configure。
出现Configuring done后点击Generate
等待出现Generating done
点击 Open Project
选择 生成->批生成
勾选ALL_BUILD和INSTALL的Debug和Release配置,之后点击生成
等待编译完成,最终生成的文件不小:
此后该文件夹也可移动到别的地方
新建要用的项目
配置项目的属性
配置选为所有配置,平台为之前所选的平台
VC++目录->包含目录
添加输出文件夹下install\include文件夹及其子文件夹的路径
VC++目录->库目录
其路径为输出文件夹下/install/x64/vc14/lib文件夹的路径
调试->环境
添加
PATH=D:\Work\OpenCV\opencv-3.4.12_build\install\x64\vc14\bin;%PATH%
路径为输出文件夹下\install\x64\vc14\bin文件夹的路径
点击应用
分别配置Debug、Release下的 链接器->输入->附加依赖项
加入lib文件夹下的以".lib"结尾的库文件名
其中以"d.dll"结尾的为Debug时需要的库
不带’d’的则为Release时需要的库
这些文件名可用如下python脚本提取,filePath为lib文件夹的路径
import os
filePath = r'D:\Work\OpenCV\opencv-3.4.12_build\install\x64\vc14\lib'
DebugLibList = []
ReleaseLibList = []
for _ in os.listdir(filePath):
if _.endswith('d.lib'):
DebugLibList.append(_)
elif _.endswith('.lib'):
ReleaseLibList.append(_)
print("DebugLibList:\n")
for _ in DebugLibList:
print(_)
print("\nReleaseLibList:\n")
for _ in ReleaseLibList:
print(_)
opencv_aruco3412d.lib
opencv_bgsegm3412d.lib
opencv_bioinspired3412d.lib
opencv_calib3d3412d.lib
opencv_ccalib3412d.lib
opencv_core3412d.lib
opencv_datasets3412d.lib
opencv_dnn3412d.lib
opencv_dnn_objdetect3412d.lib
opencv_dpm3412d.lib
opencv_face3412d.lib
opencv_features2d3412d.lib
opencv_flann3412d.lib
opencv_fuzzy3412d.lib
opencv_hdf3412d.lib
opencv_hfs3412d.lib
opencv_highgui3412d.lib
opencv_imgcodecs3412d.lib
opencv_imgproc3412d.lib
opencv_img_hash3412d.lib
opencv_line_descriptor3412d.lib
opencv_ml3412d.lib
opencv_objdetect3412d.lib
opencv_optflow3412d.lib
opencv_phase_unwrapping3412d.lib
opencv_photo3412d.lib
opencv_plot3412d.lib
opencv_reg3412d.lib
opencv_rgbd3412d.lib
opencv_saliency3412d.lib
opencv_shape3412d.lib
opencv_stereo3412d.lib
opencv_stitching3412d.lib
opencv_structured_light3412d.lib
opencv_superres3412d.lib
opencv_surface_matching3412d.lib
opencv_text3412d.lib
opencv_tracking3412d.lib
opencv_video3412d.lib
opencv_videoio3412d.lib
opencv_videostab3412d.lib
opencv_xfeatures2d3412d.lib
opencv_ximgproc3412d.lib
opencv_xobjdetect3412d.lib
opencv_xphoto3412d.lib
Release的库为
opencv_aruco3412.lib
opencv_bgsegm3412.lib
opencv_bioinspired3412.lib
opencv_calib3d3412.lib
opencv_ccalib3412.lib
opencv_core3412.lib
opencv_datasets3412.lib
opencv_dnn3412.lib
opencv_dnn_objdetect3412.lib
opencv_dpm3412.lib
opencv_face3412.lib
opencv_features2d3412.lib
opencv_flann3412.lib
opencv_fuzzy3412.lib
opencv_hdf3412.lib
opencv_hfs3412.lib
opencv_highgui3412.lib
opencv_imgcodecs3412.lib
opencv_imgproc3412.lib
opencv_img_hash3412.lib
opencv_line_descriptor3412.lib
opencv_ml3412.lib
opencv_objdetect3412.lib
opencv_optflow3412.lib
opencv_phase_unwrapping3412.lib
opencv_photo3412.lib
opencv_plot3412.lib
opencv_reg3412.lib
opencv_rgbd3412.lib
opencv_saliency3412.lib
opencv_shape3412.lib
opencv_stereo3412.lib
opencv_stitching3412.lib
opencv_structured_light3412.lib
opencv_superres3412.lib
opencv_surface_matching3412.lib
opencv_text3412.lib
opencv_tracking3412.lib
opencv_video3412.lib
opencv_videoio3412.lib
opencv_videostab3412.lib
opencv_xfeatures2d3412.lib
opencv_ximgproc3412.lib
opencv_xobjdetect3412.lib
opencv_xphoto3412.lib
来自Opencv3.1.0+opencv_contrib配置及使用SIFT测试 —— 陈纪建
opencv 3中SIFT匹配是在opencv_contrib库中的,这里我们就用它来做一个简单的测试。
#include
#include //头文件
#include
using namespace cv; //包含cv命名空间
using namespace std;
using namespace xfeatures2d;
int main()
{
//Create SIFT class pointer
Ptr<Feature2D> f2d = SIFT::create();
//读入图片
Mat img_1 = imread("D:/Work/OpenCV/Workplace/Robot/Robot/1.jpg");
Mat img_2 = imread("D:/Work/OpenCV/Workplace/Robot/Robot/2.jpg");
//Detect the keypoints
vector<KeyPoint> keypoints_1, keypoints_2;
f2d->detect(img_1, keypoints_1);
f2d->detect(img_2, keypoints_2);
//Calculate descriptors (feature vectors)
Mat descriptors_1, descriptors_2;
f2d->compute(img_1, keypoints_1, descriptors_1);
f2d->compute(img_2, keypoints_2, descriptors_2);
//Matching descriptor vector using BFMatcher
BFMatcher matcher;
vector<DMatch> matches;
matcher.match(descriptors_1, descriptors_2, matches);
//绘制匹配出的关键点
Mat img_matches;
drawMatches(img_1, keypoints_1, img_2, keypoints_2, matches, img_matches);
imshow("match图", img_matches);
//等待任意按键按下
waitKey(0);
}
测试结果如下: