OpenCV python 图片二值化
处理原图[source.jpg]
代码:
import cv2
def main():
# 1.导入图片 转换为灰度图片
img_src = cv2.imread("source.jpg")
img_gray = cv2.cvtColor(img_src, cv2.COLOR_BGR2GRAY)
# 2.执行二值化
thr, img_rst = cv2.threshold(img_gray, 127, 255, cv2.THRESH_BINARY)
# 3.显示结果
print("thr=", thr)
cv2.imshow("img_src", img_src)
cv2.imshow("img_rst", img_rst)
cv2.waitKey()
cv2.destroyAllWindows()
if __name__ == '__main__':
main()
结果图片:
来源:CSDN
作者:廷益--飞鸟
链接:https://blog.csdn.net/weixin_45875105/article/details/103641762