CQTImageConvertor.cpp
Go to the documentation of this file.
00001 /*
00002  * CQTImageConvertor.cpp
00003  *
00004  *  Created on: 23.07.2010
00005  *      Author: grigorescu
00006  */
00007 
00008 #include "CQTImageConvertor.h"
00009 
00010 CQTImageConvertor::CQTImageConvertor()
00011 {
00012         // TODO Auto-generated constructor stub
00013 }
00014 
00015 CQTImageConvertor::~CQTImageConvertor()
00016 {
00017         // TODO Auto-generated destructor stub
00018 }
00019 
00020 
00021 void CQTImageConvertor::showQTImage(QImage* image, QLabel* label)
00022 {
00023     if(!image->isNull())
00024     {
00025                 QPixmap pixmap = QPixmap::fromImage(*image);
00026         pixmap = pixmap.scaled(label->width(), label->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
00027         label->setPixmap(pixmap);
00028     }
00029 }
00030 
00031 void CQTImageConvertor::showQTImage(const IplImage* image, QLabel* label)
00032 {
00033 
00034         QImage *qimg = new QImage(image->width, image->height, QImage::Format_RGB32);
00035 
00036         IplImage2QImage(image, qimg);
00037 
00038         showQTImage(qimg, label);
00039 
00040         delete qimg;
00041 
00042 }
00043 
00044 void CQTImageConvertor::showQTImage(const IplImage* image, QPixmap &pixmap)
00045 {
00046 
00047         QImage *qimg = new QImage(image->width, image->height, QImage::Format_RGB32);
00048         std::cerr <<"part 1\n";
00049         IplImage2QImage(image, qimg);
00050         std::cerr <<"part 2\n";
00051 
00052         if(!qimg->isNull())
00053         {
00054                 std::cerr << "before picmap\n";
00055                 pixmap = QPixmap::fromImage(*qimg);
00056                 std::cerr << "*pixmap = QPixmap::fromImage(*qimg);\n";
00057                 pixmap.scaled(image->width, image->height, Qt::KeepAspectRatio, Qt::SmoothTransformation);
00058                 std::cerr << "pixmap->scaled(image->width, image->height, Qt::KeepAspectRatio, Qt::SmoothTransformation);\n";
00059         }
00060 
00061         std::cerr <<"part 3\n";
00062         //delete qimg;
00063 
00064 }
00065 
00066 void CQTImageConvertor::showQTImage(cv::Mat image, QLabel* label)
00067 {
00068         QImage *qimg = new QImage(image.rows, image.cols, QImage::Format_RGB32);
00069 
00070         IplImage2QImage(image, qimg);
00071 
00072         showQTImage(qimg, label);
00073 
00074         delete qimg;
00075 }
00076 
00077 void CQTImageConvertor::IplImage2QImage(const IplImage *iplImg, QImage* qimg)
00078 {
00079         int h = iplImg->height;
00080         int w = iplImg->width;
00081         int channels = iplImg->nChannels;
00082 
00083         char *data = iplImg->imageData;
00084 
00085         for (int y = 0; y < h; y++, data += iplImg->widthStep)
00086         {
00087                 for (int x = 0; x < w; x++)
00088                 {
00089                         char r=0, g=0, b=0, a=0;
00090 
00091                         if (channels == 1)
00092                         {
00093                                 r = data[x * channels];
00094                                 g = data[x * channels];
00095                                 b = data[x * channels];
00096                         }
00097                         else if (channels == 3 || channels == 4)
00098                         {
00099                                 r = data[x * channels + 2];
00100                                 g = data[x * channels + 1];
00101                                 b = data[x * channels];
00102                         }
00103 
00104                         if (channels == 4)
00105                         {
00106                                 a = data[x * channels + 3];
00107                                 qimg->setPixel(x, y, qRgba(r, g, b, a));
00108                         }
00109                         else
00110                         {
00111                                 qimg->setPixel(x, y, qRgb(r, g, b));
00112                         }
00113                 }
00114         }
00115 }
00116 
00117 void CQTImageConvertor::IplImage2QImage(cv::Mat iplImg, QImage* qimg)
00118 {
00119         int h = iplImg.cols;
00120         int w = iplImg.rows;
00121         int channels = iplImg.channels();
00122 
00123         char *data = (char*)iplImg.data;
00124 
00125         for (int y = 0; y < h; y++, data += iplImg.step)
00126         {
00127                 for (int x = 0; x < w; x++)
00128                 {
00129                         char r=0, g=0, b=0, a=0;
00130 
00131                         if (channels == 1)
00132                         {
00133                                 r = data[x * channels];
00134                                 g = data[x * channels];
00135                                 b = data[x * channels];
00136                         }
00137                         else if (channels == 3 || channels == 4)
00138                         {
00139                                 r = data[x * channels + 2];
00140                                 g = data[x * channels + 1];
00141                                 b = data[x * channels];
00142                         }
00143 
00144                         if (channels == 4)
00145                         {
00146                                 a = data[x * channels + 3];
00147                                 qimg->setPixel(x, y, qRgba(r, g, b, a));
00148                         }
00149                         else
00150                         {
00151                                 qimg->setPixel(x, y, qRgb(r, g, b));
00152                         }
00153                 }
00154         }
00155 }


zbar_qt_ros
Author(s): banacer
autogenerated on Mon Oct 6 2014 10:57:25