| Apriltag标签: AprilTag是一个视觉基准库,在AR,机器人,相机校准领域广泛使用。通过特定的标志(与二维码相似,但是降低了复杂度以满足实时性要求),可以快速地检测标志,并计算相对位置。
 相对于二维码,通过AprilTag检测程序可以计算相对于相机的精确3D位置,方向和id。
 
 MaixPy IDE 中在工具-》机器视觉选择中有不同码的生成
 种类
 
 AprilTag的种类叫家族(family),有下面的几种: TAG16H5 → 0 to 29TAG25H7 → 0 to 241
 TAG25H9 → 0 to 34
 TAG36H10 → 0 to 2319
 TAG36H11 → 0 to 586
 ARTOOLKIT → 0 to 511
 代码: 复制代码import sensor, image, time, math,lcd
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA) 
sensor.skip_frames(30)
sensor.set_auto_gain(False) 
sensor.set_auto_whitebal(False)
clock = time.clock()
lcd.init()
while(True):
      clock.tick()
      lcd.rotation(2)
      img = sensor.snapshot()
      for tag in img.find_apriltags(families=image.TAG16H5):
           img.draw_rectangle(tag.rect(), color = (255, 0, 0))
           img.draw_cross(tag.cx(), tag.cy(), color = (0, 255, 0))
           degress = 180 * tag.rotation() / math.pi
           print(tag.id(),degress)
           a=img.draw_string(0, 0, "id:%d"%(tag.id()), color=(0,0,0), scale=2)
           lcd.display(a)
    lcd.display(img)
 注意:img.find_apriltags()函数默认的是TAG36H11,可以在函数里添加families=image.XXXXXXX来识别自己需要的Apriltag标签 二维码: 二维码又称二维条码,常见的二维码为QR Code,QR全称Quick Response,是一个近几年来移动设备上超流行的一种编码方式,它比传统的Bar Code条形码能存更多的信息,也能表示更多的数据类型。 复制代码import sensor
import machine
import image
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.run(1)
sensor.skip_frames(10)
sensor.set_hmirror(0)
while True:
    img = sensor.snapshot()
    code = img.find_qrcodes([0,0,320,240])
    for i in code:
         code_text = i.payload()
         print(code_text)
 
 
 
 |