import sensor, image, time, math, omv
thresholds = (150, 255)
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
if omv.board_type() == "H7": sensor.set_framesize(sensor.VGA)
elif omv.board_type() == "M7": sensor.set_framesize(sensor.QVGA)
else: raise Exception("You need a more powerful OpenMV Cam to run this script")
sensor.skip_frames(time = 200)
sensor.set_auto_gain(False)
sensor.set_auto_whitebal(False)
clock = time.clock()
tag_families = 0
tag_families |= image.TAG16H5
tag_families |= image.TAG25H7
tag_families |= image.TAG25H9
tag_families |= image.TAG36H10
tag_families |= image.TAG36H11
tag_families |= image.ARTOOLKIT
while(True):
clock.tick()
img = sensor.snapshot()
box_list = []
tag_list = []
for blob in img.find_blobs([thresholds], pixels_threshold=100, area_threshold=100, merge=True):
w = min(max(int(blob.w() * 1.2), 10), 160)
h = min(max(int(blob.h() * 1.2), 10), 160)
x = min(max(int(blob.x() + (blob.w()/4) - (w * 0.1)), 0), img.width()-1)
y = min(max(int(blob.y() + (blob.h()/4) - (h * 0.1)), 0), img.height()-1)
box_list.append((x, y, w, h))
try:
tag_list.extend(img.find_apriltags(roi=(x,y,w,h), families=tag_families))
except (MemoryError):
pass
for b in box_list:
img.draw_rectangle(b)
for tag in tag_list:
img.draw_rectangle(tag.rect())
img.draw_cross(tag.cx(), tag.cy())
for c in tag.corners():
img.draw_circle(c[0], c[1], 5)
print("Tag:", tag.cx(), tag.cy(), tag.rotation(), tag.id())