import csi
import time
thresholds = (150, 255)
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.GRAYSCALE)
csi0.snapshot(time=200)
csi0.auto_gain(False)
csi0.auto_whitebal(False)
clock = time.clock()
while True:
clock.tick()
img = csi0.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)))
except (
MemoryError
):
pass
for b in box_list:
img.draw_rectangle(b)
for tag in tag_list:
img.draw_detection(tag)
for c in tag.corners:
img.draw_circle((c[0], c[1], 5))
print("Tag:", tag.cx, tag.cy, tag.rotation, tag.id)