CVK
CVK

Reputation: 63

AttributeError: 'numpy.ndarray' object has no attribute 'split' when using pytesseract on Ubuntu

I'm encountering an issue while trying to convert images to text using pytesseract in a Jupyter notebook on Ubuntu 16.04. Interestingly, the same code works fine on Windows, but throws an error on Ubuntu. Here's my code:

import cv2
import pytesseract

image = cv2.imread('80.png')
tesseract_cmd = r'/work/leptonica-1.76.0/tesseract'

print(pytesseract.image_to_string(image))

When I run this code, I get the following error:

attributeerror: 'numpy.ndarray' object has no attribute 'split'

The full traceback shows:

AttributeErrorTraceback (most recent call last)
<ipython-input-11-5e5eec226f77> in <module>()
----> 1 print(pytesseract.image_to_string(image))

/root/anaconda2/envs/python3/lib/python3.5/site-packages/pytesseract-0.1.7-py3.5.egg/pytesseract/pytesseract.py in image_to_string(image, lang, boxes, config)
    102
    103
--> 104     if len(image.split()) == 4:
    105         # In case we have 4 channels, lets discard the Alpha.
    106         # Kind of a hack, should fix in the future some time.

AttributeError: 'numpy.ndarray' object has no attribute 'split'

I've already verified that the image file exists and can be opened. The tesseract_cmd path is set correctly for my Ubuntu environment. Questions:

  1. Why am I getting this 'AttributeError' on Ubuntu when the same code works on Windows?
  2. How can I resolve this issue to successfully convert images to text on Ubuntu?

Any insights or solutions would be greatly appreciated. Thank you!

Upvotes: 0

Views: 1247

Answers (0)

Related Questions