当前位置 博文首页 > deeplearningfeng的博客:python+opencv阈值分割

    deeplearningfeng的博客:python+opencv阈值分割

    作者:[db:作者] 时间:2021-09-19 22:34

    '''
    threshold segmentation
    '''
    import cv2
    import imutils
    import numpy as np
    
    def threshold_seg(args):
        ''''''
        threshold = cv2.getTrackbarPos(trackbar_name1, wname)
        cimg = np.ones(img.shape, dtype=np.uint8)
        cimg[img <= threshold] = 0
        cimg[img > threshold] = 255
        cv2.imshow(wname, cimg)
    if __name__ == '__main__':
        wname = 'threshold segmentation'
        trackbar_name1 = 'threshold'
        img = cv2.imread("./img_1596.png", 0)
        cv2.imshow('img', img)
    
        cv2.namedWindow(wname)
        cv2.createTrackbar(trackbar_name1, wname, 100, 255, threshold_seg)
    
        threshold_seg(0)
        if cv2.waitKey(0) == 27:
            cv2.destroyAllWindows()
    
    cs