starting work on image module

This commit is contained in:
leca 2024-08-31 22:18:54 +03:00
parent 2a726a96b7
commit f9b0b75062
6 changed files with 136 additions and 37 deletions

View File

@ -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)

23
image/checkimage.cpp Normal file
View File

@ -0,0 +1,23 @@
#include <string>
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>
#include <opencv2/opencv.hpp>
#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;
}

15
image/checkimage.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef CHECKIMAGE_H
#define CHECKIMAGE_H
#include <string>
class CheckImage {
std::string path;
public:
CheckImage(std::string path);
std::string parse_text();
};
#endif // CHECKIMAGE_H

View File

@ -1,14 +1,11 @@
#include "mainwindow.h"
#include "ofd/ofd.h"
#include "utils/utils.h"
#include <iostream>
#include <QApplication>
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

View File

@ -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;
}
}

View File

@ -37,12 +37,48 @@
<string>Store</string>
</property>
</widget>
<widget class="QWidget" name="checkInfo" native="true">
<widget class="QLabel" name="checkTypeLabel">
<property name="geometry">
<rect>
<x>10</x>
<y>50</y>
<width>81</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Check type</string>
</property>
</widget>
<widget class="QComboBox" name="checkType">
<property name="geometry">
<rect>
<x>90</x>
<y>50</y>
<width>211</width>
<height>26</height>
</rect>
</property>
<item>
<property name="text">
<string>Text</string>
</property>
</item>
<item>
<property name="text">
<string>Image (not yet implemented)</string>
</property>
</item>
</widget>
<widget class="QWidget" name="checkInfoText" native="true">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>90</y>
<width>801</width>
<y>70</y>
<width>421</width>
<height>511</height>
</rect>
</property>
@ -86,38 +122,58 @@
</property>
</widget>
</widget>
<widget class="QLabel" name="storeTypeLabel_2">
<widget class="QTabWidget" name="tabWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>50</y>
<width>81</width>
<height>20</height>
<x>460</x>
<y>270</y>
<width>301</width>
<height>221</height>
</rect>
</property>
<property name="text">
<string>Check type</string>
<property name="tabPosition">
<enum>QTabWidget::TabPosition::North</enum>
</property>
</widget>
<widget class="QComboBox" name="checkType">
<property name="geometry">
<rect>
<x>90</x>
<y>50</y>
<width>211</width>
<height>26</height>
</rect>
<property name="tabShape">
<enum>QTabWidget::TabShape::Rounded</enum>
</property>
<item>
<property name="text">
<property name="currentIndex">
<number>0</number>
</property>
<property name="elideMode">
<enum>Qt::TextElideMode::ElideNone</enum>
</property>
<property name="documentMode">
<bool>true</bool>
</property>
<property name="tabsClosable">
<bool>false</bool>
</property>
<property name="tabBarAutoHide">
<bool>true</bool>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Text</string>
</property>
</item>
<item>
<property name="text">
<string>Image (not yet implemented)</string>
</property>
</item>
</attribute>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Image</string>
</attribute>
</widget>
</widget>
<widget class="QStackedWidget" name="stackedWidget">
<property name="geometry">
<rect>
<x>460</x>
<y>60</y>
<width>241</width>
<height>151</height>
</rect>
</property>
<widget class="QWidget" name="page_5"/>
<widget class="QWidget" name="page_6"/>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">