Two discussions on Apriltag processing

Introduction: ※ apriltag detection is a relatively simple method based on visual positioning. This paper discusses the effect of homography matrix in apriltag detection results, which is inconsistent with the application that can be directly used to draw apriltag normal vector. The ability of apriltag algorithm pasted on non plane is tested. If pasted on the cylinder, the apriltag can still be detected within a certain angle range.

Key words: Apriltag

 

§ 01 single transformation matrix

   in the Apriltag detection result, the Homography parameter is included, which represents the Homography matrix mapping the points located at the four corners of the origin to the four corners of the detected Apriltag.

▲ Figure 1.1 locate the Apriltag on both sides of the cube at the Apriltag

1.1 two homography matrices

apd = apriltag.Detector(apriltag.DetectorOptions(families='tag25h9'))

for id,imgfile in tqdm(enumerate(filedim)):
    img = cv2.imread(imgfile)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    tags = apd.detect(gray)

   under the above code detection, two tags can be detected, and their homography matrix is:

homo: [[ 6.68676859e-01  3.40896152e-02  2.82713831e+00]
 [-2.10627077e-01  7.71189655e-01  1.91688676e+00]
 [ 8.45537778e-05  7.78231041e-05  5.32189903e-03]]
homo: [[-5.21963542e-01 -3.95455759e-02 -1.49500546e+00]
 [-2.46071422e-01 -8.10661947e-01 -1.95403490e+00]
 [ 1.26923428e-04 -9.26461141e-05 -5.56235094e-03]]

   the positions of the corresponding corrected corners can be obtained by inverse mapping the four corners with the homography matrix:

        corner = ones((4,3), float32)
        corner[:,:2] = tag.corners

        inv_c = linalg.inv(homo).dot(corner.T)
        print("inv_c.T:\n{}".format(inv_c.T))
inv_c.T:
[[-193.81639822 -193.81639822  193.81639822]
 [ 187.66550781 -187.66550781  187.66550781]
 [ 182.3394766   182.3394766   182.3394766 ]
 [-188.14079484  188.14079484  188.14079485]]
inv_c.T:
[[ 178.67901064  178.67901064 -178.67901064]
 [-187.16842875  187.16842875 -187.16842874]
 [-180.89484096 -180.89484096 -180.89484096]
 [ 172.9529146  -172.9529146  -172.9529146 ]]

1.2 mapping from origin

    if you set the point at (0,0) and different z values, can you obtain the position of the original Apriltag center point by using the inverse mapping of geometry.

        inv_c = linalg.inv(homo).dot(corner.T)
        print("inv_c.T:\n{}".format(inv_c.T))

        for f in arange(0.1, 2, 0.05):
            c0 = array([0,0, mean(inv_c.T, axis=0)[-1]*f])
            c0_inv = homo.dot(c0)
            for c in tag.corners:
                cv2.circle(img, tuple(c.astype(int)), 4, (0,0,255),2)
            cv2.circle(img, tuple(tag.center.astype(int)), 8, (0, 100, 20), 4)
            cv2.circle(img, tuple(c0_inv[:2].astype(int)), 8, (0, 00, 255), 8)
            cv2.line(img, tuple(c0_inv[:2].astype(int)), tuple(tag.center.astype(int)), (200, 0,0), 3)

    break

    giffile = os.path.join(gifpath, '%03d.JPG'%id)
    cv2.imwrite(giffile, img)

▲ figure 1.2.1 obtain the trajectory by performing homography conversion from different heights of (0,0)

   the above mapping shows that we originally wanted to obtain a normal vector perpendicular to the center of the Apriltag, but in fact, we didn't get it. At least the Apriltag on the left does not correspond to such a mapping.

                  .

 

§ 02 Apriltag on cylinder

   if the Apriltag is no longer on a plane, but on a cylinder, can it be identified?

  test below.

▲ figure 2.1 Apriltag attached to cylinder

2.1 treatment results

2.1.1 processing code

from headm import *                 # =
import apriltag
import cv2

filename = '/home/aistudio/work/apcol.jpg'

img = cv2.imread(filename)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

atd = apriltag.Detector(apriltag.DetectorOptions(families='tag36h11 tag25h9'))
tags = atd.detect(gray)

printt(tags:)

for tag in tags:
    for c in tag.corners:
        cv2.circle(img, tuple(c.astype(int)), 8, (255,0,0), 3)
    cv2.circle(img, tuple(tag.center.astype(int)), 8, (255,0,0),4)

plt.clf()
plt.figure(figsize=(10,10))
plt.axis("off")
plt.imshow(img)

2.1.2 identification results

tags: [Detection(tag_family=b'tag25h9', tag_id=0, hamming=1, goodness=0.0, decision_margin=83.2973403930664, homography=array([[6.94448482e-01, 4.13404455e-02, 1.53937712e+00],
       [3.06866462e-02, 7.49597594e-01, 1.49692939e+00],
       [3.48276471e-06, 7.46954292e-05, 3.75277229e-03]]), center=array([410.19731493, 398.88628287]), corners=array([[218.68760681, 195.02702332],
       [595.53161621, 211.32849121],
       [593.89074707, 594.42523193],
       [231.76583862, 579.45843506]]))]

▲ figure 2.1.1 Apriltag identification results

2.2 identification results of different angles

   rotate the cylinder pasted with Apriltag for one week. Test the angle at which the Apriltag can be recognized. It can be seen that the algorithm can also detect the Apriltag when there are only a few in the middle.

▲ figure 2.1.2 Apriltag rotated for one cycle
▲ figure 2.2.1 can detect Apriltag

 

※ general ※ conclusion ※

   apriltag detection is a relatively simple method based on visual positioning. This paper discusses the effect of homography matrix in apriltag detection results, which is inconsistent with the application that can be directly used to draw apriltag normal vector. The ability of apriltag algorithm pasted on non plane is tested. If pasted on the cylinder, the apriltag can still be detected within a certain angle range.

● relevant chart links:

Keywords: Algorithm Computer Vision image processing

Added by who_cares on Mon, 03 Jan 2022 07:28:53 +0200