Skip to content

Instantly share code, notes, and snippets.

@NbtKmy
Created April 16, 2021 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NbtKmy/2266ea0fe2771bf899bbf995d602a007 to your computer and use it in GitHub Desktop.
Save NbtKmy/2266ea0fe2771bf899bbf995d602a007 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import cv2
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Pre-process for OCR')
parser.add_argument('input', help='Name of original image')
parser.add_argument('output', help='Name of output image')
args = parser.parse_args()
img = cv2.imread(args.input)
h, s, grau_img = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HSV))
cv2.imwrite(args.output, grau_img)
# Binarisierung
ret, bi_img = cv2.threshold(grau_img, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
res_name2 = 'Binarized' + args.output
cv2.imwrite(res_name2, bi_img)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment