How to use the OTSU Threshold in opencv?

后端 未结 3 1493
猫巷女王i
猫巷女王i 2020-12-24 01:25

I was using a fixed threshold but turns out that it\'s not so good for me. Then, someone told me about the otsu threshold. How can I use it in my code? I read about it and I

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-24 01:47

    In python it is simple

    import cv2
    
    img = cv2.imread('img.jpg',0)  #pass 0 to convert into gray level 
    ret,thr = cv2.threshold(img, 0, 255, cv2.THRESH_OTSU)
    cv2.imshow('win1', thr)
    cv2.waitKey(0)  
    cv2.destroyAllWindows()
    

提交回复
热议问题