Skip to content

Commit

Permalink
Fix resuming training without lstmf files
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Mar 25, 2024
1 parent 0b300a9 commit d8192f0
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions src/ccstruct/imagedata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,34 +550,19 @@ bool DocumentData::ReCachePages() {
#if !defined(TESSERACT_IMAGEDATA_AS_PIX)
if (document_name_.ends_with("png")) {
// PDF image given instead of LSTMF file.
#if 1
std::string gt_name = document_name_.substr(0, document_name_.length() - 3) + "gt.txt";
std::ifstream t(gt_name);
std::string line;
std::getline(t, line);
t.close();
ImageData *image_data = ImageData::Build(document_name_.c_str(), 0, "", nullptr, 0, line.c_str(), nullptr);
Image image = pixRead(document_name_.c_str());
image_data->SetPix(image);
#else
ImageData *image_data = new ImageData;
image_data->set_imagefilename(document_name_);
image_data->set_page_number(0);
Image image = pixRead(document_name_.c_str());
image_data->SetPix(image);
auto height = pixGetHeight(image);
auto width = pixGetWidth(image);
std::string gt_name = document_name_.substr(0, document_name_.length() - 3) + "gt.txt";
std::ifstream t(gt_name);
std::string line;
std::getline(t, line);
//std::stringstream buffer;
//buffer << t.rdbuf();
#endif
t.close();
//image_data->transcription_ = buffer.str();
pages_.push_back(image_data);
set_total_pages(1);
loaded_pages = 1;
pages_offset_ %= loaded_pages;
set_total_pages(loaded_pages);
set_memory_used(memory_used() + image_data->MemoryUsed());
if (true) {
tprintf("Loaded %zu/%d lines (%d-%zu) of document %s\n", pages_.size(),
loaded_pages, pages_offset_ + 1, pages_offset_ + pages_.size(),
Expand Down

0 comments on commit d8192f0

Please sign in to comment.