Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/api/baseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ int TessBaseAPI::Recognize(ETEXT_DESC *monitor) {
delete page_res_;
if (block_list_->empty()) {
page_res_ = new PAGE_RES(false, block_list_, &tesseract_->prev_word_best_choice_);
recognition_done_ = true;
return 0; // Empty page.
}

Expand Down
31 changes: 31 additions & 0 deletions unittest/baseapi_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,37 @@ TEST_F(TesseractTest, HOCRContainsBaseline) {
src_pix.destroy();
}

// Tests that all output formats return valid results on an empty page.
// Regression test for https://github.com/tesseract-ocr/tesseract/issues/4112
TEST_F(TesseractTest, EmptyPageOutputConsistency) {
tesseract::TessBaseAPI api;
if (api.Init(TessdataPath().c_str(), "eng", tesseract::OEM_LSTM_ONLY) == -1) {
// eng.traineddata not found.
GTEST_SKIP();
}
// Create a blank white image (no text to detect).
Image blank_pix = pixCreate(200, 200, 8);
CHECK(blank_pix);
pixSetAll(blank_pix);
api.SetImage(blank_pix);
ASSERT_EQ(api.Recognize(nullptr), 0);

// All output formats should return non-null, even on an empty page.
char *hocr = api.GetHOCRText(0);
EXPECT_TRUE(hocr != nullptr);
delete[] hocr;

char *utf8 = api.GetUTF8Text();
EXPECT_TRUE(utf8 != nullptr);
delete[] utf8;

char *tsv = api.GetTSVText(0);
EXPECT_TRUE(tsv != nullptr);
delete[] tsv;

blank_pix.destroy();
}

// Tests that Tesseract gets exactly the right answer on some page numbers.
TEST_F(TesseractTest, AdaptToWordStrTest) {
#ifdef DISABLED_LEGACY_ENGINE
Expand Down