openmv之ApriTag


 

AprilTag是一個視覺基准系統,可用於各種任務,包括AR,機器人和相機校准。這個tag可以直接用打印機打印出來,而AprilTag檢測程序可以計算相對於相機的精確3D位置,方向和id。對於OpenMV來說,這個特別有用! 它大概長這個樣子:

 

 

AprilTag的種類

AprilTag的種類叫家族(family),有下面的幾種:

TAG16H5 → 0 to 29
TAG25H7 → 0 to 241
TAG25H9 → 0 to 34
TAG36H10 → 0 to 2319
TAG36H11 → 0 to 586
ARTOOLKIT → 0 to 511
也就是說TAG16H5的家族(family)有30個,每一個都有對應的id,從0~29。

那么不同的家族,有什么區別呢?

比如說TAG16H5的有效區域是4 x 4的方塊,那么它比TAG36H11看的更遠(因為他有6 x 6個方塊)。但是TAG16H5的錯誤率比TAG36H11高很多,因為TAG36H11的校驗信息多,所以,如果沒有別的理由,推薦用TAG36H11。

 

這些圖像可以在網絡下載也可以在openmv的IDE中生成

 1 # AprilTags Example
 2 #
 3 # This example shows the power of the OpenMV Cam to detect April Tags
 4 # on the OpenMV Cam M7. The M4 versions cannot detect April Tags.
 5 
 6 import sensor, image, time, math
 7 
 8 sensor.reset()
 9 sensor.set_pixformat(sensor.RGB565)
10 sensor.set_framesize(sensor.QQVGA) # we run out of memory if the resolution is much bigger...
11 sensor.skip_frames(30)
12 sensor.set_auto_gain(False)  # must turn this off to prevent image washout...
13 sensor.set_auto_whitebal(False)  # must turn this off to prevent image washout...
14 clock = time.clock()
15 
16 while(True):
17     clock.tick()
18     img = sensor.snapshot()
19     for tag in img.find_apriltags(): # defaults to TAG36H11 without "families".
20         img.draw_rectangle(tag.rect(), color = (255, 0, 0))
21         img.draw_cross(tag.cx(), tag.cy(), color = (0, 255, 0))
22         degress = 180 * tag.rotation() / math.pi
23         print(tag.id(),degress)

 

第8行初始化攝像頭

第9行設置圖像格式為RGB565

第10行時QQVGA圖像的格式

第11行跳過30秒,使新設置生效

第12行關閉自動增益。默認開啟的,在顏色時別中一定要關閉

第13行關閉白平衡,默認開啟,在顏色時別中一定要關閉

第14行追蹤幀率

第18行從感光芯片獲得一張圖像

第19行在圖片中找到家族中的圖像

第20行畫方框,draw_rectangle((x,y,w,h) , color = White)該函數的參數,x,y是方框的左上角的坐標,w,h是寬和高

  tag.rect()

  apriltag.rect()方法

  返回一個矩形元組(x, y, w, h),用於如AprilTag邊界框的 image.draw_rectangle 等其他的 image 方法。

  color為方框的顏色

第21行draw_cross(x,y,size = 5,color = White) 畫十字先,x,y是十字的中心,size是兩側的尺寸,color是顏色

  tag.cx  ,  tag.cy是ApriTag的中心位置,

第22行是弧度制轉角度制

第23行打印ApriTag的id號 和旋轉的角度

 

 

 

 

右上角為所檢測到的ApriTag

左下角為id號

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM