# Find Rects Example
#
# 这个例子展示了如何使用april标签代码中的四元检测代码在图像中找到矩形。 四元检测算法以非常稳健的方式检测矩形,并且比基于Hough变换的方法好得多。 例如,即使镜头失真导致这些矩形看起来弯曲,它仍然可以检测到矩形。 圆角矩形是没有问题的!
# (但是,这个代码也会检测小半径的圆)...
import sensor, image, time
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # 灰度更快(160x120 max on OpenMV-M7)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()
while(True):
clock.tick()
img = sensor.snapshot()
rectangles = img.find_rects()
rectangles = []
for rectangle in rectangles :
if rectangles.size > roi(80,60,80,70):
renctangles.append(rectangles)
print(rectangles )
print("FPS %f" % clock.fps())第18行直接复制为空列表了,后面啥都没有了。
如果是大小,就是判断长和宽,要注意不能直接等于判断,要用范围判断。
import sensor, image, time
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # 灰度更快(160x120 max on OpenMV-M7)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()
while(True):
clock.tick()
img = sensor.snapshot()
rectangles = img.find_rects()
out_rectangles = []
for r in rectangles :
if 50<r.w()<100 and 50<r.h()<100:
out_rectangles.append(r)
print(out_rectangles)
print("FPS %f" % clock.fps())