***Above, an example of Google OCR API, hopefully, I will be able to do the same with Tesseract, one day
The installation of this library took me longer than usual.
!pip install pytesseract
While you should start by installing pytesseract using pip, if you try to run the library, it will run an error.
TesseractNotFoundError: /usr/bin/tesseract is not installed or it's not in your PATH
The installation is a little bit hectic. In fact, you will first need to install another package called tesseract-ocr and make a direct cmd connection to the .exe file (all written in the instructions and available on my repo, do not despair).
!sudo apt install tesseract-ocr
Make sure you are installing both libraries together.
try:
from PIL import Image
except ImportError:
import Image
import cv2
import pytesseract
Before proceeding, you will need to find out where do you have to find the tesseract execution file.
!which tesseract
/usr/bin/tesseract
You can now copy the output to specify the location of the .exe file. Unfortunately, it appears this is the only workaround to make Tesseract work on Google Colab. So far, this appears to be the only working tutorial between the many I searched.
pytesseract.pytesseract.tesseract_cmd = (
r'/usr/bin/tesseract'
)
The library should have been imported correctly.
I will be using the cv2 library to import and edit images. I will have to make sure that in my notebook storage I have uploaded the image I want, and that I can access its path correctly. In this case, the image is called image.png.
#deep-learning #ocr #artificial-intelligence #image-to-text #tesseract #deep learning