1. schlangen
  2. kinect-playground

Source

kinect-playground / hidecam2 / mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);


    dframe = cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 4);
    // the individual channels for the IplImage
    tchannel0 = cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 1);
    tchannel1 = cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 1);
    tchannel2 = cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 1);
    tchannel3 = cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 1);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::updateImage(IplImage *img)
{
    // from http://www.qtcentre.org/threads/11655-OpenCV-integration



    // set all elements in tchannel0 (alpha channel) to 255
    cvSet(tchannel0,cvScalarAll(255),0);

    // with cframe being the captured frame (3 channel RGB)
    // and dframe the frame to be displayed
    cvSplit(img, tchannel1, tchannel2, tchannel3, NULL);
    cvMerge(tchannel1, tchannel2, tchannel3, tchannel0, dframe);

    // point to the image data stored in the IplImage*
       const unsigned char * data = (unsigned char *)(dframe->imageData);


    // read other parameters in local variables
    int width = 640;
    int height = 480;
    int bytesPerLine = width*4;

    // imageframe is my QLabel object
    QImage qimage( data, width, height, bytesPerLine, QImage::Format_RGB32 );
    QPixmap pixmap;
    ui->imageframe->setPixmap(pixmap.fromImage(qimage, 0));
}