生成单个的二维码,下面给出30cmx30cm打印大小的生成脚本,输入路径直接用 apriltag-imgs 工程的tag36h11系列的图片即可。生成结果得到587个png和pdf格式的二维码。打印成30cmx30cm的即可。
#coding:utf-8
import cv2
import sys
import os
import numpy as np
def png2pdf(img_src_path, img_dst_path, img_dst_path_pdf,num):
pixel_size = 1800
#scale
os.system("convert %s -scale %s %s"%(img_src_path, pixel_size, img_dst_path))
#crop
img = cv2.imread(img_dst_path)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
region = gray[100:1700, 100:1700] #1600*1600
ret, binary = cv2.threshold(region, 127, 255, cv2.THRESH_BINARY|cv2.THRESH_OTSU)
rgb = cv2.cvtColor(binary,cv2.COLOR_GRAY2BGR)
#draw coordinate
rgb = cv2.arrowedLine(rgb, (20, 1580), (80, 1580), (0 ,0, 255), 1)
rgb = cv2.arrowedLine(rgb, (20, 1580), (20, 1520), (0, 255, 0), 1)
#putText
rgb = cv2.putText(rgb,str(num), (30, 1570), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 1, cv2.LINE_AA)
cv2.imwrite(img_dst_path, rgb)
#to pdf
os.system("convert %s %s"%(img_dst_path, img_dst_path_pdf))
if __name__ == "__main__":
if len(sys.argv) !=4:
print("generate_pdf_apriltag.py input_path output_path_png output_path_pdf")
exit(0)
input_path = os.path.abspath(sys.argv[1])
output_path_png = os.path.abspath(sys.argv[2])
output_path_pdf = os.path.abspath(sys.argv[3])
# scale + crop + pdf
img_files = os.listdir(input_path)
idxs = list()
for img_file in img_files:
if img_file.split('.')[1] == 'png':
img_src_path = os.path.join(input_path, img_file)
img_dst_path = os.path.join(output_path_png, img_file)
img_dst_path_pdf = os.path.join(output_path_pdf, img_file.split('.')[0] +'.pdf')
num = int((img_file.split('.')[0]).split('_')[-1])
idxs.append(num)
png2pdf(img_src_path, img_dst_path,img_dst_path_pdf, num)
https://github.com/ethz-asl/kalibr/wiki/calibration-targets
也可以直接下载 6x6的 pdf
kalibr_create_target_pdf --type apriltag --nx [NUM_COLS] --ny [NUM_ROWS] --tsize [TAG_WIDTH_M] --tspace [TAG_SPACING_PERCENT]