-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddresult.cpp
More file actions
72 lines (60 loc) · 2.22 KB
/
addresult.cpp
File metadata and controls
72 lines (60 loc) · 2.22 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
#include "addresult.h"
#include "ui_addresult.h"
addResult::addResult(QWidget *parent) :
QDialog(parent),
ui(new Ui::addResult)
{
ui->setupUi(this);
// 界面相关内容
ui->valueSlider->setMinimum(1);
ui->valueSlider->setMaximum(100);
ui->valueSlider->setValue(50);
this->sliderValue = ui->valueSlider->value();
QObject::connect(ui->valueSlider, SIGNAL(valueChanged(int)),
this, SLOT(addResult_Slider_Slot(int)));
QObject::connect(ui->valueSlider,SIGNAL(valueChanged(int)),
ui->numberLabel,SLOT(setNum(int)));
QObject::connect(ui->saveButton, SIGNAL(clicked(bool)),
this, SLOT(addResult_Save_Slot()));
}
addResult::~addResult()
{
delete ui;
}
void addResult::setImage(cv::Mat img1_, cv::Mat img2_)
{
this->img1 = img1_.clone();
this->img2 = img2_.clone();
}
void addResult::addResult_Slider_Slot(int value)
{
this->sliderValue = value;
cv::addWeighted(img1, value/(double)(100),
img2, 1.0 -(value/(double)(100)),
0.0, result);
cv::cvtColor(result, result, cv::COLOR_BGR2RGB);
QImage qresult = QImage((const unsigned char*)(result.data),
result.cols, result.rows,
result.cols*result.channels(),
QImage::Format_RGB888);
ui->addResultImageLabel->setPixmap(QPixmap::fromImage(qresult));
ui->addResultImageLabel->resize(ui->addResultImageLabel->pixmap()->size());
// cv::cvtColor(result, result, cv::COLOR_RGB2BGR);
// cv::imshow("a",result);
}
void addResult::addResult_Save_Slot()
{
// cv::imshow("a",result); // Now is RGB
cv::cvtColor(result, result, cv::COLOR_RGB2BGR);
// cv::imshow("b",result); // Now is BGR
QString saveFileName = QFileDialog::getSaveFileName(this,"Save File",QDir::homePath(),
tr ("Image File (*.png *.jpg *.jpeg *.bmp)"));
if(saveFileName.isEmpty())
{
// QMessageBox::information(this,"Error Message","Please select a file");
return;
}
// cvtColor(result,result,CV_RGB2BGR);
std::string savePath = saveFileName.toStdString();
imwrite(savePath, result);
}