Subversion Repositories seema-scanner

Rev

Rev 21 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include "SMVideoWidget.h"

SMVideoWidget::SMVideoWidget(QWidget *parent) : QLabel(parent){

}

static QImage cvMat2qImage(cv::Mat mat){

    // 8-bits unsigned, NO. OF CHANNELS=1
    if(mat.type()==CV_8UC1) {
        // Set the color table (used to tranMVate colour indexes to qRgb values)
        QVector<QRgb> colorTable;
        for (int i=0; i<256; i++)
            colorTable.push_back(qRgb(i,i,i));
        // Copy input Mat
        QImage img((const uchar*)mat.data, mat.cols, mat.rows, mat.step, QImage::Format_Indexed8);
        img.setColorTable(colorTable);
        return img;
    } else if(mat.type()==CV_8UC3) {
        // Copy input Mat
        QImage img((const uchar*)mat.data, mat.cols, mat.rows, mat.step, QImage::Format_RGB888);
        return img.rgbSwapped();
    } else if(mat.type()==CV_32FC1) {
        cv::Mat rgb(mat.size(), CV_32FC3);
        rgb.addref();
        cv::cvtColor(mat, rgb, cv::COLOR_GRAY2RGB);
        // Copy input Mat
        QImage img((const uchar*)rgb.data, rgb.cols, rgb.rows, rgb.step, QImage::Format_RGB32);
        rgb.release();
        return img;
    } else {
        std::cerr << "MVVideoDialog: cv::Mat could not be converted to QImage!";
        return QImage();
    }
}


void SMVideoWidget::showImageCV(cv::Mat image){
    //ui->videoWidget->showFrameCV(image);

    QImage qimage = cvMat2qImage(image);

    int w = this->width();
    int h = this->height();
    QPixmap pixmap = QPixmap::fromImage(qimage);

    this->setPixmap(pixmap.scaled(w,h,Qt::KeepAspectRatio));

}