
# AprilTags Example
#
# This example shows the power of the OpenMV Cam to detect April Tags
# on the OpenMV Cam M7. The M4 versions cannot detect April Tags.
import sensor, image, time, math
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA) # we run out of memory if the resolution is much bigger...
sensor.skip_frames(30)
sensor.set_auto_gain(False) # must turn this off to prevent image washout...
sensor.set_auto_whitebal(False) # must turn this off to prevent image washout...
clock = time.clock()
while(True):
clock.tick()
img = sensor.snapshot()
for tag in img.find_apriltags(families=image.TAG25H9): # defaults to TAG36H11 without "families".
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)
x = 0
y = 0
def tag_id(t):
if(t == 0):
x=25, y=25
if(t == 1):
x=125, y=25
if(t == 2):
x=225, y=25
tag_id(tag.id())
print(x, y)
请问程序到底该怎么编写呢?缩进不对,一个Tab应该是4个空格,
if(t == 0):这里有14个空格。

嘈点太多了,
1,首先定义函数不需要放在for循环里,你每秒重复定义100多次这个函数没必要。
2, `x=25, y=25`在python里是不能这么用的,需要两行,这也是报错的原因
x=25
y=253,即使不报错逻辑也是错的,你可能不知道什么叫做全局变量,什么叫做局部变量,函数内部的局部变量x和y并不影响全局变量x和y。
4,这个函数你应该用返回值
def tag_id(t):
x = 0
y = 0
if(t == 0):
x=25
y=25
if(t == 1):
x=125
y=25
if(t == 2):
x=225
y=25
return x,y
print(tag_id(0))
print(tag_id(1))
print(tag_id(2))5,你的缩进实在让人看不下去。。。