VISP中识别AprilTag的C++可运行代码与运行结果

Introduction

***具体解释见下一篇:***VISP中识别AprilTag的C++实例代码解释
***具体帮助开发文档下载:***开发文档

This tutorial shows how to detect one or more AprilTag marker with ViSP. To this end, we provide vpDetectorAprilTag class that is a wrapper over Apriltag 3rd party library. Notice that there is no need to install this 3rd party, since AprilTag source code is embedded in ViSP.
用VISP的话就不用下载AprilTag官方的.c和.cpp文件,VISP中的函数已经集成好了AprilTag的识别定位函数

The vpDetectorAprilTag class inherits from vpDetectorBase class, a generic class dedicated to detection. For each detected tag, it allows retrieving some characteristics such as the tag id, and in the image, the polygon that contains the tag and corresponds to its 4 corner coordinates, the bounding box and the center of gravity of the tag.
具体vpDetectorAprilTag类下载开发文档可以看,里面有集成好的识别和定位函数

Moreover, vpDetectorAprilTag class allows estimating the 3D pose of the tag. To this end, the camera parameters as well as the size of the tag are required.
这个vpDetectorAprilTag类也可以用于识别3D场景下的tag

In the next sections you will find examples that show how to detect tags in a single image or in images acquired from a camera connected to your computer.
下面这一节是一个例子,识别一张电脑中图片中的tag

Note that all the material (source code and image) described in this tutorial is part of ViSP source code and could be downloaded using the following command:
下面的下载地址可以下载源码和图片

$ svn export https://github.com/lagadic/visp.git/trunk/tutorial/detection/tag

也可以自己利用OpenMV生成AprilTag,比较清晰
参考另一篇:OpenMV生成AprilTag码

Print an AprilTag marker

官方介绍的是UNIX系统中打印的方法,其实下载好了之后自己编辑一下用打印机打印就行。

AprilTag detection and pose estimation (single image)

