例程讲解-03-flood_fill洪水填充
本例程为03-Drawing-flood_fill.py 像洪水一样填充图像中低矮凹陷的地方。
# 洪水填充
#
# 此示例显示图像中的洪水填充区域。
import sensor, image, time
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # or GRAYSCALE...
sensor.set_framesize(sensor.QVGA) # or QQVGA...
sensor.skip_frames(time = 2000)
clock = time.clock()
while(True):
clock.tick()
# seed_threshold controls the maximum allowed difference between
# the initial pixel and any filled pixels. It's important to
# set this such that flood fill doesn't fill the whole image.
# floating_threshold controls the maximum allowed difference
# between any two pixels. This can easily fill the whole image
# with even a very low threshold.
# flood_fill will fill pixels that both thresholds.
# You can invert what gets filled with "invert" and clear
# everything but the filled area with "clear_background".
x = sensor.width() // 2
y = sensor.height() // 2
img = sensor.snapshot().flood_fill(x, y, \
seed_threshold=0.05, floating_thresholds=0.05, \
color=(255, 0, 0), invert=False, clear_background=False)
print(clock.fps())
运行效果图: