Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashes with PIL.Image issues when trying to capture text #255

Closed
knochenhans opened this issue Sep 1, 2022 · 1 comment · Fixed by #257
Closed

Crashes with PIL.Image issues when trying to capture text #255

knochenhans opened this issue Sep 1, 2022 · 1 comment · Fixed by #257
Assignees
Labels
bug Something isn't working

Comments

@knochenhans
Copy link

Hi, I’m running into the following issue when I try to capture text with the current build (0.3.9, also happens in 0.3.8). I guess this is some kind of version mismatch regarding PIL? I’m using python-pillow 9.2.0.

23:16:50 - INFO    - normcap:36 - Start NormCap v0.3.9
23:16:50 - DEBUG   - normcap:57 - System info:
{'cli_args': '/usr/bin/normcap', 'is_prebuild_package': None, 'platform': 'linux', 'pyside6_version': '6.3.1', 'qt_version': '6.3.1', 'qt_library_path': '/home/andre/.local/lib/python3.10/site-packages/PySide6/Qt/plugins, /usr/bin', 'config_directory': PosixPath('/home/andre/.config/normcap'), 'normcap_version': '0.3.9', 'tessdata_path': '', 'envs': {'TESSERACT_CMD': None, 'TESSERACT_VERSION': None, 'TESSDATA_PREFIX': None, 'LD_LIBRARY_PATH': None}, 'desktop_environment': <DesktopEnvironment.OTHER: 0>, 'display_manager_is_wayland': False, 'gnome_version': None, 'screens': {0: Screen(is_primary=True, device_pixel_ratio=1.0, geometry=Rect(left=0, top=0, right=1920, bottom=1080), index=0, screenshot=None)}}
23:16:50 - DEBUG   - normcap.gui.tray:51 - Set up tray icon
23:16:50 - DEBUG   - normcap.clipboard.linux:42 - Use Qt to copy to clipboard.
23:16:50 - DEBUG   - normcap.screengrab.qt:15 - Use capture method: QT
23:16:50 - DEBUG   - normcap.gui.utils:44 - Store debug image in: /tmp/normcap/2022-09-01_23-16-50_663605_raw_screen0.png
23:16:50 - DEBUG   - normcap.gui.window:51 - Create window for screen 0
23:16:50 - DEBUG   - normcap.gui.window:199 - Set window for screen 0 to fullscreen
23:16:54 - DEBUG   - normcap.gui.tray:257 - Hide 1 window(s)
23:16:54 - INFO    - normcap.gui.tray:182 - Crop image to selected region (1226, 389, 1692, 414)
23:16:54 - DEBUG   - normcap.gui.utils:44 - Store debug image in: /tmp/normcap/2022-09-01_23-16-54_169208_cropped.png
23:16:54 - DEBUG   - normcap.gui.tray:214 - Start OCR
23:16:54 - DEBUG   - normcap.ocr.enhance:54 - Resize screenshot by factor 3.2
23:16:54 - CRITICAL - normcap.gui.utils:160 - Uncaught exception! Quitting NormCap!

System:

{  'cli_args': '/usr/bin/normcap',
   'config_directory': PosixPath('/home/REDACTED/.config/normcap'),
   'desktop_environment': <DesktopEnvironment.OTHER: 0>,
   'display_manager_is_wayland': False,
   'envs': {  'LD_LIBRARY_PATH': None,
              'TESSDATA_PREFIX': None,
              'TESSERACT_CMD': None,
              'TESSERACT_VERSION': None},
   'gnome_version': None,
   'is_prebuild_package': None,
   'normcap_version': '0.3.9',
   'platform': 'linux',
   'pyside6_version': '6.3.1',
   'qt_library_path': '/home/REDACTED/.local/lib/python3.10/site-packages/PySide6/Qt/plugins, '
                      '/usr/bin',
   'qt_version': '6.3.1',
   'screens': {  0: Screen(is_primary=True,
                           device_pixel_ratio=1.0,
                           geometry=Rect(left=0,
                                         top=0,
                                         right=1920,
                                         bottom=1080),
                           index=0,
                           screenshot=None)},
   'tessdata_path': ''}

Variables:

   '_capture_to_ocr': {'self': 'REDACTED'},
   'preprocess': {  'image': <PIL.Image.Image image mode=RGB size=466x25 at 0x7FBEDCE89B40>,
                    'padding': 80,
                    'resize_factor': 3.2},
   'recognize': {  'image': <PIL.PngImagePlugin.PngImageFile image mode=RGB size=466x25 at 0x7FBEDD0DE5F0>,
                   'languages': (...,),
                   'padding_size': 80,
                   'parse': True,
                   'resize_factor': 3.2,
                   'tessdata_path': ''},
   'resize_image': {  'factor': 3.2,
                      'image': <PIL.Image.Image image mode=RGB size=466x25 at 0x7FBEDCE89B40>}}

Exception:

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

Traceback:

  File "/usr/lib/python3.10/site-packages/normcap/gui/tray.py", line 215, in _capture_to_ocr
    ocr_result = ocr.recognize(
  File "/usr/lib/python3.10/site-packages/normcap/ocr/recognize.py", line 28, in recognize
    image = enhance.preprocess(image, resize_factor=resize_factor, padding=padding_size)
  File "/usr/lib/python3.10/site-packages/normcap/ocr/enhance.py", line 82, in preprocess
    image = resize_image(image, factor=resize_factor)
  File "/usr/lib/python3.10/site-packages/normcap/ocr/enhance.py", line 57, in resize_image
    resample=Image.Resampling.LANCZOS,  # type: ignore
  File "/home/REDACTED/.local/lib/python3.10/site-packages/PIL/Image.py", line 62, in __getattr__
    raise AttributeError("module '{}' has no attribute '{}'".format(__name__, name))
@dynobo
Copy link
Owner

dynobo commented Sep 3, 2022

Thanks for reporting, @knochenhans !

Indeed, there was recently a hidden and somewhat debatable breaking API change in Pillow.

I'm working on fixing that for NormCap.

@dynobo dynobo self-assigned this Sep 3, 2022
@dynobo dynobo added the bug Something isn't working label Sep 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants