logo

怎么使用“threshold.value()”拿出阈值.

2019-04-29 17:40
P
猫秘树

利用“histogram.get_threshold()”得到最佳阈值后,想使用“threshold.value()”拿出阈值,失败了..:loudly_crying_face: :loudly_crying_face:

THRESHOLD = [0, 100] # Grayscale threshold for dark things...
BINARY_VISIBLE = True # Does binary first so you can see what the linear regression
                      # is being run on... might lower FPS though.

import sensor, image, time
from pyb import LED

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQQVGA) # 80x60 (4,800 pixels) - O(N^2) max = 2,3040,000.
sensor.skip_frames(time = 2000)     # WARNING: If you use QQVGA it may take seconds
clock = time.clock()                # to process a frame sometimes.

LED(1).on()
LED(2).on()
LED(3).on()

while(True):
    clock.tick()
    img = sensor.snapshot().lens_corr(strength = 0.5, zoom = 1.0)
    img.gaussian(3, unsharp=True)

    histogram = img.get_histogram()#得到直方图
    Thresholds = histogram.get_threshold()#得到最佳阈值
    THR=threshold.value()#获取当前阈值

    #img.binary([THRESHOLD])if BINARY_VISIBLE else sensor.snapshot()

    line = img.get_regression([(255,255) if BINARY_VISIBLE else THRESHOLD], robust = True)

    if (line): img.draw_line(line.line(), color = 127)
be343cfa-9725-4d40-bfca-4030ed1888ac.PNG
2019-04-29 18:30
I
网红小智智 星瞳科技

https://forum.singtown.com/topic/2930/%E4%BD%BF%E7%94%A8-histogram-get_threhsold-%E5%87%BD%E6%95%B0%E5%90%8E%E6%80%8E%E4%B9%88%E4%BC%A0%E7%BB%99-img-binary