win10系统下vs2015+opencv3.4.3+cmake编译opencv-contrib3.4.3

最近在研究KAZE算法,发现我使用的opencv2.4.8中没有集成KAZE算法,网上查找该算法在opencv3版本中有,故将opencv和vs卸载重装,我安装的是opencv3.4.3+vs2015,一切配置完之后,发现KAZE算法是可以用了,但SIFT/SURF算法又出错,原来是由于版权问题,将其放在了opencv_contrib扩展模块中,又重新编译配置了一遍,该过程出现了多问题,特此将其写下来,希望能帮上忙。
一、软件下载
1、opencv下载
opencv下载大家应该都知道在官网下载,在此给出官网链接。https://opencv.org/releases.html
2、vs下载
同样也给出官方链接。
https://visualstudio.microsoft.com/zh-hans/downloads/
3、cmake下载
cmake的版本与编译成功与否几乎没有关系。下载网址为:
https://cmake.org/download/
4、opencv_contrib扩展模块的下载
在下载opencv_contrib扩展模块时,版本必须要和opencv的版本一致,否则将导致后面编译错误(我第一次下载的版本与opencv不一致,出现各种错误,千万不要入坑!!!)。
opencv_contrib扩展模块的下载网址为:
https://github.com/opencv/opencv_contrib/releases
win10系统下vs2015+opencv3.4.3+cmake编译opencv-contrib3.4.3_第1张图片
我下载的是3.4.3版本,可以根据自己所需要的版本来下载。
二、软件安装
以上四个软件的安装很容易,按提示步骤安装即可。
三、opencv_contrib扩展模块的编译
这一部分是关键步骤,它成功了就算是整个编译配置过程成功了一半。
1、首先找到cmake根目录下bin文件夹,打开cmake-gui.exe,界面如下图所示。其中where is the source code 选择你opencv的安装路径,where to build the binaries 选择需要存放生成文件的目录,在你安装的opencv根目录下新建一个文件夹,建议用英文名命名,我将其命为build。
2、点击configure,第一次使用会弹出对话框,需选择对应的vs版本,我电脑是64位的,故选择的visual studio 14 2015 win64。
win10系统下vs2015+opencv3.4.3+cmake编译opencv-contrib3.4.3_第2张图片
3、找到OPENCV_EXTRA_MODULES_PATH,将其值选择为opencv_contrib文件夹中的modules文件夹,勾选对应的文件夹。同时要记得勾选OPENCV_ENABLE_NONFREE,否则测试时会出错。
win10系统下vs2015+opencv3.4.3+cmake编译opencv-contrib3.4.3_第3张图片
4.再次点击configure,完成之后点击generate,在cmake界面直接点击open project打开项目,选择64或32位的Debuge和Release,根据自己电脑系统来选择,在菜单栏选择生成->生成解决方案,这一过程时间会比较长,耐心等待哦。
win10系统下vs2015+opencv3.4.3+cmake编译opencv-contrib3.4.3_第4张图片
5.编译完成后,会在opencv根目录下的modules文件夹下生成如下子文件夹,将各个子文件夹中的include文件夹剪切合并,并且放到opencv根目录下的include文件夹中。
win10系统下vs2015+opencv3.4.3+cmake编译opencv-contrib3.4.3_第5张图片
四、opencv的配置
1.配置环境变量
右击此电脑—>属性—>高级系统设置—>环境变量—>选择用户变量中的PATH变量—>编辑,添加环境变量。我的环境变量如下图所示(你们的按照自己的路径来,其中build就是上面编译opencv_contrib扩展模块时新建的文件夹):
win10系统下vs2015+opencv3.4.3+cmake编译opencv-contrib3.4.3_第6张图片
2.opencv的配置
打开vs2015,新建一个工程,选择属性管理器,点击工程名,根据自己电脑的系统进行配置。
win10系统下vs2015+opencv3.4.3+cmake编译opencv-contrib3.4.3_第7张图片
双击上图中红色框圈出的,选择VC++目录,分别配置包含目录和库目录,我的配置如下:
包含目录:
D:\opencv-3.4.3\include
库目录:
D:\opencv-3.4.3\build\lib\Debug
D:\opencv-3.4.3\build\lib\Release
选择链接库—>输入,添加依赖项。此处要根据opencv的版本号来配置,“343”代表我的opencv版本为3.4.3,其中带d的为Debug模式,不带d的为Release模式。
opencv_aruco343d.lib
opencv_bgsegm343d.lib
opencv_bioinspired343d.lib
opencv_calib3d343d.lib
opencv_ccalib343d.lib
opencv_core343d.lib
opencv_datasets343d.lib
opencv_dnn343d.lib
opencv_dnn_objdetect343d.lib
opencv_dpm343d.lib
opencv_face343d.lib
opencv_features2d343d.lib
opencv_flann343d.lib
opencv_fuzzy343d.lib
opencv_hfs343d.lib
opencv_highgui343d.lib
opencv_imgcodecs343d.lib
opencv_imgproc343d.lib
opencv_img_hash343d.lib
opencv_line_descriptor343d.lib
opencv_ml343d.lib
opencv_objdetect343d.lib
opencv_optflow343d.lib
opencv_phase_unwrapping343d.lib
opencv_photo343d.lib
opencv_plot343d.lib
opencv_reg343d.lib
opencv_rgbd343d.lib
opencv_saliency343d.lib
opencv_shape343d.lib
opencv_stereo343d.lib
opencv_stitching343d.lib
opencv_structured_light343d.lib
opencv_superres343d.lib
opencv_surface_matching343d.lib
opencv_text343d.lib
opencv_tracking343d.lib
opencv_ts343d.lib
opencv_video343d.lib
opencv_videoio343d.lib
opencv_videostab343d.lib
opencv_xfeatures2d343d.lib
opencv_ximgproc343d.lib
opencv_xobjdetect343d.lib
opencv_xphoto343d.lib

