logo

请问对一张图片边缘检测完后,如何保存获得的边缘图像?

2023-05-17 20:04
V
x6sp

请问对一张图片边缘检测完后,如何保存获得的边缘图像?

2023-05-17 20:17
V
x6sp

完整描述:从sd卡中读取某一张图片,然后进行边缘检测,接着保存framebuffer中的边缘图像至sd卡中

2023-05-20 21:00
I
网红小智智 星瞳科技
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