0

x64, Win 10, Anaconda Python 2.7

I'm trying to do some OCR from captured video frames using OpenCV & pytesseract, my code...

import numpy as np
import cv2
from PIL import ImageGrab
import pytesseract

cap = cv2.VideoCapture(0)

while True:
   # orig_img = ImageGrab.grab(box)
    ret, orig_img = cap.read()

    np_im = np.array(orig_img)

    img = cv2.cvtColor(np_im, cv2.COLOR_BGR2GRAY)

    text = pytesseract.image_to_string(img)

    cv2.imshow('window',img)
    if cv2.waitKey(25) & 0xFF == ord('q'):
        cv2.destroyAllWindows()

    print(text)

I used pip install pytesseract but whenever I run the code I get the following errors..

  File "C:\ProgramData\Anaconda2\lib\site-packages\pytesseract\pytesseract.py", line 309, in image_to_string
    }[output_type]()

  File "C:\ProgramData\Anaconda2\lib\site-packages\pytesseract\pytesseract.py", line 308, in <lambda>
    Output.STRING: lambda: run_and_get_output(*args),

  File "C:\ProgramData\Anaconda2\lib\site-packages\pytesseract\pytesseract.py", line 218, in run_and_get_output
    run_tesseract(**kwargs)

  File "C:\ProgramData\Anaconda2\lib\site-packages\pytesseract\pytesseract.py", line 186, in run_tesseract
    raise TesseractNotFoundError()

TesseractNotFoundError: tesseract is not installed or it's not in your path

And sure enough when I look in the pytesseract folder pytesseract.py or tesseact.exe or anything tesseract isn't there...

enter image description here

So even if I wanted to add it to my PATH I cant.

What am I missing here?

DrBwts
  • 3,470
  • 6
  • 38
  • 62

3 Answers3

2

Have you installed Google Tesseract OCR? It's a pre-requisite for using pytesseract.

If not all the instructions to do so are on it's GitHub page. https://github.com/tesseract-ocr/tesseract/wiki

I hope this helps.

Aprajita Verma
  • 208
  • 1
  • 5
1

There could be multiple problems.

  1. Check If tesseract.exe is installed. If not get exe file from below link and install the same.

    https://github.com/UB-Mannheim/tesseract/wiki

  2. If you already have tesseract installed. But pytesseract is unable to access tesseract using python. You can set the path with in the script like this.

    pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"

anil kumar
  • 774
  • 7
  • 7
-1

On Ubuntu you can try this especially under python web frameworks

pytesseract.pytesseract.tesseract_cmd = r"/usr/bin/tesseract"
img = Image.open(picture_name)
print(pytesseract.image_to_string(img))
Prajwol KC
  • 398
  • 6
  • 13