Welcome to Jetson AGX Orin repository
当製品の日本語版マニュアル資料は、こちらからご取得ください。
03.Machine Code Recognition
Machine Code Recognition
Machine Code RecognitionHardware ConnectionInstall Driver LibrariesExample CodeRunning the ProgramProgram Effect
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.
xxxxxxxxxxls /dev/video*

Install Driver Libraries
xxxxxxxxxxsudo apt install libzbar-devsudo pip3 install pyzbarsudo pip3 install pupil-apriltags
Example Code
xxxxxxxxxxfrom pupil_apriltags import Detectorimport cv2 as cvfrom pyzbar.pyzbar import decodeimport timeimport numpy as npfrom PIL import Image, ImageDraw, ImageFont# 创建检测器实例,可指定参数# Create a detector instance, specifying parameters.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 your desktop terminal and run the program:
xxxxxxxxxx~/content_recognition/apriltag/python apriltag_parsing_usb.py
Note: Because the program requires a display screen, do not run it in a remote SSH terminal. Please use the native desktop or VNC remote desktop to run the program.
Program Effect
After the program runs, it automatically opens the USB camera. Point the camera at the Apriltag machine code, and the machine code will be highlighted and printed in the terminal.

Example Machine Code Image:
