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.
57 lines
1.7 KiB
C++
57 lines
1.7 KiB
C++
#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;
|
||
}
|