forked from AnvarNazar/Malayalam-OCR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
100 lines (81 loc) · 3.4 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->blurSizeSlider->setValue(blurSize);
ui->blurSizeBox->setValue(blurSize);
ui->charWidthBox->setValue(charWidth);
ui->charWidthSlider->setValue(charWidth);
ui->charHeightBox->setValue(charHeight);
ui->charHeightSlider->setValue(charHeight);
ui->contourAreaBox->setValue(contourArea);
ui->contourAreaSlider->setValue(contourArea);
ui->blockSizeBox->setValue(blockSize);
ui->blockSizeSlider->setValue(blockSize);
connect(ui->blurSizeSlider, SIGNAL(valueChanged(int)), ui->blurSizeBox, SLOT(setValue(int)));
connect(ui->blurSizeBox, SIGNAL(valueChanged(int)), ui->blurSizeSlider, SLOT(setValue(int)));
connect(ui->charWidthSlider, SIGNAL(valueChanged(int)), ui->charWidthBox, SLOT(setValue(int)));
connect(ui->charWidthBox, SIGNAL(valueChanged(int)), ui->charWidthSlider, SLOT(setValue(int)));
connect(ui->charHeightSlider, SIGNAL(valueChanged(int)), ui->charHeightBox, SLOT(setValue(int)));
connect(ui->charHeightBox, SIGNAL(valueChanged(int)), ui->charHeightSlider, SLOT(setValue(int)));
connect(ui->contourAreaSlider, SIGNAL(valueChanged(int)), ui->contourAreaBox, SLOT(setValue(int)));
connect(ui->contourAreaBox, SIGNAL(valueChanged(int)), ui->contourAreaSlider, SLOT(setValue(int)));
connect(ui->blockSizeSlider, SIGNAL(valueChanged(int)), ui->blockSizeBox, SLOT(setValue(int)));
connect(ui->blockSizeBox, SIGNAL(valueChanged(int)), ui->blockSizeSlider, SLOT(setValue(int)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionOpen_triggered()
{
}
void MainWindow::processImage()
{
cv::cvtColor(image, imageGrayscale, CV_BGR2GRAY);
cv::GaussianBlur(imageGrayscale, imageBlurred, cv::Size(blurSize, blurSize), 0);
cv::adaptiveThreshold(imageBlurred, imageThresholded, 255, CV_ADAPTIVE_THRESH_GAUSSIAN_C, CV_THRESH_BINARY_INV, blockSize, 2);
imageThresholdedCopy = imageThresholded.clone();
}
void MainWindow::displayImage()
{
this->dImage = QImage(imageThresholdedCopy.data, imageThresholdedCopy.cols,
imageThresholdedCopy.rows, QImage::Format_Grayscale8);
ui->imageLabel->setPixmap(QPixmap::fromImage(dImage));
}
void MainWindow::on_actionImage_triggered()
{
fileName = QFileDialog::getOpenFileName(this, "Open Image", QDir::currentPath(), tr("Image Files(*.jpg *.png *.gif *.bmp)")).toStdString();
if(fileName.empty()) {
return;
} else {
image = cv::imread(fileName);
}
processImage();
displayImage();
}
void MainWindow::on_actionTraining_File_triggered()
{
trainingFileName = QFileDialog::getOpenFileName(this, "Open Training File", QDir::currentPath()).toStdString();
if(trainingFileName.empty()) {
return;
} else {
openTrainingFile();
}
}
void MainWindow::openTrainingFile()
{
cv::FileStorage fs(trainingFileName, cv::FileStorage::READ);
fs["classifications"] >> classificationNumbers;
fs["images"] >> trainingImagesAsFlattenedFloats;
if(classificationNumbers.empty() || trainingImagesAsFlattenedFloats.empty()) {
QMessageBox::information(this, "Error", "Error opening training file");
return;
}
QMessageBox::information(this, "Done", "Training File opened");
fs.release();
ui->pushButton->setEnabled(true);
}