scale_percent = 30
image = cv2.imread(captcha)
dim = (image.shape[1] * scale_percent // 100, image.shape[0] * scale_percent // 100)
resized = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)
gray = cv2.cvtColor(resized, cv2.COLOR_BGR2GRAY) #
ret, threshold_image = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)
threshold_image = np.invert(threshold_image)