Subversion Repositories seema-scanner

Rev

Rev 2 | Rev 23 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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