# -*- coding: utf-8 -*-
from PIL import Image
import pytesseract 
import argparse
import cv2
import os



"""
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, 
                help="path to input image to OCR'd")
ap.add_argument("-p", "--preprocess", type=str, default="thresh", 
                help="type of preprocessing to be done")

args = vars(ap.parse_args())
"""


image = cv2.imread("image1.png")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)


"""
gray = cv2.threshold(gray, 0, 255,    
                     cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
"""

gray = cv2.medianBlur(gray, 3)
"""
elif args["preprocess"] == "blur":
    gray = cv2.medianBlur(gray, 3)
"""

    
filename = "image1_res.png"
cv2.imwrite(filename, gray) 


text = pytesseract.image_to_string(Image.open(filename)) 
os.remove(filename) 
print(text) 


cv2.imshow("Image", image)
cv2.imshow("Output", gray)
cv2.waitKey(0)