Skip to content

Commit 3dcb5c2

Browse files
scottb89amitdo
scottb89
authored andcommitted
Bypass Leptonica error message with pixGenHalftoneMask()
Fixes #292
1 parent 1958b3b commit 3dcb5c2

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

textord/imagefind.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,21 @@ Pix* ImageFind::FindImages(Pix* pix) {
6767
if (pixGetWidth(pix) < kMinImageFindSize ||
6868
pixGetHeight(pix) < kMinImageFindSize)
6969
return pixCreate(pixGetWidth(pix), pixGetHeight(pix), 1);
70+
7071
// Reduce by factor 2.
7172
Pix *pixr = pixReduceRankBinaryCascade(pix, 1, 0, 0, 0);
7273
pixDisplayWrite(pixr, textord_tabfind_show_images);
7374

7475
// Get the halftone mask directly from Leptonica.
76+
//
77+
// Leptonica will print an error message and return NULL if we call
78+
// pixGenHalftoneMask(pixr, NULL, ...) with too small image, so we
79+
// want to bypass that.
80+
if (pixGetWidth(pixr) < kMinImageFindSize ||
81+
pixGetHeight(pixr) < kMinImageFindSize) {
82+
pixDestroy(&pixr);
83+
return pixCreate(pixGetWidth(pix), pixGetHeight(pix), 1);
84+
}
7585
l_int32 ht_found = 0;
7686
Pix *pixht2 = pixGenHalftoneMask(pixr, NULL, &ht_found,
7787
textord_tabfind_show_images);

0 commit comments

Comments
 (0)