logo

显示未定义变量

2019-03-18 17:18
U
ym3w

import sensor, image, time, pyb

from pyb import Pin

from pyb import UART

from pyb import LED

led_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)

265121e3-02f9-4198-959b-ff8a7597b74e.png
2019-03-19 13:58
I
网红小智智 星瞳科技

如果blobs是空的话,max_blob就没有定义。

http://book.openmv.cc/project/zhui-xiao-qiu-de-xiao-8f665d28-project-pan-tilt-md.html