MCPcopy Create free account
hub / github.com/OneMoreGres/ScreenTranslator / recognize

Method recognize

src/ocr/tesseract.cpp:268–296  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

266}
267
268QString Tesseract::recognize(const QPixmap &source)
269{
270 SOFT_ASSERT(api_, return {});
271 SOFT_ASSERT(!source.isNull(), return {});
272
273 error_.clear();
274
275 PixGuard image(prepareImage(source.toImage()));
276 SOFT_ASSERT(image, return {});
277 LTRACE() << "Preprocessed Pix for OCR" << image;
278
279 api_->SetImage(image);
280 LTRACE() << "Set Pix to engine";
281
282 const auto outText = api_->GetUTF8Text();
283 LTRACE() << "Received recognized text";
284
285 api_->Clear();
286 LTRACE() << "Cleared engine";
287
288 const auto result = QString(outText).trimmed();
289
290 delete[] outText;
291 LTRACE() << "Cleared recognized text buffer";
292
293 if (result.isEmpty())
294 error_ = QObject::tr("Failed to recognize text or no text selected");
295 return result;
296}
297
298bool Tesseract::isValid() const
299{

Callers 2

capturedMethod · 0.45
handleMethod · 0.45

Calls 4

prepareImageFunction · 0.85
isNullMethod · 0.80
ClearMethod · 0.80
QStringClass · 0.50

Tested by

no test coverage detected