OpenCV自适应阈值二值化处理

在图像处理的过程中,第一步需要二值化处理,尽可能多的保存图像的细节

import cv2 as cv

img=cv.imread("D:/wyx.jpg")
img_Gray=cv.cvtColor(img,cv.COLOR_BGR2GRAY)

athdMEAM=cv.adaptiveThreshold(img_Gray,255,cv.ADAPTIVE_THRESH_MEAN_C,cv.THRESH_BINARY,5,3)
athGAUS=cv.adaptiveThreshold(img_Gray,255,cv.ADAPTIVE_THRESH_GAUSSIAN_C,cv.THRESH_BINARY,5,3)

cv.imshow("wyx",img)
cv.imshow("MEAN_C",athdMEAM)
cv.imshow("GAUSSIAN_C",athGAUS)

cv.imwrite("D:/MEAN_C.jpg",athdMEAM)
cv.imwrite("D:/GAUSSIAN_C.jpg",athGAUS)

cv.waitKey()
cv.destroyAllWindows()

代码运行的结果如图所示

OpenCV自适应阈值二值化处理_第1张图片

 OpenCV自适应阈值二值化处理_第2张图片

 

你可能感兴趣的:(OpenCV,opencv,计算机视觉,人工智能)