import cv2
import numpy as np
if __name__ == '__main__':
img_src = cv2.imread("picture.png", 1)
img_gray = cv2.cvtColor(img_src, cv2.COLOR_BGR2GRAY)
thresh = 100
max_pixel = 255
ret, img_dst = cv2.threshold(img_gray,
thresh,
max_pixel,
cv2.THRESH_BINARY)
height = img_dst.shape[0]
width = img_dst.shape[1]
halfsize = (round(width/2),round(height/2))
halfsize_dst = cv2.resize(img_dst,halfsize)
cv2.imshow("Show BINARIZATION Image", halfsize_dst)
cv2.imwrite("picture_bin.png", halfsize_dst)
cv2.destroyAllWindows()