opencv_aruco343.lib
opencv_bgsegm343.lib
opencv_bioinspired343.lib
opencv_calib3d343.lib
opencv_ccalib343.lib
opencv_core343.lib
opencv_datasets343.lib
opencv_dnn343.lib
opencv_dnn_objdetect343.lib
opencv_dpm343.lib
opencv_face343.lib
opencv_features2d343.lib
opencv_flann343.lib
opencv_fuzzy343.lib
opencv_hfs343.lib
opencv_highgui343.lib
opencv_imgcodecs343.lib
opencv_imgproc343.lib
opencv_img_hash343.lib
opencv_line_descriptor343.lib
opencv_ml343.lib
opencv_objdetect343.lib
opencv_optflow343.lib
opencv_phase_unwrapping343.lib
opencv_photo343.lib
opencv_plot343.lib
opencv_reg343.lib
opencv_rgbd343.lib
opencv_saliency343.lib
opencv_shape343.lib
opencv_stereo343.lib
opencv_stitching343.lib
opencv_structured_light343.lib
opencv_superres343.lib
opencv_surface_matching343.lib
opencv_text343.lib
opencv_tracking343.lib
opencv_ts343.lib
opencv_video343.lib
opencv_videoio343.lib
opencv_videostab343.lib
opencv_xfeatures2d343.lib
opencv_ximgproc343.lib
opencv_xobjdetect343.lib
opencv_xphoto343.lib
至此,opencv的配置完成了,我们需要通过测试来检查是否安装配置成功。
五、测试程序
在新建的工程中添加如下代码,生成解决方案。

#include "opencv2/opencv.hpp"  
#include"opencv2/xfeatures2d.hpp"
#include

using namespace cv;
using namespace std;

int main() {
	Mat img = imread("1.png", CV_LOAD_IMAGE_COLOR);
	Ptr sift = xfeatures2d::SIFT::create();
	vector keypoints;
	Mat descriptors;

	sift->detectAndCompute(img, noArray(), keypoints, descriptors);
	drawKeypoints(img, keypoints, descriptors, Scalar(0, 255, 255));
	imshow("Result", descriptors);
	waitKey(0);
	return 0;
}

显示如下图表示测试成功。
win10系统下vs2015+opencv3.4.3+cmake编译opencv-contrib3.4.3_第8张图片
参考博客:https://blog.csdn.net/weixin_42012977/article/details/82992962

你可能感兴趣的:(软件安装)