Subversion Repositories seema-scanner

Rev

Rev 2 | Rev 23 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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();
21 jakw 23
    } else if(mat.type()==CV_16UC1) {
24
        mat.convertTo(mat, CV_8UC1, 1.0/256.0);
25
        return cvMat2qImage(mat);
2 jakw 26
    } else if(mat.type()==CV_32FC1) {
27
        cv::Mat rgb(mat.size(), CV_32FC3);
28
        rgb.addref();
29
        cv::cvtColor(mat, rgb, cv::COLOR_GRAY2RGB);
30
        // Copy input Mat
31
        QImage img((const uchar*)rgb.data, rgb.cols, rgb.rows, rgb.step, QImage::Format_RGB32);
32
        rgb.release();
33
        return img;
34
    } else {
35
        std::cerr << "MVVideoDialog: cv::Mat could not be converted to QImage!";
36
        return QImage();
37
    }
38
}
39
 
40
 
41
void SMVideoWidget::showImageCV(cv::Mat image){
42
    //ui->videoWidget->showFrameCV(image);
43
 
44
    QImage qimage = cvMat2qImage(image);
45
 
46
    int w = this->width();
47
    int h = this->height();
48
    QPixmap pixmap = QPixmap::fromImage(qimage);
49
 
50
    this->setPixmap(pixmap.scaled(w,h,Qt::KeepAspectRatio));
51
 
52
}