-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
99 lines (81 loc) · 2.37 KB
/
mainwindow.cpp
File metadata and controls
99 lines (81 loc) · 2.37 KB
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::ShowOnLabel(cv::Mat mat, QLabel *k)
{
if(mat.channels()==3)
{
cv::cvtColor(mat,mat,CV_BGR2RGB);
QImage qtemp = QImage((const unsigned char*)(mat.data),mat.cols,mat.rows,mat.step,QImage::Format_RGB888);
k->clear();
k->setPixmap(QPixmap::fromImage(qtemp.scaled(k->width(),k->height(),Qt::KeepAspectRatio)));
k->show();
}
else if(mat.channels() == 1)
{
QVector<QRgb> colorTable;
for(int i=0;i<256;i++)
{
colorTable.push_back(qRgb(i,i,i));
}
//const uchar *qImageBuffer = (const uchar*)mat.data;
QImage qtemp = QImage((const unsigned char*)(mat.data),mat.cols,mat.rows,mat.step,QImage::Format_Indexed8);
qtemp.setColorTable(colorTable);
k->clear();
k->setPixmap(QPixmap::fromImage(qtemp.scaled(k->width(),k->height(),Qt::KeepAspectRatio)));
k->show();
}
}
void MainWindow::drawOnRGB(std::vector<cv::Point> p)
{
cv::Mat temp =rgb.clone();
for(int i=0;i<p.size();i++)
{
cv::circle(temp,p[i],10,cv::Scalar(255,0,0),-1,8);
}
ShowOnLabel(temp,ui->RGBLabel);
cv::imshow("temp",temp);
}
void MainWindow::on_LoadPic_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this,tr("Open Pic Image"), "D:/Dropbox/", tr("Image Files (*.jpg)"));
if(fileName.isEmpty())
{
return;
}
ui->FileLabel->setText(fileName);
pic = cv::imread(fileName.toStdString().c_str()); //,CV_LOAD_IMAGE_COLOR
qDebug()<<pic.channels();
// cv::cvtColor(pic,pic,CV_GRAY2BGR);
// qDebug()<<pic.channels();
ShowOnLabel(pic, ui->PicLabel);
}
void MainWindow::on_LoadRGB_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this,tr("Open RGB Image"), "D:/Dropbox/", tr("Image Files (*.jpg)"));
if(fileName.isEmpty())
{
return;
}
ui->FileLabelRGB->setText(fileName);
rgb = cv::imread(fileName.toStdString().c_str());
cv::resize(rgb,rgb,cv::Size(720,480),CV_INTER_LINEAR);
ShowOnLabel(rgb, ui->RGBLabel);
}
void MainWindow::on_PointButtom_clicked()
{
if(!pic.empty())
{
picdialog.picOpenPint(pic,rgb);
}
return;
}