import sensor, image, time
# 仍然需要初始化 sensor
sensor.reset()
# 设置 sensor
sensor.set_contrast(1)
sensor.set_gainceiling(16)
# 设置sensor的像素格式
sensor.set_framesize(sensor.QQVGA)
sensor.set_pixformat(sensor.GRAYSCALE)
kernel_size = 1 # kernel width = (size*2)+1, kernel height = (size*2)+1
kernel = [-1, -1, -1,\
-1, +8, -1,\
-1, -1, -1]
thresholds = [(100, 255)] # grayscale thresholds设置阈值
# 导入 image
img = image.Image("/example.bmp", copy_to_fb=True)
img.morph(kernel_size, kernel)
img.binary(thresholds)
img.erode(1, threshold = 2)
img.save('binary.bmp')
# Flush FB
sensor.flush()
# Add a small delay to allow the IDE to read the flushed image.
# 添加一个小的延迟,以允许IDE读取刷新后的图像
time.sleep_ms(100)
参考代码:
https://book.openmv.cc/example/03-Drawing/copy2fb.html
https://book.openmv.cc/example/04-Image-Filters/edge-detection.html