''' 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()
python+opencv阈值分割
最新推荐文章于 2021-08-30 17:35:48 发布