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

Maximum supported image size #3184

Open
MerlijnWajer opened this issue Dec 18, 2020 · 8 comments
Open

Maximum supported image size #3184

MerlijnWajer opened this issue Dec 18, 2020 · 8 comments
Milestone

Comments

@MerlijnWajer
Copy link
Contributor

Environment

  • Tesseract Version: 4.1.1 and latest master
  • Platform: Linux gentoo-x230 5.6.18-grsec #2 SMP Tue Jul 7 18:17:17 CEST 2020 x86_64 Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz GenuineIntel GNU/Linux

Current Behavior:

On large images, Tesseract fails like this:

Tesseract Open Source OCR Engine v4.1.1 with Leptonica
Warning: Invalid resolution 0 dpi. Using 70 instead.
Image too large: (2559, 37192)
Error during processing.

This is the image in question (large image!):
https://archive.org/download/manualzz-id-765154/765154_jp2.zip/765154_jp2/765154_0017.jp2

Expected Behavior:

Tesseract would process the image without erroring out.

Comments

I don't know where exactly this limitation comes from. I see that the specific error comes from the Otsu thresholding code, but I am not sure if the limit of 2^15 (INT16_MAX) limit is actually also a leptonica maximum size limit.

Perhaps this is not considered a problem and the bug can be closed, but as it stands I am not sure what the best practice would be to OCR the image linked above. Perhaps the limit can be raised some, to 2^16 ?

@stweil
Copy link
Contributor

stweil commented Jan 23, 2021

@MerlijnWajer, did you replace the image? I just loaded the image from the URL above, and it works because the size is 1706 x 24795 which is supported by the current tesseract.

Leptonica uses l_int32 for image dimensions.

@stweil stweil added this to the 5.0.0 milestone Jan 23, 2021
@MerlijnWajer
Copy link
Contributor Author

Yes, unfortunately someone changed the image to make it work for the existing item I linked to. I'll try to provide another sample file.

@MerlijnWajer
Copy link
Contributor Author

@amitdo
Copy link
Collaborator

amitdo commented Mar 16, 2021

bool ImageThresholder::ThresholdToPix(PageSegMode pageseg_mode, Pix **pix) {
if (image_width_ > INT16_MAX || image_height_ > INT16_MAX) {
tprintf("Image too large: (%d, %d)\n", image_width_, image_height_);
return false;
}

@MerlijnWajer
Copy link
Contributor Author

MerlijnWajer commented May 18, 2021

It looks like with 57b79742920cdda6d72e4fd7d0cab218db22f08b this limit is removed, and now the output is:

$ tesseract -c thresholding_method=2 /tmp/সহজ_কুরআন_শিক্ষা_0005.jp2 -
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()

@stweil
Copy link
Contributor

stweil commented May 19, 2021

Several Tesseract classes are currently limited to images with a maximum width and heigth of 32767 (INT16_MAX) because they use int16_t coordinates. Here is a list of classes identified so far:

TPOINT, BLOCK, PDBLK, ICOORD, ICOORDELT, TBOX, OL_BUCKETS

For some of those it might be possible to replace int16_t by uint16_t which would raise the limit for image dimensions to 65535, but some also use negative values. So maybe we have to use int32_t (which is compatible with Leptonica).

@stweil
Copy link
Contributor

stweil commented May 19, 2021

@MerlijnWajer, if you want you can test pull request #3435 for your large images. I still don't consider that as stable code, so would not use it for production of normal sized images.

@MerlijnWajer
Copy link
Contributor Author

Great! I'll try to do this next week.

GerHobbelt added a commit to GerHobbelt/tesseract that referenced this issue Feb 27, 2023
… input images. Available to both userland and tesseract internal code, these can be used to report & early fail images which are too large to fit in memory.

Some very lenient defaults are used for the memory pressure allowance (1.5 GByte for 32bit builds, 64GByte for 64bit builds) but this can be tweaked to your liking and local machine shop via Tesseract Global Variable `allowed_image_memory_capacity` (DOUBLE type).

NOTE: the allowance limit can be effectively removed by setting this variable to an 'insane' value, e.g. `1.0e30`.
HOWEVER, the CheckAndReportIfImageTooLarge() API will still fire for images with either width or high dimension >= TDIMENSION_MAX, which in the default built is the classic INT16_MAX (32767px); when compiled with defined(LARGE_IMAGES), then the width/height limit is raised to 24bit i.e. ~ 16.7 Mpx, which would then tolerate images smaller than 16777216 x 16777216px. (This latter part is a work-in-progress.)

Related:

- tesseract-ocr#3184
- tesseract-ocr#3885
- tesseract-ocr#3435 (pullreq by @stweil -- WIP)

# Conflicts:
#	src/api/baseapi.cpp
#	src/ccmain/tesseractclass.h
#	src/ccmain/thresholder.cpp
#	src/ccutil/params.h
#	src/textord/tordmain.cpp
GerHobbelt added a commit to GerHobbelt/tesseract that referenced this issue Feb 27, 2023
… input images. Available to both userland and tesseract internal code, these can be used to report & early fail images which are too large to fit in memory.

Some very lenient defaults are used for the memory pressure allowance (1.5 GByte for 32bit builds, 64GByte for 64bit builds) but this can be tweaked to your liking and local machine shop via Tesseract Global Variable `allowed_image_memory_capacity` (DOUBLE type).

NOTE: the allowance limit can be effectively removed by setting this variable to an 'insane' value, e.g. `1.0e30`.
HOWEVER, the CheckAndReportIfImageTooLarge() API will still fire for images with either width or high dimension >= TDIMENSION_MAX, which in the default built is the classic INT16_MAX (32767px); when compiled with defined(LARGE_IMAGES), then the width/height limit is raised to 24bit i.e. ~ 16.7 Mpx, which would then tolerate images smaller than 16777216 x 16777216px. (This latter part is a work-in-progress.)

Related:

- tesseract-ocr#3184
- tesseract-ocr#3885
- tesseract-ocr#3435 (pullreq by @stweil -- WIP)
@stweil stweil modified the milestones: 5.0.0, 6.0.0 Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants