I am using windows 10 and tesserocr version is 2.4. Want to detect text from an image and then the language of that text.
While running this piece of code:
from tesserocr import PyTessBaseAPI
import argparse
parser = argparse.ArgumentParser("Enter Image Path")
parser.add_argument('-i' , '--image' , help="Image Path")
args, unknown = parser.parse_known_args()
images = ['b.jpg']
images[0] = args.image
count = 0
count2 = 0
count3 = 0
with PyTessBaseAPI() as api:
for img in images:
api.Init(lang = 'eng')
api.SetImageFile(img)
# print api.AllWordConfidences()
arr = list(api.AllWordConfidences())
sumarr = sum(arr) / float(len(arr))
Getting below error :
<ipython-input-3-152e90ab44c3> in <module>
13 count2 = 0
14 count3 = 0
---> 15 with PyTessBaseAPI() as api:
16 for img in images:
17 api.Init(lang = 'eng')
tesserocr.pyx in tesserocr._tesserocr.PyTessBaseAPI.__cinit__()
tesserocr.pyx in tesserocr._tesserocr.PyTessBaseAPI._init_api()
RuntimeError: Failed to init API, possibly an invalid tessdata path: C:\Users\hp\Anaconda3\/tessdata/
Anyone aware of this issue ?
Add an environment variable on your system to point to the tessdata directory
You can also pass it in to PyTessBaseAPI
as per the docs:
Args:
path (str): The name of the parent directory of tessdata. Must end in /.
Should be:
with PyTessBaseAPI(path='./') as api:
this is if you have the trainedata in the same folder as the script, otherwise substitute './'
with your path
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With