1
0
forked from BRT/arc
arc/services/db/AccountInfoScreener.cpp
slava b1876bc3b9 Refactor includes and add AccountInfoScreener functionality
Updated include paths for consistent structure under the `db` directory. Added `AccountInfoScreener` for parsing card data using Tesseract OCR and enhanced related models. Removed unused code and simplified main workflow.
2025-04-21 23:12:21 +07:00

57 lines
1.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "AccountInfoScreener.h"
#include <QImage>
#include <QList>
#include <QDebug>
#include <qregularexpression.h>
#include "android/Card.h"
#include "tesseract/baseapi.h"
QList<Card> AccountInfoScreener::parseCardData(const QByteArray &imageData) {
QList<Card> cards;
// QImage image;
// if (!image.loadFromData(imageData)) {
// return {};
// }
// image = image.convertToFormat(QImage::Format_Grayscale8);
QImage image("./images/img.png");
if (image.isNull()) {
return {};
}
// важная часть, без нее не парсит
image = image.convertToFormat(QImage::Format_Grayscale8);
tesseract::TessBaseAPI tess;
if (tess.Init(nullptr, "rus")) {
qDebug() << "Ошибка инициализации Tesseract с русским языком....";
}
tess.SetImage(image.bits(), image.width(), image.height(), 1, image.bytesPerLine());
const QString result = QString::fromUtf8(tess.GetUTF8Text());
qDebug() << "Распознанный текст:" << result;
const QRegularExpression re(R"((дебетовая(?:, цифровая)?),\s*\*(\d{4})\s+([\d]+\.\d{2})\s*Р)",
QRegularExpression::CaseInsensitiveOption);
QRegularExpressionMatchIterator i = re.globalMatch(result);
while (i.hasNext()) {
auto card = Card();
bool ok;
QRegularExpressionMatch match = i.next();
const double amount = match.captured(3).toDouble(&ok);
if (ok) {
card.amount = amount;
card.name = match.captured(2);
card.description = match.captured(1);
cards.append(card);
}
}
return cards;
}