Fix for windows
This commit is contained in:
parent
e9aaa71c56
commit
1ed7cbe6f7
@ -33,11 +33,24 @@ static QString recognizeTextFromImage(const QByteArray &pngData) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
api->SetImage(pix);
|
// Convert to grayscale for better OCR accuracy
|
||||||
|
Pix *gray = pixConvertRGBToGray(pix, 0.0f, 0.0f, 0.0f);
|
||||||
|
pixDestroy(&pix);
|
||||||
|
if (!gray) {
|
||||||
|
qWarning() << "[OCR] Failed to convert to grayscale";
|
||||||
|
api->End();
|
||||||
|
delete api;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
api->SetImage(gray);
|
||||||
|
// adb screencap PNGs lack DPI metadata; set 300 DPI so Tesseract
|
||||||
|
// interprets character sizes correctly
|
||||||
|
api->SetSourceResolution(300);
|
||||||
char *text = api->GetUTF8Text();
|
char *text = api->GetUTF8Text();
|
||||||
QString result = QString::fromUtf8(text).trimmed();
|
QString result = QString::fromUtf8(text).trimmed();
|
||||||
delete[] text;
|
delete[] text;
|
||||||
pixDestroy(&pix);
|
pixDestroy(&gray);
|
||||||
api->End();
|
api->End();
|
||||||
delete api;
|
delete api;
|
||||||
|
|
||||||
@ -45,8 +58,9 @@ static QString recognizeTextFromImage(const QByteArray &pngData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static QString extractTransactionId(const QString &ocrText) {
|
static QString extractTransactionId(const QString &ocrText) {
|
||||||
// "ID операции A60130542076330K0000040011670301" или "ID операции = Аб60650..."
|
// Ищем по слову "операции" — OCR часто искажает "ID" перед ним
|
||||||
QRegularExpression reId(R"(ID\s+операции\s*=?\s*([A-Za-zА-Яа-я0-9]+))");
|
// \S{1,3} вместо точного "ID" покрывает любые OCR-ошибки (1О, 1Ю, ID, 10 и т.д.)
|
||||||
|
QRegularExpression reId(R"(\S{1,3}\s+операции\s*=?\s*([A-Za-zА-Яа-яЁё0-9]+))");
|
||||||
if (auto m = reId.match(ocrText); m.hasMatch()) return m.captured(1);
|
if (auto m = reId.match(ocrText); m.hasMatch()) return m.captured(1);
|
||||||
|
|
||||||
// "№ Ф-2026-25235663"
|
// "№ Ф-2026-25235663"
|
||||||
@ -333,6 +347,8 @@ void GetLastTransactionsScript::doStart() {
|
|||||||
qDebug() << "[GetLastTransactions] OCR result, txId:" << saved.id
|
qDebug() << "[GetLastTransactions] OCR result, txId:" << saved.id
|
||||||
<< "\n--- OCR TEXT START ---\n" << ocrText
|
<< "\n--- OCR TEXT START ---\n" << ocrText
|
||||||
<< "\n--- OCR TEXT END ---";
|
<< "\n--- OCR TEXT END ---";
|
||||||
|
qDebug() << "[GetLastTransactions] OCR hex:"
|
||||||
|
<< ocrText.left(200).toUtf8().toHex(' ');
|
||||||
const QString txId = extractTransactionId(ocrText);
|
const QString txId = extractTransactionId(ocrText);
|
||||||
if (!txId.isEmpty()) {
|
if (!txId.isEmpty()) {
|
||||||
TransactionDAO::updateBankTrExternalId(saved.id, txId);
|
TransactionDAO::updateBankTrExternalId(saved.id, txId);
|
||||||
|
|||||||
BIN
eng.traineddata
Normal file
BIN
eng.traineddata
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user