赞
踩
#有两个返回值:执行结果ret及返回图像dst
ret,dst = cv2.threshold(img,180,255,cv2.THRESH_BINARY)
dst =cv2.daptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,3,0)
kernel = np.ones((3,3),np.uint8)
dst = cv2.erode(img,kernel,iterations = 1)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(3,3))
dst = cv2.dilate(img,kernel,iterations = 1)
#可以先调用一次腐蚀操作,再调用一次膨胀操作实现
#也可以直接调用开运算API实现
dst = cv2.morphlogogyEx(img,cv2.MORPH_OPEN,kernel)
闭运算 = 膨胀(先) + 腐蚀(后)
能消除内部噪点
morphlogogyEx(img,MORPH_CLOSE,kernel)
dst = cv2.morphlogogyEx(img,cv2.MORPH_CLOSE,kernel)
dst = cv2.morphlogogyEx(img,cv2.MORPH_GRADIENT,kernel)
dst = cv2.morphlogogyEx(img,cv2.MORPH_TOPHAT,kernel)
dst = cv2.morphlogogyEx(img,cv2.MORPH_BLACKHAT,kernel)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。