-
Notifications
You must be signed in to change notification settings - Fork 54
/
showhistogtamresult.cpp
124 lines (93 loc) · 3.05 KB
/
showhistogtamresult.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "showhistogtamresult.h"
#include "ui_showhistogtamresult.h"
#include <QMessageBox>
#include <QDebug>
#include <QPainter>
#include <QPalette>
#pragma execution_character_set("utf-8")
///////////////////////////////////
/// \brief ShowHistogtamResult::ShowHistogtamResult
/// \param parent
///直方图显示程序会让程序特别的卡,可能是paintEvent(QPaintEvent *)的缘故
/// 目前没有更好的方法解决个bug;
///
///
///
///
ShowHistogtamResult::ShowHistogtamResult(QWidget *parent) :
QWidget(parent),
ui(new Ui::ShowHistogtamResult)
{
ui->setupUi(this);
ui->show_label->setScaledContents(true);//自动调整为Qlabel大小。
// QWidget *widget = new QWidget();
// widget->setAutoFillBackground(true);
// QPalette palette;
// QPixmap pixmap(":/Resources/Penguins.jpg");
// palette.setBrush(QPalette::Window, QBrush(pixmap));
// widget->setPalette(palette);
// widget->show();
this->setAutoFillBackground(true);
}
ShowHistogtamResult::~ShowHistogtamResult()
{
delete ui;
}
void ShowHistogtamResult::showHistogtam_Mat(Mat receive_Mat)
{
source_gray_Mat=receive_Mat;
setPicture(resultMat);
}
void ShowHistogtamResult::setPicture(Mat his_Mat)
{
ui->show_label->clear();
QImage image;
Mat pImgs=his_Mat;//m_listMat_glob.at(0);
if(pImgs.channels()==1)//灰度图通道变为1
{
//灰度转换时候Format_Grayscale8
QImage imageGray((const uchar*)pImgs.data, pImgs.cols,
pImgs.rows,pImgs.cols*pImgs.channels(),QImage::Format_Grayscale8);
image=imageGray;
}
else
{
// 将抓取到的帧,转换为QImage格式。QImage::Format_RGB888不同的摄像头用不同的格式。
QImage imageOriginal((const uchar*)pImgs.data, pImgs.cols,
pImgs.rows,pImgs.cols*pImgs.channels(),QImage::Format_RGB888);
image=imageOriginal;
}
// image = image.scaled(this->geometry().size(),Qt::KeepAspectRatio,Qt::SmoothTransformation);
QPixmap pixmapCV =QPixmap::fromImage(image);
// ui->show_label->setPixmap(pixmapCV);
// ui->show_label->setAlignment(Qt::AlignCenter);
QPalette palette;
palette.setBrush(this->backgroundRole(),
QBrush(pixmapCV.scaled(this->size(),
Qt::IgnoreAspectRatio,
Qt::SmoothTransformation)));
this->setPalette(palette);
}
// void HistogtamDlg::closeEvent(QCloseEvent *event)
// {
// //在这里添加你希望执行关闭事件需要处理的事情
// //弹出消息框,关闭其他窗口
// }
void ShowHistogtamResult::paintEvent(QPaintEvent *)
{
// ui->show_label->clear();
// ui->show_label->resize(this->geometry().size());
// setPicture(resultMat);
reFresh();
}
void ShowHistogtamResult::reFresh()
{
// ui->show_label->clear();
setPicture(resultMat);
}
void ShowHistogtamResult::receiveHistogtam_Mat(Mat re_Mat)
{
ui->show_label->clear();
resultMat=re_Mat;
setPicture(resultMat);
}