EasyOCR icon indicating copy to clipboard operation
EasyOCR copied to clipboard

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

Open ArtDoctor opened this issue 2 years ago • 27 comments

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 avatar Jul 09 '23 13:07 ArtDoctor

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.

ArtDoctor avatar Jul 09 '23 15:07 ArtDoctor

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

Rockyisnoteasy avatar Jul 15 '23 09:07 Rockyisnoteasy

It works,very thanks

Rockyisnoteasy avatar Jul 15 '23 09:07 Rockyisnoteasy

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

SabahatAnsari avatar Jul 19 '23 14:07 SabahatAnsari

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.

ArtDoctor avatar Jul 19 '23 14:07 ArtDoctor

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.

Yingrjimsch avatar Jul 19 '23 15:07 Yingrjimsch

Thank You

SabahatAnsari avatar Jul 19 '23 15:07 SabahatAnsari

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

It works for me. Thanks

silence0618 avatar Jul 24 '23 20:07 silence0618

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

pratyush-1966 avatar Aug 13 '23 12:08 pratyush-1966

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.

Yingrjimsch avatar Aug 13 '23 15:08 Yingrjimsch

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.

dekwidap avatar Aug 15 '23 02:08 dekwidap

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

ozgurmsc avatar Aug 26 '23 10:08 ozgurmsc

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.

davidearlyoung avatar Aug 29 '23 05:08 davidearlyoung

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

archywillhe avatar Aug 30 '23 05:08 archywillhe

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?

davidearlyoung avatar Aug 30 '23 23:08 davidearlyoung

Pillow to 9.5.0

working with me,thanks you

tuha1994 avatar Sep 07 '23 14:09 tuha1994

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

SunYuhe26862 avatar Sep 13 '23 08:09 SunYuhe26862

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.

patrickmappedin avatar Oct 11 '23 20:10 patrickmappedin

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!

wtigga avatar Oct 25 '23 06:10 wtigga

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!

Rebeque avatar Nov 10 '23 22:11 Rebeque

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

NasrCH avatar Nov 22 '23 14:11 NasrCH

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!!!

crisstang avatar Jan 13 '24 01:01 crisstang

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

pranith7 avatar Feb 27 '24 05:02 pranith7

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 avatar May 08 '24 13:05 ShariShah1234

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: @.***>

ShariShah1234 avatar Aug 13 '24 14:08 ShariShah1234