logo

使用“histogram.get_threhsold()”函数后怎么传给“ img.binary”

2019-04-29 01:02
P
猫秘树

想使用OTSU算法,找到了“histogram.get_threhsold()”函数,但是在传参数的时候一直报错,希望大佬解救

53f4f680-88c2-4d69-bfd9-0bcd4df8890d.PNG
2019-04-29 11:24
I
网红小智智 星瞳科技

如果涉及代码,需要报错提示与全部代码文本,请注意不要贴代码图片

2019-04-29 14:26
P
猫秘树
import sensor, image, time,machine
from pyb import LED

sensor.reset()
sensor.set_vflip(False)
sensor.set_hmirror(False)
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA) # 80x60 (4,800 pixels) - O(N^2) max = 2,3040,000.
#sensor.set_windowing([0,20,80,40])
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=sensor.snapshot().save("lvbo_2.jpg")  #获取图像
    img.bilateral(3,color_sigma=0.1,space_sigma=0.1)#采用双边滤波
    img.gaussian(3, unsharp=True,)#图像消除锐化
    histogram = img.get_histogram()
    Thresholds = histogram.get_threshold()
    img.binary(threshold)
    print(Thresholds)



    #line = img.get_regression([(100,100,0,0,0,0)], robust = True)

    #if(line):img.draw_line(line.line(), color = 127)

    #print(clock.fps()
2019-04-29 18:17
I
网红小智智 星瞳科技

你可以试试这个:

    Thresholds = histogram.get_threshold()
    l = Thresholds.l_value()
    a = Thresholds.a_value()
    b = Thresholds.b_value()
    print(Thresholds)
    img.binary([(0, l), (-128, a),(-128, b)])
5c76f9b7-df25-49b1-917a-660c99d37f61.png
2019-04-30 11:42
P
猫秘树

@kidswong999 ok了!!! 完美的想哭, 我换成灰度图了