| 266 | } |
| 267 | |
| 268 | QString 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 | |
| 298 | bool Tesseract::isValid() const |
| 299 | { |