显示未定义变量
-
import sensor, image, time, pyb
from pyb import Pin
from pyb import UART
from pyb import LEDled_R = pyb.LED(1) # Red LED = 1, Green LED = 2, Blue LED = 3, IR LEDs = 4.
led_G = pyb.LED(2) # Red LED = 1, Green LED = 2, Blue LED = 3, IR LEDs = 4.
led_B = pyb.LED(3) # Red LED = 1, Green LED = 2, Blue LED = 3, IR LEDs = 4.red_threshold = (22, 72, 40, 69, 14, 58)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)clock = time.clock()
while(True):
clock.tick()
img = sensor.snapshot()
blobs = img.find_blobs([red_threshold], pixels_threshold=20, area_threshold=20, merge=True)
for blob in blobs:
if blob.area()>max_blob.area():
max_blob = blob
x_error = max_blob.cx()
h_error = max_blob.cy()
print(x_error)
print(h_error)
-
如果blobs是空的话,max_blob就没有定义。
http://book.openmv.cc/project/zhui-xiao-qiu-de-xiao-8f665d28-project-pan-tilt-md.html