def set_outstr(timer):
out_str ='['
out_str +='(%d,%d)' %(x_error,y_error)
out_str +=']'
uart.write(out_str) #向arduino传递out_str字符串
print (out_str)
while(True):
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.
blobs = img.find_blobs([green_threshold])
tim=Timer(4,freq=5)
if blobs:
max_blob = find_max(blobs)
x_error = max_blob[5]-img.width()/2 #X方向偏差
y_error = max_blob[6]-img.height()/2 #y方向偏差
print("x error: ", x_error)
print("y_error: ", y_error)
img.draw_rectangle(max_blob[0:4]) # rect
img.draw_cross(max_blob[5], max_blob[6]) # cx, cy
tim.callback(set_outstr)提示错误:uncaught exception in Timer(4) interrupt handler
MemoryError:
x error: -119.0
y_error: -21.0
你的代码不全,无法运行。