Here, I’ll use Python as a programming language to complete the OCR task.Make sure we have python 3 installed in our system then we are ready to install OCR and Tesseract, use the commands mentioned below one by one:
pip install opencv-python
pip install pytesseract
import pytesseract
import cv2
import os
from gtts import gTTS
import numpy as np
import imutils
image = cv2.imread("image/Sample_image.png")
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
this step is require if you have colored image because if you skip this part then tesseract won't able to detect text correctly and this will give incorrect result)
threshold_img = cv2.threshold(gray_image, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
cv2.imshow('Result', image)
img = Image.open('image/Sample_image.png')
cv2.waitKey(0)
text = tess.image_to_string(img)
print(text)
audio = gTTS(text = xy, lang = 'en', slow = True)
audio.save("quote3.wav")
os.system("quote3.wav")