Aruco标识码在视频检测中的应用

2020-12-28  本文已影响0人  gaoshine

Aruco标识码在视频检测中的应用

在许多计算机视觉应用程序中,姿势估计非常重要:机器人导航,增强现实等等。 该过程基于发现真实环境中的点与其2d图像投影之间的对应关系。 这通常是一个困难的步骤,因此通常使用合成或基准标记来简化操作。

最受流行的方法之一是使用二进制方形基准标记。 这些标记的主要优点是单个标记可提供足够的对应关系(四个角)来获得相机的姿势。 而且,内部二进制编码使它们特别强大,从而允许应用错误检测和纠正技术。

与AprilTags相似,ArUco标记是计算机视觉算法可以轻松检测到的2D二进制模式。

通常,我们将AprilTags和ArUco标记用于:

image

0.Aruco码

ArUco标记是一个合成的正方形标记,由宽的黑色边框和确定其标识符(id)的内部二进制矩阵组成。 黑色边框有助于其在图像中的快速检测,并且二进制编码允许其识别以及错误检测和纠正技术的应用。 标记大小决定内部矩阵的大小。 例如,标记大小4x4由16位组成。

Aruco码例子

这些词典中的大多数遵循特定的命名约定cv2.aruco.DICT_NxN_M,其大小为NxN,后跟一个整数M,但这些值是什么意思?

1. 生成aruco码

明白了上边的道理,下面我们使用代码生成需要的aruco码.

arucoDict 是上边的字典
id 是ArUco ID
比如我们使用 "DICT_5X5_50",生产一个id是24的aruco码.

arucoDict = "DICT_5X5_50"
id = 24

tag = np.zeros((300, 300, 1), dtype="uint8")
cv2.aruco.drawMarker(arucoDict, id, 300, tag, 1)


cv2.imwrite("mycode.jpg", tag)
cv2.imshow("ArUCo Tag", tag)
cv2.waitKey(0)

image

看代码还是很简单的,aruco库已经整合到opencv的库里了,直接可以使用.

2. 检测识别aruco码

识别aruco码标识还是比较方便的,opencv的aruco lib已将集成了函数.


image

通过cv2.aruco子模块,使用OpenCV检测ArUco标记的过程分为三个步骤:

# load the input image from disk and resize it
print("[INFO] loading image...")
image = cv2.imread(args["image"])
image = imutils.resize(image, width=600)
# verify that the supplied ArUCo tag exists and is supported by
# OpenCV
if ARUCO_DICT.get(args["type"], None) is None:
    print("[INFO] ArUCo tag of '{}' is not supported".format(
        args["type"]))
    sys.exit(0)
# load the ArUCo dictionary, grab the ArUCo parameters, and detect
# the markers
print("[INFO] detecting '{}' tags...".format(args["type"]))
arucoDict = cv2.aruco.Dictionary_get(ARUCO_DICT[args["type"]])
arucoParams = cv2.aruco.DetectorParameters_create()
(corners, ids, rejected) = cv2.aruco.detectMarkers(image, arucoDict,
    parameters=arucoParams)
    
    
# verify *at least* one ArUco marker was detected
if len(corners) > 0:
    # flatten the ArUco IDs list
    ids = ids.flatten()
    # loop over the detected ArUCo corners
    for (markerCorner, markerID) in zip(corners, ids):
        # extract the marker corners (which are always returned in
        # top-left, top-right, bottom-right, and bottom-left order)
        corners = markerCorner.reshape((4, 2))
        (topLeft, topRight, bottomRight, bottomLeft) = corners
        # convert each of the (x, y)-coordinate pairs to integers
        topRight = (int(topRight[0]), int(topRight[1]))
        bottomRight = (int(bottomRight[0]), int(bottomRight[1]))
        bottomLeft = (int(bottomLeft[0]), int(bottomLeft[1]))
        topLeft = (int(topLeft[0]), int(topLeft[1]))
        
        
        # draw the bounding box of the ArUCo detection
        cv2.line(image, topLeft, topRight, (0, 255, 0), 2)
        cv2.line(image, topRight, bottomRight, (0, 255, 0), 2)
        cv2.line(image, bottomRight, bottomLeft, (0, 255, 0), 2)
        cv2.line(image, bottomLeft, topLeft, (0, 255, 0), 2)
        # compute and draw the center (x, y)-coordinates of the ArUco
        # marker
        cX = int((topLeft[0] + bottomRight[0]) / 2.0)
        cY = int((topLeft[1] + bottomRight[1]) / 2.0)
        cv2.circle(image, (cX, cY), 4, (0, 0, 255), -1)
        # draw the ArUco marker ID on the image
        cv2.putText(image, str(markerID),
            (topLeft[0], topLeft[1] - 15), cv2.FONT_HERSHEY_SIMPLEX,
            0.5, (0, 255, 0), 2)
        print("[INFO] ArUco marker ID: {}".format(markerID))
        # show the output image
        cv2.imshow("Image", image)
        cv2.waitKey(0)


    

image

3.应用

我们使用aruco标识码,做了一个小测试.

aruco.gif aruco2.gif
上一篇 下一篇

猜你喜欢

热点阅读