【最新:程序可能有未知原因的bug】
前言
由于在官方例程里似乎没有完整的otsu算法,所以自己码了个。
一开始一度以为openmv没有内置的otsu,后来论坛搜索发现有
histogram.get_threhsold()
使用Otsu’s 方法计算最佳阈值,将直方图分的每个通道为两半。 该方法返回一个 image.threshold 对象。
这个方法对确定最佳的 image.binary() 阈值特别有用。
程序
import sensor, image, time
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # 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.
clock = time.clock() # Create a clock object to track the FPS.
while(True):
clock.tick() # Update the FPS clock.
img = sensor.snapshot() # Take a picture and return the image.
# to the IDE. The FPS should increase once disconnected