出现莫名起码的报错,不知道为什么报错
-
import sensor, time, image,pyb from pyb import Pin, Timer from pyb import LED sensor.reset() sensor.set_contrast(3) sensor.set_gainceiling(16) sensor.set_framesize(sensor.VGA) sensor.set_windowing((320, 240)) sensor.set_pixformat(sensor.GRAYSCALE) sensor.skip_frames(time = 2000) sensor.set_auto_gain(False) sensor.set_auto_whitebal(False) p1 = Pin("P7", Pin.OUT_PP) p2 = Pin("P8", Pin.OUT_PP) p3 = Pin("P4", Pin.OUT_PP) led1 = pyb.LED(1) led2 = pyb.LED(2) led3 = pyb.LED(3) kpts3 = image.load_descriptor("/a3.orb") kpts4 = image.load_descriptor("/a4.orb") kpts5 = image.load_descriptor("/a5.orb") kpts51 = image.load_descriptor("/a51.orb") kpts6 = image.load_descriptor("/a6.orb") kpts61 = image.load_descriptor("/a61.orb") kpts7 = image.load_descriptor("/a7.orb") kpts71 = image.load_descriptor("/a71.orb") kpts8 = image.load_descriptor("/a8.orb") kpts81 = image.load_descriptor("/a81.orb") clock = time.clock() light = Timer(2, freq=50000).channel(1, Timer.PWM, pin=Pin("P6")) light.pulse_width_percent(1) while (True): clock.tick() time.sleep(1) img = sensor.snapshot() if (kpts3 == None): kpts3 = img.find_keypoints(max_keypoints=150, threshold=10, scale_factor=1.2) else: kpts2 = img.find_keypoints(max_keypoints=150, threshold=10, normalized=True) if (kpts2): match3 = image.match_descriptor(kpts3, kpts2, threshold=85) match4 = image.match_descriptor(kpts4, kpts2, threshold=85) match5 = image.match_descriptor(kpts5, kpts2, threshold=85) match51 = image.match_descriptor(kpts51, kpts2, threshold=85) match6 = image.match_descriptor(kpts6, kpts2, threshold=85) match61 = image.match_descriptor(kpts61, kpts2, threshold=85) match7 = image.match_descriptor(kpts7, kpts2, threshold=85) match71 = image.match_descriptor(kpts71, kpts2, threshold=85) match8 = image.match_descriptor(kpts8, kpts2, threshold=85) match81 = image.match_descriptor(kpts81, kpts2, threshold=85) if (match3.count()>15): img.draw_rectangle(match3.rect()) img.draw_cross(match3.cx(), match3.cy(), size=10) print("3") p1.high() p2.low() p3.low() if (match4.count()>15): img.draw_rectangle(match4.rect()) img.draw_cross(match4.cx(), match4.cy(), size=10) print("4") p1.low() p2.high() p3.low() if (match5.count()>15): img.draw_rectangle(match5.rect()) img.draw_cross(match5.cx(), match5.cy(), size=10) print("5") p1.low() p2.low() p3.high() if (match51.count()>15): img.draw_rectangle(match51.rect()) img.draw_cross(match51.cx(), match51.cy(), size=10) print("51") p1.low() p2.low() p3.high() if (match6.count()>15): img.draw_rectangle(match6.rect()) img.draw_cross(match6.cx(), match6.cy(), size=10) print("6") p1.high() p2.high() p3.low() if (match61.count()>15): img.draw_rectangle(match61.rect()) img.draw_cross(match61.cx(), match61.cy(), size=10) print("61") p1.high() p2.high() p3.low() if (match7.count()>15): img.draw_rectangle(match7.rect()) img.draw_cross(match7.cx(), match7.cy(), size=10) print("7") p1.low() p2.high() p3.high() if (match71.count()>15): img.draw_rectangle(match71.rect()) img.draw_cross(match71.cx(), match71.cy(), size=10) print("71") p1.low() p2.high() p3.high() if (match8.count()>15): img.draw_rectangle(match8.rect()) img.draw_cross(match8.cx(), match8.cy(), size=10) print("8") p1.high() p2.low() p3.high() if (match81.count()>15): img.draw_rectangle(match81.rect()) img.draw_cross(match81.cx(), match81.cy(), size=10) print("81") p1.high() p2.low() p3.high()
用的plus
-
-
报错图片在评论的啊
-
不要一开始把所有的全部load进来,在for循环里lord。
for循环里也不要把所有match_descriptor的对象复制到变量里,内存爆了。