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

supplant imutils with something maintained #141

Open
bertsky opened this issue Dec 1, 2024 · 3 comments · May be fixed by #146
Open

supplant imutils with something maintained #141

bertsky opened this issue Dec 1, 2024 · 3 comments · May be fixed by #146

Comments

@bertsky
Copy link
Contributor

bertsky commented Dec 1, 2024

Eynollah currently relies on https://github.com/PyImageSearch/imutils:

imutils >= 0.5.3

However, this still uses distutils and setup.py, does not track its dependencies, and does not install for me:

pip install imutils
Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com
Collecting imutils
  Downloading imutils-0.5.4.tar.gz (17 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [1 lines of output]
      ERROR: Can not execute `setup.py` since setuptools is not available in the build environment.
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

(The same happens with --no-build-isolation.)

(Of course, I do have an up-to-date setuptools, wheel, and pip, so the error message itself is also broken. The point is that this library cannot be installed out of the box anymore.)

There have even been two PRs – this one and that one trying to fix these issues, but it has been closed by the author because imutils seems to be entirely unmaintained.

So I think this dependency should be removed.

@cneud
Copy link
Member

cneud commented Mar 3, 2025

Thanks for reporting! I agree that imutils should be removed as a dependency.

From what I could find imutils is only used in rotate.py in these three functions:

def rotation_image_new(img, thetha):

def rotation_not_90_func(img, textline, text_regions_p_1, table_prediction, thetha):

def rotation_not_90_func_full_layout(img, textline, text_regions_p_1, text_regions_p_fully, thetha):

The most efficient would imho be replacing these with their equivalent OpenCV implementations.

cneud added a commit that referenced this issue Mar 3, 2025
@cneud cneud linked a pull request Mar 3, 2025 that will close this issue
@cneud cneud linked a pull request Mar 3, 2025 that will close this issue
@bertsky
Copy link
Contributor Author

bertsky commented Mar 3, 2025

@cneud,

From what I could find imutils is only used in rotate.py in these three functions: [...]

Yes, that seems to be it.

And sbb_pixelwise_segmentation likewise uses imutils.rotate.

The most efficient would imho be replacing these with their equivalent OpenCV implementations.

I agree. But AFAIK OpenCV itself does not provide a high-level / abstracted operation for rotation which also avoids cropping, i.e. finds the new minimal bounding box and increasing the canvas size, and uses a high-quality interpolation. (That's why in OCR-D core I am still using Pillow's Image.rotate for this.)

Alternatively one could look at albumentations or imgaug, both of which are well maintained and using OpenCV as their backend, but albumentations being faster.

I advise against imgaug: it's not maintained ...

Image

... and the latest release has a bug.

Looking closer at albumentations this time, I also find it unsatisfactory: its Rotation does not strictly increase the image size. On the contrary, the boolean kwarg crop_border can only be used to strictly decrease the size (no black borders), but never to increase it:

https://github.com/albumentations-team/albumentations/blob/529b074309256272fd2f0b2fdd52ccc62183fc57/albumentations/augmentations/geometric/rotate.py#L164-L167

What does fit the bill (besides Pillow, which is slow), is scikit-image's skimage.transform.rotate, but (using Numpy) that's slower than OpenCV.

Tensorflow does not offer such an operator, but Pytorch does – and it is implemented via Pillow 😉

Looking for cv2-based code on Github, I found Bernhard's Origami does it correctly, so perhaps we should just copy this?

@cneud
Copy link
Member

cneud commented Mar 3, 2025

Thanks for looking into it further...I've been trying something very simple, but Bernhard's implementation seems solid - good find!

In sbb_pixelwise_segmentation there is only one occurence which is a duplication of Eynollah's code anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants