Remove unused tesseract engines after some time
This commit is contained in:
parent
5397521c79
commit
d931015d6b
@ -33,6 +33,9 @@ void RecognizeWorker::handle(const TaskPtr &task)
|
|||||||
if (result->recognized.isEmpty())
|
if (result->recognized.isEmpty())
|
||||||
result->error = engine->error();
|
result->error = engine->error();
|
||||||
|
|
||||||
|
lastGenerations_[task->sourceLanguage] = task->generation;
|
||||||
|
removeUnused(task->generation);
|
||||||
|
|
||||||
emit finished(result);
|
emit finished(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,3 +47,17 @@ void RecognizeWorker::reset(const QString &tessdataPath)
|
|||||||
tessdataPath_ = tessdataPath;
|
tessdataPath_ = tessdataPath;
|
||||||
engines_.clear();
|
engines_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RecognizeWorker::removeUnused(Generation current)
|
||||||
|
{
|
||||||
|
const auto keepGenerations = 10;
|
||||||
|
for (auto it = lastGenerations_.begin(), end = lastGenerations_.end();
|
||||||
|
it != end;) {
|
||||||
|
if (current - it->second < keepGenerations) {
|
||||||
|
++it;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
engines_.erase(it->first);
|
||||||
|
it = lastGenerations_.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -19,6 +19,9 @@ signals:
|
|||||||
void finished(const TaskPtr &task);
|
void finished(const TaskPtr &task);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void removeUnused(Generation current);
|
||||||
|
|
||||||
std::map<QString, std::unique_ptr<Tesseract>> engines_;
|
std::map<QString, std::unique_ptr<Tesseract>> engines_;
|
||||||
|
std::map<QString, Generation> lastGenerations_;
|
||||||
QString tessdataPath_;
|
QString tessdataPath_;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user