Welcome to Jetson AGX Thor repository
03.Machine Code Recognition
Machine Code Recognition
Machine Code RecognitionHardware ConnectionInstall Driver Libraries例程代码Running the ProgramProgram Output
Hardware Connection
Plug the USB camera into the motherboard's USB port. Open the system terminal and enter the following command to check the camera's device number. If /dev/video0 appears, it's normal.
ls /dev/video*

Install Driver Libraries
xxxxxxxxxxsudo apt install libzbar-devsudo pip3 install pyzbar --break-system-packagessudo pip3 install pupil-apriltags --break-system-packages
例程代码
xfrom pupil_apriltags import Detectorimport cv2 as cvfrom pyzbar.pyzbar import decodeimport timeimport numpy as npfrom PIL import Image, ImageDraw, ImageFont# Create a detector instance (parameters can be specified)at_detector = Detector(families="tag36h11", # Specify Tag Familynthreads=1,quad_decimate=1.0,quad_sigma=0.0,refine_edges=1,decode_sharpening=0.25,debug=0)def decodeDisplay(image):gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)# Perform Detectionresults = at_detector.detect(gray)for tag in results:# 提取机器码的边界框的位置# Extract the position of the boundary box of the apriltag(c1, c2, c3, c4) = tag.cornersx = int(c4[0])y = int(c4[1])x1 = int(c2[0])y1 = int(c2[1])cv.rectangle(image, (x, y), (x1, y1), (225, 0, 0), 5)# 绘出图像上数据和类型# Draw the data and type on the imagepilimg = Image.fromarray(image)# 创建画笔# create brushdraw = ImageDraw.Draw(pilimg)# # 参数1:打印坐标,参数2:文本,参数3:字体颜色# Parameter 1: print coordinates, parameter 2: text, parameter 3: font colortext = str(tag.tag_family).lstrip('b\'').rstrip('\'') + ' - ' + str(tag.tag_id)draw.text((x, y - 40), text, fill=(255, 0, 0))# 绘出标签码的中心点# Draw the center of the apriltagtag_center = tag.centerradius = 5draw.ellipse([(tag_center[0]-radius, tag_center[1]-radius), (tag_center[0]+radius, tag_center[1]+radius)], fill="red")# # PIL图片转cv2 图片# PIL picture to CV2 pictureimage = cv.cvtColor(np.array(pilimg), cv.COLOR_RGB2BGR)# 向终端打印信息# Print information to terminalprint(f"Tag Family: {tag.tag_family}")print(f"Tag ID: {tag.tag_id}")print(f"Center: {tag.center}")print(f"Corners: {tag.corners}")print("---")return imageif __name__ == '__main__':capture = cv.VideoCapture(0)cv_edition = cv.__version__if cv_edition[0] == '3': capture.set(cv.CAP_PROP_FOURCC, cv.VideoWriter_fourcc(*'XVID'))else: capture.set(cv.CAP_PROP_FOURCC, cv.VideoWriter.fourcc('M', 'J', 'P', 'G'))capture.set(cv.CAP_PROP_FRAME_WIDTH, 640)capture.set(cv.CAP_PROP_FRAME_HEIGHT, 480)print ("capture get FPS : ",capture.get(cv.CAP_PROP_FPS))while capture.isOpened():start = time.time()ret, frame = capture.read()action = cv.waitKey(10) & 0xFFframe = decodeDisplay(frame)end = time.time()fps = 1 / (end - start)text = "FPS : " + str(int(fps))cv.putText(frame, text, (30, 30), cv.FONT_HERSHEY_SIMPLEX, 0.6, (100, 200, 200), 1)cv.imshow('frame', frame)if action == ord('q') or action == 113: breakcapture.release()cv.destroyAllWindows()
Running the Program
Open a desktop terminal and execute the program:
xxxxxxxxxxcd ~/content_recognition/apriltag/python apriltag_parsing_usb.py
Note: Since the program requires a display window to show the video feed, do not run it via a remote SSH terminal. Please run the program using the native desktop environment or a VNC remote desktop session instead.
Program Output
Upon execution, the program automatically activates the USB camera. Simply point the camera at an AprilTag; the program will then automatically frame the tag in the video feed and print its associated information to the terminal.

Sample AprilTag Image:
