logo

如何只对一张图片进行二值化处理

2022-10-23 09:57
6
cptb

我要做什么:

我想采集一张图片就停下来,然后对它做后续各种处理比如二值化。

我遇到的问题:

只操作一张图片进行二值化framebuffer里面没有反应。

我想得到什么帮助:

如何只对一张图片进行二值化,而不是循环采集

import sensor, image, time     


sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 2000)     # Wait for settings take effect.


# 获得一帧图像
img = sensor.snapshot()

threshold = (0,100,   -128,127,	20,50)#二值化的分割阈值

img.binary([threshold])
5e39c212-bfb6-411e-925f-8ddfeae59a14.png
2022-10-24 21:13
I
网红小智智 星瞳科技

是因为IDE没有接收到数据。代码里是正常采集到的。

如果想显示,可以这样:

import sensor, image, time     


sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 2000)     # Wait for settings take effect.


# 获得一帧图像

img = sensor.snapshot()

threshold = (0,100,   -128,127,	20,50)
img.binary([threshold])

img = sensor.snapshot()
while True:
    time.sleep(1)