Attributeerror-module-pil-image-has-no-attribute-antialias

257 Views Asked by At

I am working on Automatic Number plate detection problem using opencv and yolo. I am getting the below error when i pass the numpy array to easyocr readtext module

import easyocr
reader = easyocr.Reader(['en'], gpu=False)

print(type(license_plate_crop)) # <class 'numpy.ndarray'>
print(license_plate_crop)
detections = reader.readtext(license_plate_crop)

This is the error i am getting

line 619, in get_image_list
    crop_img,ratio = compute_ratio_and_resize(crop_img,width,height,model_height)
  File "/home/pranith_dev/Desktop/Datavoice/Automatic-License-Plate-Recognition-using-YOLOv8/dev-venv/lib/python3.10/site-packages/easyocr/utils.py", line 582, in compute_ratio_and_resize
    img = cv2.resize(img,(int(model_height*ratio),model_height),interpolation=Image.ANTIALIAS)
AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'

I tried downgrading pillow version from 10.0.0 to 9.5 or 9.4 according to online solutions but the issue still persists and the following is the output

<class 'numpy.ndarray'>
[[255 255 255 ... 255 255 255]
 [255 255 255 ... 255 255 255]
 [255 255 255 ... 255 255 255]
 ...
 [255 255 255 ... 255 255 255]
 [255 255 255 ... 255 255 255]
 [255 255 255 ... 255 255 255]]
Illegal instruction
1

There are 1 best solutions below

4
tacon On

Welcome Pranith !

The EasyOCR project on Github lists a commit to utils.py: Update utils.py. Apparently, Image.Resampling.LANCZOS replaced PIL.Image.ANTIALIAS in Pillow 10.

You can check your own Pillow version with pip list | grep pillow. Make sure you have:

  • either the EasyOCR version which includes the mentioned commit (and still compatible with Python 3.10, which you are using)
  • or keep your EasyOCR version but downgrade your Pillow version accordingly, so that it has PIL.Image.ANTIALIAS