Apriltag是一种在机器人研究中流行的视觉基准系统。该存储库包含最新版本的Apriltag Apriltag 3,其中包括更快(> 2X)检测器,提高小标签的检测率,灵活的标签布局和姿势估计。 Apriltag由一个小的C库组成,其依赖性最小。
您可以在此处找到预先生成的布局的标签图像。我们建议使用tagstandard41h12布局。
Apriltag是以下论文的主题。
Apriltag:强大而灵活的视觉基准系统
APRILTAG 2:有效而健壮的基准检测
信托标签的灵活布局
尽管用户在Windows上也成功安装了官方的Linux操作系统,但仅支持Linux操作系统。
默认安装将在/usr/local/include库中放置标题和/usr/local/lib中的共享库。它还将pkg-config脚本安装到/usr/local/lib/pkgconfig中,如果安装了Python3,将安装Python包装器。
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --target install
默认情况下,这将构建共享(*.so)库。如果您需要静态(*.A)库将BUILD_SHARED_LIBS
设置为OFF
:
cmake -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF
cmake --build build --target install
如果已安装了忍者( sudo apt install ninja-build
),则可以使用:
cmake -B build -GNinja -DCMAKE_BUILD_TYPE=Release
cmake --build build --target install
通过忍者构建脚本生成和编译。它的速度要比CMAKE的默认MakeFile发电机快得多。
您可以省略--target install
如果您只想在本地使用此情况而无需安装。
对于绝大多数应用程序,Tagstandard41H12系列将是正确的选择。您可以在Apriltag-Imgs存储库中找到标签的图像。将图像扩展到您喜欢的编辑器中,然后将其打印出来。
一些何时选择其他标签家庭的启发式方法:
如果这些都不适合您的需求,请在此处生成自己的自定义标签家族。
import cv2
import numpy as np
from apriltag import apriltag
imagepath = 'test.jpg'
image = cv2.imread(imagepath, cv2.IMREAD_GRAYSCALE)
detector = apriltag("tagStandard41h12")
detections = detector.detect(image)
或者,您可以使用Duckietown创建的Apriltag Python绑定。
image_u8_t* im = image_u8_create_from_pnm("test.pnm");
if (im == NULL) {
fprintf(stderr, "Failed to load pnm image.n");
exit(1);
}
apriltag_detector_t *td = apriltag_detector_create();
apriltag_family_t *tf = tagStandard41h12_create();
apriltag_detector_add_family(td, tf);
zarray_t *detections = apriltag_detector_detect(td, im);
for (int i = 0; i < zarray_size(detections); i++) {
apriltag_detection_t *det;
zarray_get(detections, i, &det);
// Do stuff with detections here.
}
// Cleanup.
apriltag_detections_destroy(detections);
tagStandard41h12_destroy(tf);
apriltag_detector_destroy(td);
由第三方提供。
由第三方提供
对于大多数用例,这应该是替换的下降。
请注意,该库没有外部依赖关系。大多数应用程序至少需要一种获取图像的方法。
请参阅示例/opencv_demo.cc,以获取与OpenCV中C ++中使用Apriltag的示例。可以通过执行以下操作来构建此示例应用程序:
$ cd examples
$ make opencv_demo
CV :: MAT对象中的图像数据可以传递给Apriltag而不创建深副本。只需为CV :: MAT数据缓冲区创建一个Image_U8_T标题:
cv::Mat img;
image_u8_t img_header = { .width = img.cols,
.height = img.rows,
.stride = img.cols,
.buf = img.data
};
增加quad_decimate参数将以检测距离成本提高检测器的速度。如果您有额外的CPU内核可以解决问题,则可以增加nThreads。如果您的图像有些嘈杂,则增加Quad_sigma参数可以提高速度。
首先选择一个示例图像并使用debug = 1运行检测器以生成调试图像。这些显示了检测管道中每个步骤的检测器的输出。如果标签的边框未被检测为四边形,请降低quad_decimate(如有必要,一直到1)。如果检测到标签的边框,则尝试更改DecoDe_sharpening。
我们提供了一种计算标签姿势如下的方法(或者,将OPENCV的PNP求解器与solvepnp_ippe_square一起使用)。您将需要包含apriltag_pose.h头文件,然后拨打estimate_tag_pose函数如下:
// First create an apriltag_detection_info_t struct using your known parameters.
apriltag_detection_info_t info;
info.det = det;
info.tagsize = tagsize;
info.fx = fx;
info.fy = fy;
info.cx = cx;
info.cy = cy;
// Then call estimate_tag_pose.
apriltag_pose_t pose;
double err = estimate_tag_pose(&info, &pose);
// Do something with pose.
...
参数如下:
det
:标签检测结构(April_detection_t)。tagsize
:标签的大小为米。每个标签设计都有一个黑色边框和一个白色边框,但是有些设计的内部有白色边框,有些设计在内部有黑色边框。因此,标签是从两个边界相遇的位置测量的,请参见下图。fx
, fy
:相机的焦距(以像素为单位)。对于大多数相机, fx
和fy
几乎相等。cx
, cy
:相机的焦点中心(以像素为单位)。对于大多数相机,这将与图像中心大致相同。注意:标签大小不应从标签的外部测量。标签大小定义为检测角之间的距离,或者交替地,白色边框和黑色边框之间的边缘长度。以下图表标记了带有红色XS的检测角和带有红色箭头的标签大小,用于48h12custom标签家族的标签。
坐标系在相机中心具有原点。 Z轴从相机中心指出相机镜头。 X轴位于相机拍摄的图像中的右侧,而y则降低。标签的坐标帧以标签的中心为中心,右侧为X轴,y轴向下,z轴为标签。
您可以通过设置ASAN
选项:
cmake -B build -GNinja -DCMAKE_BUILD_TYPE=Debug -DASAN=ON
cmake --build build
大多数情况下,您可以像往常一样运行可执行文件,并检查疗程器的输出。如果您收到诸如ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.
您必须预加载相应的libasan.so.5
这样:
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.5 ./build/opencv_demo
Apriltag 3除了Apriltag 2中支持的经典布局外,还支持各种可能的标签布局。没有数据位的边界。在此存储库中,我们包括:
您可以使用我们的其他仓库生成自己的标签家庭。
请在此Github上创建问题,以获取任何问题,而不是发送私人消息。这允许其他有相同问题的人找到您的答案。