From f9b0b75062c6638b685f6d95494d92f841da679a Mon Sep 17 00:00:00 2001 From: leca Date: Sat, 31 Aug 2024 22:18:54 +0300 Subject: [PATCH] starting work on image module --- CMakeLists.txt | 14 ++++-- image/checkimage.cpp | 23 +++++++++ image/checkimage.h | 15 ++++++ main.cpp | 5 +- mainwindow.cpp | 4 +- mainwindow.ui | 112 ++++++++++++++++++++++++++++++++----------- 6 files changed, 136 insertions(+), 37 deletions(-) create mode 100644 image/checkimage.cpp create mode 100644 image/checkimage.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 831ffca..bcae8c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ set(PROJECT_SOURCES mainwindow.ui ) + if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(checks-parser MANUAL_FINALIZATION @@ -48,14 +49,12 @@ else() ofd/ofd.h ofd/ofd.cpp ofd/module.h ofd/module.cpp utils/utils.h utils/utils.cpp + image/checkimage.h image/checkimage.cpp ) endif() endif() target_link_libraries(checks-parser PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) - - - # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. # If you are developing for iOS or macOS you should consider setting an # explicit, fixed bundle identifier manually though. @@ -86,3 +85,12 @@ FetchContent_Declare(cpr GIT_REPOSITORY https://github.com/libcpr/cpr.git GIT_TAG 3b15fa82ea74739b574d705fea44959b58142eb8) FetchContent_MakeAvailable(cpr) target_link_libraries(checks-parser PRIVATE cpr::cpr) + + +find_package(PkgConfig REQUIRED) + +pkg_search_module(opencv REQUIRED IMPORTED_TARGET opencv) +target_link_libraries(checks-parser PRIVATE PkgConfig::opencv) +target_link_libraries(checks-parser PRIVATE -ltesseract) + + diff --git a/image/checkimage.cpp b/image/checkimage.cpp new file mode 100644 index 0000000..caddf3d --- /dev/null +++ b/image/checkimage.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +#include +#include "checkimage.h" + +CheckImage::CheckImage(std::string path) { + this->path = path; +} + +std::string CheckImage::parse_text() { + std::string result; + + tesseract::TessBaseAPI *ocr = new tesseract::TessBaseAPI(); + ocr->Init(NULL, "rus", tesseract::OEM_LSTM_ONLY); + ocr->SetPageSegMode(tesseract::PSM_AUTO); + + cv::Mat im = cv::imread(this->path, cv::IMREAD_COLOR); + ocr->SetImage(im.data, im.cols, im.rows, 3, im.step); + result = std::string(ocr->GetUTF8Text()); + + return result; +} diff --git a/image/checkimage.h b/image/checkimage.h new file mode 100644 index 0000000..54496f9 --- /dev/null +++ b/image/checkimage.h @@ -0,0 +1,15 @@ +#ifndef CHECKIMAGE_H +#define CHECKIMAGE_H + +#include + +class CheckImage { + std::string path; +public: + CheckImage(std::string path); + + std::string parse_text(); + +}; + +#endif // CHECKIMAGE_H diff --git a/main.cpp b/main.cpp index 799388d..0e713fb 100644 --- a/main.cpp +++ b/main.cpp @@ -1,14 +1,11 @@ #include "mainwindow.h" -#include "ofd/ofd.h" -#include "utils/utils.h" -#include #include int main(int argc, char *argv[]) { + QApplication a(argc, argv); MainWindow w; w.show(); - return a.exec(); } diff --git a/mainwindow.cpp b/mainwindow.cpp index 523fb2f..58afbb0 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -37,10 +37,10 @@ void MainWindow::setupStoresList() { void MainWindow::on_checkType_currentIndexChanged(int index) { switch (index) { case 0: - ui->checkInfo->setVisible(true); + ui->checkInfoText->setVisible(true); break; case 1: - ui->checkInfo->setVisible(false); + ui->checkInfoText->setVisible(false); break; } } diff --git a/mainwindow.ui b/mainwindow.ui index 0b4d814..06903e4 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -37,12 +37,48 @@ Store - + + + + 10 + 50 + 81 + 20 + + + + Check type + + + + + + 90 + 50 + 211 + 26 + + + + + Text + + + + + Image (not yet implemented) + + + + + + true + 0 - 90 - 801 + 70 + 421 511 @@ -86,38 +122,58 @@ - + - 10 - 50 - 81 - 20 + 460 + 270 + 301 + 221 - - Check type + + QTabWidget::TabPosition::North - - - - - 90 - 50 - 211 - 26 - + + QTabWidget::TabShape::Rounded - - + + 0 + + + Qt::TextElideMode::ElideNone + + + true + + + false + + + true + + + Text - - - - - Image (not yet implemented) - - + + + + + Image + + + + + + + 460 + 60 + 241 + 151 + + + +