在进行编译前,首先确定想要将二者配置到pc的那个位置,这里我选择D盘,目录是D:\study_soft,在该目录下新建一个文件夹并且命名为opencv420,之后再在opencv420文件夹中分别建立两个文件夹build(用来存放安装文件),source(用来存放编译源文件)
将下载的opencv-4.2.0-openvino.zip中的源代码和一些附加文件全部解压到刚刚建立的source文件夹中
解压后source文件夹内部的目录结构如下
相同步骤,将opencv_contrib-4.2.0.zip解压到D:\study_soft\opencv\opencv420_contrib,解压后的目录如下
上面几步做完之后打开已经安装好的cmake,在where is the source code 选择源代码的编译路径(D:/study_soft/opencv/opencv420/source),就是之前opencv410解压的source文件夹,在where to build the binaries 选择之前建立的build文件夹(D:/study_soft/opencv/opencv420/build),确认无误后点击config
在弹出来的页面中选择系统型号,这里我选择VS2019,其他选项不用管
确定好后点击Finish,cmake开始编译(注意,不可断网)
这个过程完成之后一般会遇见某些选项报错,因为这些文件下载失败,这个时候重复上面操作,即继续点击config继续下载直至不再出现报错
一般第二次就无报错了
可以看见cmake上下两个界面都没有报错,接下来点击generate
知道cmake下面界面出现Configuring done和Generating done说明编译完成
至此,opencv编译完成
在cmake界面中找到OPENCV_EXTRA_MODULES_PATH,并且找到解压后的modules文件夹D:\study_soft\opencv\opencv420_contrib\opencv_contrib-4.2.0\modules
添加后界面如下
此外,还需勾选中OPENCV_ENABLE_NONFREE的value值
这里两个改动后界面
接下来也是直接点击config,也有可能遇见红色报错警告,同上也是某些文件下载失败(一般如果网速慢的话容易出现这种问题,建议大家一定要在网速快的地方编译),这里的节解决方式也是重复config直至不再出现红色报错,直接到下方出现Configuring done,再点击generate
知道cmake下面界面出现Configuring done和Generating done则opencv_contrib编译完成
在cmake界面中点击open project
在打卡的visual stdio 2019中批生成ALL_BUILD和INSTALL(debug和release都选中)
这个过程时间比较长,时长取决于电脑配置,我这里花了30分钟左右(注意,这个过程可能会出现少部分报错),只要完成这个过程没有出现报错应该就没有问题了
右键电脑点击属性,在弹出的窗口中找到高级系统设置
在弹出的窗口中选择环境变量
在系统变量中找到path,点击编辑
新建一个路径,将之前CMake设置的build目录D:\study_soft\opencv\opencv420\build\install\x64\vc16\bin,确定后退出
右键项目,点击属性
首先将配置右边两系那个项设置为 所有配置 所以平台
点击配置属性目录下的VC++目录
在其右侧的包含目录中加入两个路径
D:\study_soft\opencv\opencv420\build\install\include\opencv2
D:\study_soft\opencv\opencv420\build\install\include
在其右侧的库目录中加入库路径
D:\study_soft\opencv\opencv420\build\install\x64\vc16\lib
确定后退出属性
再次打开属性添加附加依赖项
配置也要配置为所有配置和所有平台
将以下文件名拷贝至附加依赖项
//debug所需
opencv_aruco410d.lib
opencv_bgsegm410d.lib
opencv_bioinspired410d.lib
opencv_calib3d410d.lib
opencv_ccalib410d.lib
opencv_core410d.lib
opencv_datasets410d.lib
opencv_dnn410d.lib
opencv_dnn_objdetect410d.lib
opencv_dpm410d.lib
opencv_face410d.lib
opencv_features2d410d.lib
opencv_flann410d.lib
opencv_fuzzy410d.lib
opencv_gapi410d.lib
opencv_hfs410d.lib
opencv_highgui410d.lib
opencv_imgcodecs410d.lib
opencv_imgproc410d.lib
opencv_img_hash410d.lib
opencv_line_descriptor410d.lib
opencv_ml410d.lib
opencv_objdetect410d.lib
opencv_optflow410d.lib
opencv_phase_unwrapping410d.lib
opencv_photo410d.lib
opencv_plot410d.lib
opencv_quality410d.lib
opencv_reg410d.lib
opencv_rgbd410d.lib
opencv_saliency410d.lib
opencv_shape410d.lib
opencv_stereo410d.lib
opencv_stitching410d.lib
opencv_structured_light410d.lib
opencv_superres410d.lib
opencv_surface_matching410d.lib
opencv_text410d.lib
opencv_tracking410d.lib
opencv_video410d.lib
opencv_videoio410d.lib
opencv_videostab410d.lib
opencv_xfeatures2d410d.lib
opencv_ximgproc410d.lib
opencv_xobjdetect410d.lib
opencv_xphoto410d.lib
//release所需
opencv_aruco410.lib
opencv_bgsegm410.lib
opencv_bioinspired410.lib
opencv_calib3d410.lib
opencv_ccalib410.lib
opencv_core410.lib
opencv_datasets410.lib
opencv_dnn410.lib
opencv_dnn_objdetect410.lib
opencv_dpm410.lib
opencv_face410.lib
opencv_features2d410.lib
opencv_flann410.lib
opencv_fuzzy410.lib
opencv_gapi410.lib
opencv_hfs410.lib
opencv_highgui410.lib
opencv_imgcodecs410.lib
opencv_imgproc410.lib
opencv_img_hash410.lib
opencv_line_descriptor410.lib
opencv_ml410.lib
opencv_objdetect410.lib
opencv_optflow410.lib
opencv_phase_unwrapping410.lib
opencv_photo410.lib
opencv_plot410.lib
opencv_quality410.lib
opencv_reg410.lib
opencv_rgbd410.lib
opencv_saliency410.lib
opencv_shape410.lib
opencv_stereo410.lib
opencv_stitching410.lib
opencv_structured_light410.lib
opencv_superres410.lib
opencv_surface_matching410.lib
opencv_text410.lib
opencv_tracking410.lib
opencv_video410.lib
opencv_videoio410.lib
opencv_videostab410.lib
opencv_xfeatures2d410.lib
opencv_ximgproc410.lib
opencv_xobjdetect410.lib
opencv_xphoto410.lib
确定后退出
这里通过使用opencv开源库显示手机相机拍摄的鼠标特征点(采用orb方式)来验证环境搭建是否成功,如若编译后无误并且成功在窗口中显示图片特征点则说明环境搭建成功。
#include
#include
//#include
using namespace std;
using namespace cv;
int main()
{
cv::Mat imageL = cv::imread("C:\\Users\\86151\\Desktop\\shubaio.jpg");//图片的路径(都要改成双斜杠)
cv::Ptr<cv::ORB> orb = cv::ORB::create();
std::vector<cv::KeyPoint> keyPointL;
//单独提取特征点
orb->detect(imageL, keyPointL);
//画特征点
cv::Mat keyPointImageL;
drawKeypoints(imageL, keyPointL, keyPointImageL, cv::Scalar::all(-1), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
//显示窗口
cv::namedWindow("鼠标特征带点");
//显示特征点
cv::imshow("鼠标特征带点", keyPointImageL);
cv::waitKey(0);
return 0;
}
编译后出现
opencv_contrib安装笔记
opencv3.0中contrib模块的添加