11| # importing modules
22| import cv2
33| import pytesseract
45| # reading image using opencv
56| image = cv2.imread(sample_image.png’)
67| #converting image into gray scale image
78| gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
89| # converting it to binary image by Thresholding
910| # this step is require if you have colored image because if you skip this part
1011| # then tesseract won't able to detect text correctly and this will give incorrect result
1111|threshold_img = cv2.threshold(gray_image, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
1212| # display image
1313| cv2.imshow(‘threshold image’, threshold_img)
1414| # Maintain output window until user presses a key
1515| cv2.waitKey(0)
1616| # Destroying present windows on screen
1717| cv2.destroyAllWindows()
18