为什么max_blob没有识别到颜色时显示没有定义,而运行开始时识别到相应颜色就没事?
-
# Blob Detection Example # # This example shows off how to use the find_blobs function to find color # blobs in the image. This example in particular looks for dark green objects. import sensor, image, time from pyb import UART sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(10) sensor.set_auto_whitebal(False) clock = time.clock() uart = UART(3,19200,timeout_char=1000) green_threshold = (17, 96, -17, 40, 88, 19) size_threshold = 2000 def find_max(blobs): max_size=0 max_blob=None for blob in blobs: if blob[2]*blob[3] > max_size: max_blob=blob max_size = blob[2]*blob[3] return max_blob 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]) if blobs: max_blob = find_max(blobs) img.draw_rectangle(max_blob[0:4]) # rect img.draw_cross(max_blob[5], max_blob[6]) # cx, cy if max_blob: #此处max_blob显示没定义 pan_error = max_blob.cx()-img.width()/2 if max_blob == None: print('旋转') uart.write('$ZY!') time.sleep_ms(100)
-
在
if blobs:
上面添加max_blob=None
-
此回复已被删除!