-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
100 lines (86 loc) · 2.56 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
//local includes
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "AutoCrop.h"
//OpenCV includes
#include <highgui.h>
#include <cvaux.h>
#include <opencv/cv.h>
//Qt includes
#include <QLabel>
#include <QFileDialog>
#include <QMessageBox>
#include <QDebug>
#include <QRect>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
//Starting off with reading the image
ui->progressBar->setValue(0);
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
//Starting off with reading the image
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", tr("*.*"));
if (fileName == "")
{
QMessageBox::critical(this, tr("Error"), tr("Could not open File"));
return;
}
ui->lineEdit->setText(fileName);
IplImage* img = cvLoadImage(fileName.toStdString().c_str());
if (img==0)
{
QMessageBox::critical(this, tr("Error"),tr("Could not load image"));
}
int width = img->width;
int height = img->height;
int step = img->widthStep;
int channel = img->nChannels;
QString info;
info.append("Width: ");
info.append(QString::number(width));
info.append("\nHeight: ");
info.append(QString::number(height));
info.append("\nChannels: ");
info.append(QString::number(channel));
info.append("\nWidth Step: ");
info.append(QString::number(step));
ui->textEdit->setText(info);
cvReleaseImage(&img);
}
void MainWindow::on_pushButton_2_clicked()
{
AutoCrop act(this);
connect(&act, SIGNAL(signalProgress(int)),
this, SLOT(slotProgress(int)));
act.setImagePath(ui->lineEdit->text());
QRect crop = act.autoOuterCrop();
ui->textEdit->setText(act.output());
qDebug() << "\nTopLeft : ("<<crop.left()<<","<<crop.top()<<")";
qDebug() << "\nBottomRight : ("<<crop.right()<<","<<crop.bottom()<<")";
act.ShowOutput(crop);
}
void MainWindow::slotProgress(int value)
{
ui->progressBar->setValue(value);
}
void MainWindow::on_pushButton_3_clicked()
{
AutoCrop act(this);
connect(&act, SIGNAL(signalProgress(int)),
this, SLOT(slotProgress(int)));
act.setImagePath(ui->lineEdit->text());
//QRect crop = act.autoOuterCrop();
QRect innercrop=act.autoInnerCrop();
ui->textEdit->setText(act.output());
qDebug() << "\nTopLeft : ("<<innercrop.left()<<","<<innercrop.top()<<")";
qDebug() << "\nBottomRight : ("<<innercrop.right()<<","<<innercrop.bottom()<<")";
act.ShowOutput(innercrop);
}