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.96k stars 3.13k forks source link

AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS' #1077

Open ArtDoctor opened 1 year ago

ArtDoctor commented 1 year ago

When I try to use easyocr on any image, I get this error: AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'

According to (https://stackoverflow.com/questions/76616042/attributeerror-module-pil-image-has-no-attribute-antialias), new version of PIL (10.0.0) has no ANTIALIAS, as it's deprecated.

Full error:

File "...", line 8, in convert_img_to_text result = reader.readtext(img_path) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "...\venv\Lib\site-packages\easyocr\easyocr.py", line 464, in readtext result = self.recognize(img_cv_grey, horizontal_list, free_list,\ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "...\venv\Lib\site-packages\easyocr\easyocr.py", line 383, in recognize image_list, max_width = get_image_list(h_list, f_list, img_cv_grey, model_height = imgH) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "...\venv\Lib\site-packages\easyocr\utils.py", line 613, in get_image_list crop_img,ratio = compute_ratio_and_resize(crop_img,width,height,model_height) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "...\venv\Lib\site-packages\easyocr\utils.py", line 576, in compute_ratio_and_resize img = cv2.resize(img,(int(model_height*ratio),model_height),interpolation=Image.ANTIALIAS)

ArtDoctor commented 1 year ago

Some update: downgrading Pillow to 9.5.0 fixes this issue, but I think it will be a good idea to also change the ANTIALIAS parameter in the easyocr\utils.py too.

Rockyisnoteasy commented 1 year ago

I met the same error just now, now i ll try your method

Rockyisnoteasy commented 1 year ago

It works,very thanks

SabahatAnsari commented 1 year ago

Same issue. Can you please provide how to change the ANTIALIAS parameter in the easyocr\utils.py

ArtDoctor commented 1 year ago

I think, it's easier for you to just reinstall the PIL package. Try running this in the console/terminal: pip install --force-reinstall -v "Pillow==9.5.0" After this it should work.

Yingrjimsch commented 1 year ago

I think, it's easier for you to just reinstall the PIL package. Try running this in the console/terminal: pip install --force-reinstall -v "Pillow==9.5.0" After this it should work.

This works thanks I've got the issue right now but it would be great to make it compatible with newer versions. It seems like PIL.Image.LANCZOS or PIL.Image.Resampling.LANCZOS need to be used to achieve the same thing.

SabahatAnsari commented 1 year ago

Thank You

silence0618 commented 1 year ago

pip install --force-reinstall -v "Pillow==9.5.0"

It works for me. Thanks

pratyush-1966 commented 1 year ago

Same issue. Can you please provide how to change the ANTIALIAS parameter in the easyocr\utils.py

Yingrjimsch commented 1 year ago

Same issue. Can you please provide how to change the ANTIALIAS parameter in the easyocr\utils.py

Use PILOW==9.5.0 as workaround. That worked for me.

dekwidap commented 1 year ago

I think, it's easier for you to just reinstall the PIL package. Try running this in the console/terminal: pip install --force-reinstall -v "Pillow==9.5.0" After this it should work.

Thankyou. Currently using Pillow 10.0.0. Then downgrade. It's work.

ozgurmsc commented 1 year ago

I think, it's easier for you to just reinstall the PIL package. Try running this in the console/terminal: pip install --force-reinstall -v "Pillow==9.5.0" After this it should work.

you just saved my life thank you

davidearlyoung commented 1 year ago

Having the same issue. I'll give the PIL older version a try. I agree that easyocr should be adjusted for newer PIL versions. Or at least give people a heads up at installation documentation.

archywillhe commented 1 year ago

This issue is fixed in the master branch. You can install the master branch via: pip install git+https://github.com/JaidedAI/EasyOCR.git

davidearlyoung commented 1 year ago

Back installing worked for me. As well as installing from the the git master as archywillh mentioned worked for me as well. Thank you archywillhe for that info by the way. Additional question. If you don't mind me asking so I can better assist myself in the future, where did you find the info that the master branch had a fix for this?

tuha1994 commented 1 year ago

Pillow to 9.5.0

working with me,thanks you

SunYuhe26862 commented 1 year ago

I've had this problem for a long time, thanks for your help

patrickmappedin commented 12 months ago

When forced to find another solution, this also worked for me:

import PIL
PIL.Image.ANTIALIAS = PIL.Image.LANCZOS

Insert before the call to easyocr's readtext() (or other) method.

wtigga commented 11 months ago

When forced to find another solution, this also worked for me:

import PIL
PIL.Image.ANTIALIAS = PIL.Image.LANCZOS

Insert before the call to easyocr's readtext() (or other) method.

Much better than downgrading PIL. Thank you!

Rebeque commented 11 months ago

When forced to find another solution, this also worked for me:

import PIL
PIL.Image.ANTIALIAS = PIL.Image.LANCZOS

Insert before the call to easyocr's readtext() (or other) method.

Heroic thanks!

NasrCH commented 10 months ago

When forced to find another solution, this also worked for me:

import PIL
PIL.Image.ANTIALIAS = PIL.Image.LANCZOS

Insert before the call to easyocr's readtext() (or other) method.

Thanks ! you saved my day

crisstang commented 8 months ago

When forced to find another solution, this also worked for me:

import PIL
PIL.Image.ANTIALIAS = PIL.Image.LANCZOS

Insert before the call to easyocr's readtext() (or other) method.

Its a good idea!!!

pranith7 commented 7 months ago

Hey @patrickmappedin, I have tried both the approaches a. Downgrading pillow b. PIL.Image.ANTIALIAS = PIL.Image.LANCZOS

but i am getting error like Illegal instruction You can read my post for more info

ShariShah1234 commented 5 months ago

Some update: downgrading Pillow to 9.5.0 fixes this issue, but I think it will be a good idea to also change the ANTIALIAS parameter in the easyocr\utils.py too.

its work thanks

ShariShah1234 commented 1 month ago

THANKS

On Tue, Aug 13, 2024 at 1:52 PM Rashid Rysaev @.***> wrote:

When forced to find another solution, this also worked for me:

import PIL PIL.Image.ANTIALIAS = PIL.Image.LANCZOS

Insert before the call to easyocr's readtext() (or other) method.

Works like a charm, God bless

— Reply to this email directly, view it on GitHub https://github.com/JaidedAI/EasyOCR/issues/1077#issuecomment-2285715169, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZGHA3YOFT4QNERXSX2Z233ZRHCM7AVCNFSM6AAAAAA2DQJ3JKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOBVG4YTKMJWHE . You are receiving this because you commented.Message ID: @.***>