windows10 vs2019 版本:cmake将 opencv_contrib-4.5.5 扩展模块编译添加到 opencv-4.5.5 正式版中

******  opencv-4.5.5 和 opencv_contrib-4.5.5 区别

opencv-4.5.5:包含常用的稳定的视觉与图像的算法模块。

opencv_contrib-4.5.5:收录一些具有专利的算法(如SURF)以及一些还没有稳定的算法模块(如ARUCO)。

环境准备:window10+vs2019+opencv-4.5.5+opencv_contrib-4.5.5+cmake

vs2019下载地址:https://www.onlinedown.net/soft/1226702.htm

opencv 主页:https://github.com/opencv

opencv-4.5.5源码下载:https://github.com/opencv/opencv/tree/4.5.5

 opencv_contrib源码下载:https://github.com/opencv/opencv_contrib/tree/4.5.5

 cmake下载:https://cmake.org/download/

下载的文件目录如下:

一.  准备文件

1. 双击 cmake-3.24.0-rc2-windows-x86_64 安装cmake,并将安装路径:C:\Program Files\CMake\bin 添加到系统变量中

 2. 解压 opencv_contrib-4.5.5.zip 和  opencv-4.5.5.zip 到当前文件夹,并创建一个新的文件夹opencv-build 用来存放两者编译合并后的文件

 二.  编译opencv和opencv_contrib

1. 打开cmake ,填写opencv-4.5.5 路径以及 opencv-build 路径

2. 点击Configure 按钮,弹出对话框,选择所安装visual studio 版本(vs2019),选择use default native compilers ,点击finish 开始编译(编译的时候尽量连接稳定的网络)

 **** 会出现很多红色的话,就再点击一次Configure

 成功后,显示configuring done

3. 开始添加 opencv_contrib-4.5.5 ,并配置

1)在搜索框搜索OPENCV_EXTRA_MODULES_PATH ,并点击右侧选取opencv_contrib-4.5.5路径;

2)在搜索框搜索OPENCV_ENABLE_NONFREE(如果没有选中,那么类似SIFT这种已经被申请专利的方法就无法使用),并打上对号

 3)点击 Configure ,如果显示红色,再次点击Configure,显示全白色后,点击Generate,成功后,显示configuring done Generating done

 4. vs2019 编译

1)点击cmake 对话框中的Open Project

 2)点击生成->批生成

 3) 勾选 ALL BUILD  以及INSTALL 两组,点击右侧生成并持续等待生成完成

 4)  生成完成后 opencv-build 文件夹下会产生install的文件夹,就是添加了opencv_contrib 扩展模块后的 opencv 库

  三.  配置opencv 环境变量,并将opencv 添加到vs2019中使用(将opencv-build移到了D盘

1)将opencv-build 添加到系统变量中:D:\ProgramData\opencv-build\install\x64\vc16\bin

2)打开vs2019 新建-项目-空项目,切换成release x64 (也可以选择所有配置,即为所有项目都添加opencv 链接),点击项目-属性 

3)点击VC++目录,编辑包含目录和库目录

包含目录:

D:\ProgramData\opencv-build\install\include\

D:\ProgramData\opencv-build\install\include\opencv2

 库目录:D:\ProgramData\opencv-build\install\x64\vc16\lib 

 4)在链接器-输入,编辑附加依赖项

路径:D:\ProgramData\opencv-build\install\x64\vc16\lib

如果是Release x64 就填入opencv_xxx.lib 

opencv_aruco455.lib
opencv_barcode455.lib
opencv_bgsegm455.lib
opencv_bioinspired455.lib
opencv_calib3d455.lib
opencv_ccalib455.lib
opencv_core455.lib
opencv_datasets455.lib
opencv_dnn455.lib
opencv_dnn_objdetect455.lib
opencv_dnn_superres455.lib
opencv_dpm455.lib
opencv_face455.lib
opencv_features2d455.lib
opencv_flann455.lib
opencv_fuzzy455.lib
opencv_gapi455.lib
opencv_hfs455.lib
opencv_highgui455.lib
opencv_imgcodecs455.lib
opencv_imgproc455.lib
opencv_img_hash455.lib
opencv_intensity_transform455.lib
opencv_line_descriptor455.lib
opencv_mcc455.lib
opencv_ml455.lib
opencv_objdetect455.lib
opencv_optflow455.lib
opencv_phase_unwrapping455.lib
opencv_photo455.lib
opencv_plot455.lib
opencv_quality455.lib
opencv_rapid455.lib
opencv_reg455.lib
opencv_rgbd455.lib
opencv_saliency455.lib
opencv_shape455.lib
opencv_stereo455.lib
opencv_stitching455.lib
opencv_structured_light455.lib
opencv_superres455.lib
opencv_surface_matching455.lib
opencv_text455.lib
opencv_tracking455.lib
opencv_video455.lib
opencv_videoio455.lib
opencv_videostab455.lib
opencv_wechat_qrcode455.lib
opencv_xfeatures2d455.lib
opencv_ximgproc455.lib
opencv_xobjdetect455.lib
opencv_xphoto455.lib

 如果是Debug x64 就填入opencv_xxxd.lib

opencv_aruco455d.lib
opencv_barcode455d.lib
opencv_bgsegm455d.lib
opencv_bioinspired455d.lib
opencv_calib3d455d.lib
opencv_ccalib455d.lib
opencv_core455d.lib
opencv_datasets455d.lib
opencv_dnn455d.lib
opencv_dnn_objdetect455d.lib
opencv_dnn_superres455d.lib
opencv_dpm455d.lib
opencv_face455d.lib
opencv_features2d455d.lib
opencv_flann455d.lib
opencv_fuzzy455d.lib
opencv_gapi455d.lib
opencv_hfs455d.lib
opencv_highgui455d.lib
opencv_imgcodecs455d.lib
opencv_imgproc455d.lib
opencv_img_hash455d.lib
opencv_intensity_transform455d.lib
opencv_line_descriptor455d.lib
opencv_mcc455d.lib
opencv_ml455d.lib
opencv_objdetect455d.lib
opencv_optflow455d.lib
opencv_phase_unwrapping455d.lib
opencv_photo455d.lib
opencv_plot455d.lib
opencv_quality455d.lib
opencv_rapid455d.lib
opencv_reg455d.lib
opencv_rgbd455d.lib
opencv_saliency455d.lib
opencv_shape455d.lib
opencv_stereo455d.lib
opencv_stitching455d.lib
opencv_structured_light455d.lib
opencv_superres455d.lib
opencv_surface_matching455d.lib
opencv_text455d.lib
opencv_tracking455d.lib
opencv_video455d.lib
opencv_videoio455d.lib
opencv_videostab455d.lib
opencv_wechat_qrcode455d.lib
opencv_xfeatures2d455d.lib
opencv_ximgproc455d.lib
opencv_xobjdetect455d.lib
opencv_xphoto455d.lib

 5)在项目中,添加opencv 头文件

#include <opencv2/core/utility.hpp>
#include <opencv2/aruco.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/calib3d.hpp>

如果没有红色波浪线,ctrl +鼠标点击,可以跳转,说明添加成功。

6)检测是否加入 opencv_contrib-4.5.5扩展模块(该模块还有aruco 算法),下面code 如果可以正常运行,则添加正确

#include <opencv2/highgui.hpp>
#include <opencv2/aruco.hpp>

using namespace cv;

int main(int argc, char *argv[]) {

    Mat markerImage;
    Ptr<cv::aruco::Dictionary> dictionary = aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);

    aruco::drawMarker(dictionary, 33, 200, markerImage, 1);

    imwrite("marker33.png", markerImage);

}

评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值