- 说在前面
操作系统:win10
vs 版本:2017
opencv版本:4.0.1
opencv-contrb版本:4.0.1
- 编译opencv库
由于aruco并没有直接放在官方的.exe安装包里面,所以要使用的话必须自己编译;笔者是将aruco和opencv放在一块编译的,网上貌似说可以单独编译,木有试过;
相关教程网上有很多,这里提一下一些注意点:
1. 编译可以看看这篇文章:【opencv/编译】Windows编译OpenCV+contrib&坑(内含编译过的库)
opencv版本与contrib版本必须一致;contirb版本在这里
2. 编译完成后需要配置环境变量以及vs链接库和工程库,这部分可以参考浅墨大佬的教程:【OpenCV入门教程之一】 安 装OpenCV:OpenCV 3.0、OpenCV 2.4.8、OpenCV 2.4.9 +VS 开发环境配置
3. 笔者编译完后是x86/release版本,在vs中调试的时候选择对应的版本
4. 编译后若..\opencv\x86\vc15\lib 路径下的lib文件不是以d结尾,生成和调试的时候请改为release;否则可能会出现以下错误
1>artest.obj : error LNK2019: 无法解析的外部符号 "void __cdecl cv::imshow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class cv::debug_build_guard::_InputArray const &)" (?imshow@cv@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV_InputArray@debug_build_guard@1@@Z),该符号在函数 _main 中被引用
1>artest.obj : error LNK2019: 无法解析的外部符号 "void __cdecl cv::aruco::drawMarker(struct cv::Ptr<class cv::aruco::Dictionary> const &,int,int,class cv::debug_build_guard::_OutputArray const &,int)" (?drawMarker@aruco@cv@@YAXABU?$Ptr@VDictionary@aruco@cv@@@2@HHABV_OutputArray@debug_build_guard@2@H@Z),该符号在函数 _main 中被引用
1>D:\Program Files\opencv\proj\artest\Debug\artest.exe : fatal error LNK1120: 2 个无法解析的外部命令
5. 把库文件名贴一下
opencv_flann401.lib
opencv_shape401.lib
opencv_fuzzy401.lib
opencv_stereo401.lib
opencv_gapi401.lib
opencv_stitching401.lib
opencv_hfs401.lib
opencv_structured_light401.lib
opencv_highgui401.lib
opencv_superres401.lib
opencv_imgcodecs401.lib
opencv_surface_matching401.lib
opencv_aruco401.lib
opencv_imgproc401.lib
opencv_text401.lib
opencv_bgsegm401.lib
opencv_img_hash401.lib
opencv_tracking401.lib
opencv_bioinspired401.lib
opencv_line_descriptor401.lib
opencv_video401.lib
opencv_calib3d401.lib
opencv_ml401.lib
opencv_videoio401.lib
opencv_ccalib401.lib
opencv_objdetect401.lib
opencv_videostab401.lib
opencv_core401.lib
opencv_optflow401.lib
opencv_xfeatures2d401.lib
opencv_datasets401.lib
opencv_phase_unwrapping401.lib
opencv_ximgproc401.lib
opencv_dnn401.lib
opencv_photo401.lib
opencv_xobjdetect401.lib
opencv_dnn_objdetect401.lib
opencv_plot401.lib
opencv_xphoto401.lib
opencv_dpm401.lib
opencv_reg401.lib
opencv_face401.lib
opencv_rgbd401.lib
opencv_features2d401.lib
opencv_saliency401.lib
- 第一个demo-create marker
#include <opencv2\highgui.hpp>
#include <opencv2\aruco.hpp>
#include <opencv2\aruco\dictionary.hpp>
#include <vector>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
cv::Mat markerImage;//创建存储marker的Mat对象
cv::aruco::Dictionary mDictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);//创建字典
cv::aruco::drawMarker(&mDictionary, 23, 200, markerImage, 1);//生成marker ID:23 大小200x200像素 存放至Mat对象
imshow("test", markerImage);//显示marker
waitKey();
return 0;
}