JaidedAI / EasyOCR

Ready-to-use OCR with 80+ supported languages and all popular writing scripts including Latin, Chinese, Arabic, Devanagari, Cyrillic and etc.
https://www.jaided.ai
Apache License 2.0
23.61k stars 3.1k forks source link

passing a batch of images #1168

Open noamKayzer opened 9 months ago

noamKayzer commented 9 months ago

Hey, I haven't been able to use the detect function with any sort of list of images, I have tried with a list of numpy arrays, a list of bytes (PNG encoding), with and without the "reformat" argument, but it keeps failing when trying to access the image list as a numpy array (search for the "shape" attribute exist in a single numpy array).

reader = easyocr.Reader(["ar","fa","ur","ug","en"],
                        detect_network="dbnet18", #'craft'
                        recognizer=False,
                        quantize=True)
...
reader.detect(images_bytes_list,bbox_min_size=7,reformat=False)

OR
def img_decode(content: bytes):
    np_arr = np.frombuffer(content, dtype=np.uint8)
    return cv2.imdecode(np_arr, cv2.IMREAD_UNCHANGED)
images_np_list =[img_decode(img) for img in images_bytes_list]
reader.detect(images_bytes_list,bbox_min_size=7,reformat=False)

each element in the list is of shape (1024, 576, 3).

the error massage is :


  File "<string>", line 2, in <module>
  File "/home/ubuntu/venv-ai/lib/python3.9/site-packages/easyocr/easyocr.py", line 321, in detect
    text_box_list = self.get_textbox(self.detector,
  File "/home/ubuntu/venv-ai/lib/python3.9/site-packages/easyocr/detection_db.py", line 207, in get_textbox
    _, polys_list = test_net(image,
  File "/home/ubuntu/venv-ai/lib/python3.9/site-packages/easyocr/detection_db.py", line 74, in test_net
    images, original_shapes = zip(*[detector.resize_image(img, canvas_size) for img in image_arrs])
  File "/home/ubuntu/venv-ai/lib/python3.9/site-packages/easyocr/detection_db.py", line 74, in <listcomp>
    images, original_shapes = zip(*[detector.resize_image(img, canvas_size) for img in image_arrs])
  File "/home/ubuntu/venv-ai/lib/python3.9/site-packages/easyocr/DBNet/DBNet.py", line 254, in resize_image
    height, width, _ = img.shape
AttributeError: 'list' object has no attribute 'shape'```
TheMegistone4Ever commented 7 months ago

You can try readtext_batched in easyocr.easyocr file. I've tried, but it's the same as using readtext in linear for loop, so maybe it's not done