You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introducing new APIs to assist with detecting and reporting overlarge 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)
Copy file name to clipboardExpand all lines: include/tesseract/baseapi.h
+32
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,7 @@
28
28
#include"unichar.h"
29
29
30
30
#include<tesseract/version.h>
31
+
#include<tesseract/memcost_estimate.h>// for ImageCostEstimate
31
32
32
33
#include<cstdio>
33
34
#include<tuple>// for std::tuple
@@ -119,6 +120,37 @@ class TESS_API TessBaseAPI {
119
120
voidSetVisibleImage(Pix *pix);
120
121
Pix* GetVisibleImage();
121
122
123
+
/**
124
+
* Return a memory capacity cost estimate for the given image dimensions and
125
+
* some heuristics re tesseract behaviour, e.g. input images will be normalized/greyscaled,
126
+
* then thresholded, all of which will be kept in memory while the session runs.
127
+
*
128
+
* Also uses the Tesseract Variable `allowed_image_memory_capacity` to indicate
129
+
* whether the estimated cost is oversized --> `cost.is_too_large()`
130
+
*
131
+
* For user convenience, static functions are provided:
132
+
* the static functions MAY be used by userland code *before* the high cost of
133
+
* instantiating a Tesseract instance is incurred.
134
+
*/
135
+
static ImageCostEstimate EstimateImageMemoryCost(int image_width, int image_height, float allowance = 1.0e30f /* a.k.a.dont_care, use system limit and be done */ );
136
+
static ImageCostEstimate EstimateImageMemoryCost(const Pix* pix, float allowance = 1.0e30f /* a.k.a. dont_care, use system limit and be done */ );
137
+
138
+
/**
139
+
* Ditto, but this API may be invoked after SetInputImage() or equivalent has been called
140
+
* and reports the cost estimate for the current instance/image.
Copy file name to clipboardExpand all lines: src/api/baseapi.cpp
+82-4
Original file line number
Diff line number
Diff line change
@@ -75,6 +75,7 @@
75
75
#include<set>// for std::pair
76
76
#include<sstream>// for std::stringstream
77
77
#include<vector>// for std::vector
78
+
#include<cfloat>
78
79
79
80
#include<allheaders.h>// for pixDestroy, boxCreate, boxaAddBox, box...
80
81
#ifdef HAVE_LIBCURL
@@ -106,14 +107,15 @@ namespace tesseract {
106
107
107
108
FZ_HEAPDBG_TRACKER_SECTION_START_MARKER(_)
108
109
109
-
staticBOOL_VAR(stream_filelist, false, "Stream a filelist from stdin");
110
-
staticSTRING_VAR(document_title, "", "Title of output document (used for hOCR and PDF output)");
110
+
BOOL_VAR(stream_filelist, false, "Stream a filelist from stdin");
111
+
STRING_VAR(document_title, "", "Title of output document (used for hOCR and PDF output)");
111
112
#ifdef HAVE_LIBCURL
112
-
staticINT_VAR(curl_timeout, 0, "Timeout for curl in seconds");
113
+
INT_VAR(curl_timeout, 0, "Timeout for curl in seconds");
113
114
#endif
114
115
BOOL_VAR(debug_all, false, "Turn on all the debugging features");
115
116
STRING_VAR(vars_report_file, "+", "Filename/path to write the 'Which -c variables were used' report. File may be 'stdout', '1' or '-' to be output to stdout. File may be 'stderr', '2' or '+' to be output to stderr. Empty means no report will be produced.");
116
117
BOOL_VAR(report_all_variables, true, "When reporting the variables used (via 'vars_report_file') also report all *unused* variables, hence the report will always list *all available variables.");
118
+
double_VAR(allowed_image_memory_capacity, ImageCostEstimate::get_max_system_allowance(), "Set maximum memory allowance for image data: this will be used as part of a sanity check for oversized input images.");
117
119
118
120
119
121
/** Minimum sensible image size to be worth running tesseract. */
0 commit comments