#include <visp3/detection/vpDetectorAprilTag.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/io/vpImageIo.h>
#include <visp3/core/vpXmlParserCamera.h>int main(int argc, const char **argv)
{
#if defined(VISP_HAVE_APRILTAG) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV))std::string input_filename = "AprilTag.pgm";vpDetectorAprilTag::vpAprilTagFamily tagFamily = vpDetectorAprilTag::TAG_36h11;vpDetectorAprilTag::vpPoseEstimationMethod poseEstimationMethod = vpDetectorAprilTag::HOMOGRAPHY_VIRTUAL_VS;double tagSize = 0.053;float quad_decimate = 1.0;int nThreads = 1;std::string intrinsic_file = "";std::string camera_name = "";bool display_tag = false;int color_id = -1;unsigned int thickness = 2;bool z_aligned = false;for (int i = 1; i < argc; i++) {if (std::string(argv[i]) == "--pose_method" && i + 1 < argc) {poseEstimationMethod = (vpDetectorAprilTag::vpPoseEstimationMethod)atoi(argv[i + 1]);} else if (std::string(argv[i]) == "--tag_size" && i + 1 < argc) {tagSize = atof(argv[i + 1]);} else if (std::string(argv[i]) == "--input" && i + 1 < argc) {input_filename = std::string(argv[i + 1]);} else if (std::string(argv[i]) == "--quad_decimate" && i + 1 < argc) {quad_decimate = (float)atof(argv[i + 1]);} else if (std::string(argv[i]) == "--nthreads" && i + 1 < argc) {nThreads = atoi(argv[i + 1]);} else if (std::string(argv[i]) == "--intrinsic" && i + 1 < argc) {intrinsic_file = std::string(argv[i + 1]);} else if (std::string(argv[i]) == "--camera_name" && i + 1 < argc) {camera_name = std::string(argv[i + 1]);} else if (std::string(argv[i]) == "--display_tag") {display_tag = true;} else if (std::string(argv[i]) == "--color" && i + 1 < argc) {color_id = atoi(argv[i + 1]);} else if (std::string(argv[i]) == "--thickness" && i + 1 < argc) {thickness = (unsigned int)atoi(argv[i + 1]);} else if (std::string(argv[i]) == "--tag_family" && i + 1 < argc) {tagFamily = (vpDetectorAprilTag::vpAprilTagFamily)atoi(argv[i + 1]);} else if (std::string(argv[i]) == "--z_aligned") {z_aligned = true;} else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {std::cout << "Usage: " << argv[0]<< " [--input <input file>] [--tag_size <tag_size in m>]"" [--quad_decimate <quad_decimate>] [--nthreads <nb>]"" [--intrinsic <intrinsic file>] [--camera_name <camera name>]"" [--pose_method <method> (0: HOMOGRAPHY, 1: HOMOGRAPHY_VIRTUAL_VS, "" 2: DEMENTHON_VIRTUAL_VS, 3: LAGRANGE_VIRTUAL_VS, "" 4: BEST_RESIDUAL_VIRTUAL_VS, 5: HOMOGRAPHY_ORTHOGONAL_ITERATION) (default: 0)]"" [--tag_family <family> (0: TAG_36h11, 1: TAG_36h10 (DEPRECATED), 2: TAG_36ARTOOLKIT (DEPRECATED),"" 3: TAG_25h9, 4: TAG_25h7 (DEPRECATED), 5: TAG_16h5, 6: TAG_CIRCLE21h7, 7: TAG_CIRCLE49h12,"" 8: TAG_CUSTOM48h12, 9: TAG_STANDARD41h12, 10: TAG_STANDARD52h13) (default: 0)]"" [--display_tag] [--color <color_id (0, 1, ...)>]"" [--thickness <thickness>] [--z_aligned]"" [--help]"<< std::endl;return EXIT_SUCCESS;}}vpCameraParameters cam;cam.initPersProjWithoutDistortion(615.1674805, 615.1675415, 312.1889954, 243.4373779);vpXmlParserCamera parser;if (!intrinsic_file.empty() && !camera_name.empty())parser.parse(cam, intrinsic_file, camera_name, vpCameraParameters::perspectiveProjWithoutDistortion);std::cout << cam << std::endl;std::cout << "poseEstimationMethod: " << poseEstimationMethod << std::endl;std::cout << "tagFamily: " << tagFamily << std::endl;std::cout << "nThreads : " << nThreads << std::endl;std::cout << "Z aligned: " << z_aligned << std::endl;try {vpImage<unsigned char> I;vpImageIo::read(I, input_filename);#ifdef VISP_HAVE_X11vpDisplayX d(I);
#elif defined(VISP_HAVE_GDI)vpDisplayGDI d(I);
#elif defined(VISP_HAVE_OPENCV)vpDisplayOpenCV d(I);
#endifvpDetectorAprilTag detector(tagFamily);detector.setAprilTagQuadDecimate(quad_decimate);detector.setAprilTagPoseEstimationMethod(poseEstimationMethod);detector.setAprilTagNbThreads(nThreads);detector.setDisplayTag(display_tag, color_id < 0 ? vpColor::none : vpColor::getColor(color_id), thickness);detector.setZAlignedWithCameraAxis(z_aligned);vpDisplay::display(I);double t = vpTime::measureTimeMs();std::vector<vpHomogeneousMatrix> cMo_vec;detector.detect(I, tagSize, cam, cMo_vec);t = vpTime::measureTimeMs() - t;std::stringstream ss;ss << "Detection time: " << t << " ms for " << detector.getNbObjects() << " tags";vpDisplay::displayText(I, 40, 20, ss.str(), vpColor::red);for (size_t i = 0; i < detector.getNbObjects(); i++) {std::vector<vpImagePoint> p = detector.getPolygon(i);vpRect bbox = detector.getBBox(i);vpDisplay::displayRectangle(I, bbox, vpColor::green);std::string message = detector.getMessage(i);std::size_t tag_id_pos = message.find("id: ");if (tag_id_pos != std::string::npos) {int tag_id = atoi(message.substr(tag_id_pos + 4).c_str());ss.str("");ss << "Tag id: " << tag_id;vpDisplay::displayText(I, (int)(bbox.getTop() - 10), (int)bbox.getLeft(), ss.str(), vpColor::red);}for (size_t j = 0; j < p.size(); j++) {vpDisplay::displayCross(I, p[j], 14, vpColor::red, 3);std::ostringstream number;number << j;vpDisplay::displayText(I, p[j] + vpImagePoint(15, 5), number.str(), vpColor::blue);}}vpDisplay::displayText(I, 20, 20, "Click to display tag poses", vpColor::red);vpDisplay::flush(I);vpDisplay::getClick(I);vpDisplay::display(I);for (size_t i = 0; i < cMo_vec.size(); i++) {vpDisplay::displayFrame(I, cMo_vec[i], cam, tagSize / 2, vpColor::none, 3);}vpDisplay::displayText(I, 20, 20, "Click to quit.", vpColor::red);vpDisplay::flush(I);vpDisplay::getClick(I);} catch (const vpException &e) {std::cerr << "Catch an exception: " << e.getMessage() << std::endl;}return EXIT_SUCCESS;
#else(void)argc;(void)argv;return 0;
#endif
}

The default behavior is to detect 36h11 marker in AprilTag.pgm image, but –tag_family option allows considering other tags. To see which are the options, just run:

$ ./tutorial-apriltag-detector --help

To detect multiple 36h11 tags in the AprilTag.pgm image that is provided just run:

$ ./tutorial-apriltag-detector

结果:


点击一下图片:

