引用特定于OpenMV Cam的库 的问题
-
import sensor, image, time sensor.reset() sensor.set_pixformat(sensor.RGB565) # 灰度更快(160x120 max on OpenMV-M7) sensor.set_framesize(sensor.QQVGA)#160 * 120 sensor.skip_frames(time = 2000) clock = time.clock() while(True): clock.tick() img = sensor.snapshot() for r in img.find_rects(threshold = 20000): img.draw_rectangle(r.rect(), color = (255, 0, 0)) rects=img.find_rects(threshold = 20000) for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0)) x=rect.x() print(r) print("FPS %f" % clock.fps())
运行报错NameError: name 'rect' isn't defined
应该如何写这个函数(rect.x())
-
你代码写的不对。
正确的代码:
import sensor, image, time sensor.reset() sensor.set_pixformat(sensor.RGB565) # 灰度更快(160x120 max on OpenMV-M7) sensor.set_framesize(sensor.QQVGA)#160 * 120 sensor.skip_frames(time = 2000) clock = time.clock() while(True): clock.tick() img = sensor.snapshot() for r in img.find_rects(threshold = 20000): img.draw_rectangle(r.rect(), color = (255, 0, 0)) for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0)) x=r.x() print(x) print(r) print("FPS %f" % clock.fps())
-
谢谢