AttributeError: ‘dict’ object has no attribute ‘mode’ when using Tsseract OCR


This Content is from Stack Overflow. Question asked by XYJ

Using Google Colab, I wrote the following code. I utilized Python. I intended to import an image file from my computer and then use Tesseract OCR to recignize the characters in the image.

After running the following code on colab, the error message: AttributeError: ‘dict’ object has no attribute ‘mode’
Although there are same cases on the Internet with the error message of “‘dict’ object has no attribute ‘~'”, but I couldn’t find any case that was regarding the attribute “mode.”

Could you please advise me how to improve my code?

The code I wrote

!apt install tesseract-ocr libtesseract-dev tesseract-ocr-jpn
!pip install pyocr

from PIL import Image
import pyocr
import cv2
from google.colab.patches import cv2_imshow

from google.colab import files


txt1 = tool.image_to_string(

The error message showed by colab

AttributeError                            Traceback (most recent call last)
<ipython-input-38-2ad0a8585335> in <module>
      2     uploaded,
      3     lang='jpn+eng',
----> 4
      5     )
      6 help(dict.items)

/usr/local/lib/python3.7/dist-packages/pyocr/ in image_to_string(image, lang, builder)
    362         builder = builders.TextBuilder()
    363     with tempfile.TemporaryDirectory() as tmpdir:
--> 364         if image.mode != "RGB":
    365             image = image.convert("RGB")
    366, "input.bmp"))
AttributeError: 'dict' object has no attribute 'mode'


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?