# Text Detection and Extraction using OpenCV and OCR

import cv2
import pytesseract

pytesseract.pytesseract.tesseract_cmd = 'tesseract'

img = cv2.imread("sample.jpg")

gray =cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

text = pytesseract.image_to_string(gray)
print(text)

file = open("recognized.txt","w+")
file.write(text)
file.close()

# cv2.imshow("Demo",gray)
# cv2.waitKey(0)