openni_view.cpp
Go to the documentation of this file.
00001 #include "openni_view.h"
00002 
00003 //#include <QtCore/QBasicTimer>
00004 #include <QtGui/QPainter>
00005 //#include <QtGui/QDialog>
00006 
00007 #include <sstream>
00008 
00009 QView::QView():label(0),count(0) {
00010 };
00011 
00012 QView::~QView(){
00013     if(label){
00014         delete info;
00015         delete label;
00016     };
00017 };
00018 
00019 void QView::init(int Width, int Height) {
00020     if(!label) {
00021         img = QImage(Width, Height, QImage::Format_RGB32);
00022         img.fill(QColor(0,0,0));
00023         label = new QLabel();
00024         label->setScaledContents(true);
00025         label->resize(Width*2,Height*2);
00026         label->show();
00027         info = new QLabel(label);
00028         info->setText("Info");
00029         info->move(10,10);
00030         info->show();
00031     };
00032 };
00033 
00034 void QView::show(const openni_cam::openni_cam & cam) {
00035     //++count;
00036     int Width = cam.rgb_width();
00037     int Height = cam.rgb_height();
00038     if(!label)init(Width,Height);
00039 // display image
00040     QRgb * pimg = (QRgb*)img.bits();
00041     unsigned char * prgb = cam.rgb.begin();
00042     double max_depth = -1e5;
00043     double min_depth = 1e5;
00044     for(int i = 0; i < (Width) * (Height); ++i) {
00045         if(cam.depth[i]>0) {
00046             double v = 1/(double(cam.depth[i]));
00047             if(v>max_depth)max_depth = v;
00048             if(v<min_depth)min_depth = v;
00049         };
00050     };
00051     for(int i = 0; i < (Width) * (Height); ++i) {
00052         unsigned char * pixel = &prgb[i*3];
00053         double V = 1.0;
00054         if(cam.depth[i]>0) {
00055             double v = 1/(double(cam.depth[i]));
00056             V = (v-min_depth)/(max_depth-min_depth);
00057             pimg[i] = qRgb(floor((V)*255),floor((V)*255),0);
00058             //pimg[i] = qRgb(std::max(std::min(int(floor((0.5-0.5*V)*255+(0.5*V+0.5)*pixel[0])),255),0),std::max(std::min(int(floor((0.5-0.5*V)*255+(0.5*V+0.5)*pixel[1])),255),0),floor(V*pixel[2]));
00059             //pimg[i] = qRgb(std::max(std::min(int(floor((1-V)*255)),255),0),std::max(std::min(int(floor((1-V)*255)),255),0),0);
00060         } else {
00061             pimg[i] = qRgb(pixel[0],pixel[1],pixel[2]);
00062         };
00063        //pimg[i] = qRgb(std::max(std::min(int(floor((1-V)*255)),255),0),std::max(std::min(int(floor((1-V)*255)),255),0),pixel[2]);
00064     };
00065     label->setPixmap(QPixmap::fromImage(img));
00066     {
00067         std::stringstream ss;
00068         ss<<count;
00069         info->setText(QString("<font color='black' size='6'>")+ss.str().c_str()+QString("</font>"));
00070         info->adjustSize();
00071     };
00073 };
 All Classes Namespaces Files Functions Variables Typedefs Defines


openni_cam
Author(s): Alexander Shekhovtsov
autogenerated on Sun Dec 1 2013 17:19:20