2 |
jakw |
1 |
#include "SMVideoWidget.h"
|
|
|
2 |
|
|
|
3 |
SMVideoWidget::SMVideoWidget(QWidget *parent) : QLabel(parent){
|
|
|
4 |
|
|
|
5 |
}
|
|
|
6 |
|
|
|
7 |
static QImage cvMat2qImage(cv::Mat mat){
|
|
|
8 |
|
|
|
9 |
// 8-bits unsigned, NO. OF CHANNELS=1
|
|
|
10 |
if(mat.type()==CV_8UC1) {
|
|
|
11 |
// Set the color table (used to tranMVate colour indexes to qRgb values)
|
|
|
12 |
QVector<QRgb> colorTable;
|
|
|
13 |
for (int i=0; i<256; i++)
|
|
|
14 |
colorTable.push_back(qRgb(i,i,i));
|
|
|
15 |
// Copy input Mat
|
|
|
16 |
QImage img((const uchar*)mat.data, mat.cols, mat.rows, mat.step, QImage::Format_Indexed8);
|
|
|
17 |
img.setColorTable(colorTable);
|
|
|
18 |
return img;
|
|
|
19 |
} else if(mat.type()==CV_8UC3) {
|
|
|
20 |
// Copy input Mat
|
|
|
21 |
QImage img((const uchar*)mat.data, mat.cols, mat.rows, mat.step, QImage::Format_RGB888);
|
|
|
22 |
return img.rgbSwapped();
|
|
|
23 |
} else if(mat.type()==CV_32FC1) {
|
|
|
24 |
cv::Mat rgb(mat.size(), CV_32FC3);
|
|
|
25 |
rgb.addref();
|
|
|
26 |
cv::cvtColor(mat, rgb, cv::COLOR_GRAY2RGB);
|
|
|
27 |
// Copy input Mat
|
|
|
28 |
QImage img((const uchar*)rgb.data, rgb.cols, rgb.rows, rgb.step, QImage::Format_RGB32);
|
|
|
29 |
rgb.release();
|
|
|
30 |
return img;
|
|
|
31 |
} else {
|
|
|
32 |
std::cerr << "MVVideoDialog: cv::Mat could not be converted to QImage!";
|
|
|
33 |
return QImage();
|
|
|
34 |
}
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
void SMVideoWidget::showImageCV(cv::Mat image){
|
|
|
39 |
//ui->videoWidget->showFrameCV(image);
|
|
|
40 |
|
|
|
41 |
QImage qimage = cvMat2qImage(image);
|
|
|
42 |
|
|
|
43 |
int w = this->width();
|
|
|
44 |
int h = this->height();
|
|
|
45 |
QPixmap pixmap = QPixmap::fromImage(qimage);
|
|
|
46 |
|
|
|
47 |
this->setPixmap(pixmap.scaled(w,h,Qt::KeepAspectRatio));
|
|
|
48 |
|
|
|
49 |
}
|