ViSP中识别AprilTag的C++实例代码与运行结果相关推荐

  1. ViSP中识别AprilTag的C++实例代码解释

    VISP中识别AprilTag的C++实例代码解释 接着上一篇: VISP中识别AprilTag的C++实例代码与运行结果 先展示代码,一句一句解释吧 #include <visp3/detec ...

  2. 批量插入数据库语句java_java相关:MyBatis批量插入数据到Oracle数据库中的两种方式(实例代码)...

    java相关:MyBatis批量插入数据到Oracle数据库中的两种方式(实例代码) 发布于 2020-7-22| 复制链接 本文通过实例代码给大家分享了MyBatis批量插入数据到Oracle数据库 ...

  3. html 存储登录状态,Vue中保存用户登录状态实例代码

    首先我们假设,这里的登录组件(register.vue)是App.vue组件的子组件,是通过路由进入登录组件的. 登录组件中用户点击登录后,后台会传过来一个用户名,我的App.vue组件中需要拿到这个 ...

  4. java get null_java 获取对象中为null的字段实例代码

    下面一段简单的代码给大家分享java 获取对象中为null的字段,具体代码如下所述: private static String[] getNullPropertyNames(Object sourc ...

  5. android 方形按钮代码,Android中实现图文并茂的按钮实例代码

    效果图如下所示: 代码: android:orientation="horizontal" android:layout_width="match_parent" ...

  6. linux shell中实现循环日期的实例代码

    这篇文章主要介绍了linux shell中实现循环日期的实例代码,文中还给大家提到了LINUX SHELL遍历日期(指定输入两个日期)的实现方法,感兴趣的朋友跟随小编一起看看吧 下面通过一段代码给大家 ...

  7. oracle 删除表存过,oracle删除数据库中已存在表的实例代码

    摘要 腾兴网为您分享:oracle删除数据库中已存在表的实例代码,长沙银行,银万财富,图钉,听中国等软件知识,以及土豆app,局域网文件,宝宝学动物,观海听涛bbs,育碧,生男生女预测大师,新先视,信 ...

  8. php模拟红绿灯,JS 中使用Promise 实现红绿灯实例代码(demo)

    本文通过实例代码给大家介绍了JS 中使用Promise 实现红绿灯效果,在文中给大家介绍了一个promise用法例子,不了解js中如何使用Promise的朋友可以参考下本篇文章 要求使用promise ...

  9. java获取图片主色_Java获取彩色图像中的主色彩的实例代码

    本文讲述了java获取彩色图像中的主色彩的实例代码.分享给大家供大家参考,具体如下: 一:基本思路 对于一张rgb色彩空间的彩色图像,很多时间我们想通过程序获得该图像有几种主要的色彩,但是对一般图像来 ...

最新文章

  1. 一文搞懂重复测量资料分析
  2. 页面怎么把关键字保留下来_怎么做seo优化,以及网站SEO优化计划!
  3. java idisposable_在C#中实现IDisposable [重复]
  4. python字母频率_科学网-Python统计字母频数和频率-吕波的博文
  5. linux+模块与设备关系,linux内核设计与实现读书笔记——设备和模块
  6. MDaemon12.X特殊注意事项和新功能
  7. 计算机管理储存u盘无法使用,Win7系统退出U盘后重新插入电脑无法使用怎么办
  8. 液晶拼接处理器_创新维OLED拼接屏施工单位操作说明
  9. DevExpress 隐藏Ribbon中barbuttonItem的SuperTip(2)
  10. jQuery--checkbox全选/取消全选 及checkbox遍历
  11. 【跳频扩频通信】基于matlab跳频扩频通信【含Matlab源码 1003期】
  12. plc和pc串口通讯接线_电脑和PLC连接不上我用的是USB转串口的连接线
  13. 四川途志:短视频营销公司做视频广告投放有技巧吗?
  14. html5 js实现今日头条视频播放列表,Github最火开源项目-高仿今日头条视频列表功能...
  15. 内存卡没有Android,安卓内存卡读不出来怎么办
  16. java mongo gte_java-如何操作$concat使用spring mongodb
  17. SpringBoot 整合Smart-doc生成接口文档
  18. 3.数据仓库之确定粒度
  19. springboot+druid+dynamic-datasource+mysql数据库密码加密
  20. 安装完JDK后没有JRE文件怎么办

热门文章

  1. 硬件开源需求迫切?开源笔电 Nevona 筹款金额达预设目标3倍
  2. iframe父子页面交互
  3. 盘点路由协议之RIP协议及IGRP协议
  4. 一个电脑白痴和***的对话!
  5. 从Web2.0到Enterprise 2.0(三)Enterprise 2.0的三个方向
  6. 最新mysql5.7.12 win64 安装及配置
  7. C++中友元函数和友元类
  8. substr()函数——mysql:截取字符串子串
  9. 如何快速开发一个博客
  10. 【jdk源码分析】ArrayList的size()==0和isEmpty()