-
Notifications
You must be signed in to change notification settings - Fork 59
/
colorchanneldisplay.cpp
74 lines (66 loc) · 2.37 KB
/
colorchanneldisplay.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
/******************************************************************************
**
** Copyright 2016 Dale Eason
** This file is part of DFTFringe
** is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License
** DFTFringe is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with DFTFringe. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "colorchanneldisplay.h"
#include "ui_colorchanneldisplay.h"
#include <opencv2/opencv.hpp>
ColorChannelDisplay::ColorChannelDisplay(QWidget *parent) :
QDialog(parent),
ui(new Ui::ColorChannelDisplay)
{
ui->setupUi(this);
ui->red->setScaledContents( true );
ui->green->setScaledContents( true );
ui->blue->setScaledContents( true );
//ui->green->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored );
}
ColorChannelDisplay::~ColorChannelDisplay()
{
delete ui;
}
void ColorChannelDisplay::setImage(cv::Mat imgMat){
for (int channel = 0; channel < 3; ++channel){
cv::Mat planes[4];
split(imgMat,planes);
cv::Mat mm;
for (int i = 0; i < 3; ++i){
if (channel == i)
continue;
planes[i] *= 0;
}
merge(planes,3,mm);
QImage tmp = QImage((uchar*)mm.data,
mm.cols,
mm.rows,
mm.step,
QImage::Format_RGB888).copy();
QLabel *label;
switch(channel){
case 0:
label = ui->red;
break;
case 1:
label = ui->green;
break;
case 2:
label = ui->blue;
break;
}
QSize labelSize = label->size();
// set a scaled pixmap to a w x h window keeping its aspect ratio
label->setPixmap(QPixmap::fromImage(tmp.scaled(labelSize.width(),labelSize.height(),
Qt::KeepAspectRatio)));
}
}