23 #include <QtGui/QImage> 24 #include <QtGui/QColor> 25 #include <opencv2/core/core.hpp> 47 if(!image.empty() && image.depth() == CV_8U)
49 if(image.channels()==3)
51 const unsigned char * data = image.data;
52 if(image.channels() == 3)
54 qtemp = QImage(image.cols, image.rows, QImage::Format_RGB32);
55 for(
int y = 0; y < image.rows; ++y, data += image.cols*image.elemSize())
57 for(
int x = 0; x < image.cols; ++x)
59 QRgb * p = ((QRgb*)qtemp.scanLine (y)) + x;
62 *p = qRgb(data[x * image.channels()+2], data[x * image.channels()+1], data[x * image.channels()]);
66 *p = qRgb(data[x * image.channels()], data[x * image.channels()+1], data[x * image.channels()+2]);
72 else if(image.channels() == 1)
75 qtemp = QImage(image.data, image.cols, image.rows, image.cols, QImage::Format_Indexed8).copy();
76 QVector<QRgb> my_table;
77 for(
int i = 0; i < 256; i++)
78 my_table.push_back(qRgb(i,i,i));
79 qtemp.setColorTable(my_table);
83 printf(
"Wrong image format, must have 1 or 3 channels\n");
86 else if(image.depth() == CV_32F && image.channels()==1)
89 const float * data = (
const float *)image.data;
90 float min=data[0],
max=data[0];
91 for(
unsigned int i=1; i<image.total(); ++i)
106 qtemp = QImage(image.cols, image.rows, QImage::Format_Indexed8);
107 for(
int y = 0; y < image.rows; ++y, data += image.cols)
109 for(
int x = 0; x < image.cols; ++x)
111 uchar * p = qtemp.scanLine (y) + x;
131 QVector<QRgb> my_table;
132 my_table.reserve(256);
135 my_table.push_back(qRgb(0,0,0));
136 for(
int i = 1; i < 256; i++)
137 my_table.push_back(QColor::fromHsv(i, 255, 255, 255).rgb());
141 for(
int i = 0; i < 256; i++)
142 my_table.push_back(qRgb(i,i,i));
144 qtemp.setColorTable(my_table);
146 else if(image.depth() == CV_16U && image.channels()==1)
149 const unsigned short * data = (
const unsigned short *)image.data;
150 unsigned short min=data[0],
max=data[0];
151 for(
unsigned int i=1; i<image.total(); ++i)
166 qtemp = QImage(image.cols, image.rows, QImage::Format_Indexed8);
167 for(
int y = 0; y < image.rows; ++y, data += image.cols)
169 for(
int x = 0; x < image.cols; ++x)
171 uchar * p = qtemp.scanLine (y) + x;
191 QVector<QRgb> my_table;
192 my_table.reserve(256);
195 my_table.push_back(qRgb(0,0,0));
196 for(
int i = 1; i < 256; i++)
197 my_table.push_back(QColor::fromHsv(i, 255, 255, 255).rgb());
201 for(
int i = 0; i < 256; i++)
202 my_table.push_back(qRgb(i,i,i));
204 qtemp.setColorTable(my_table);
206 else if(!image.empty() && image.depth() != CV_8U)
208 printf(
"Wrong image format, must be 8_bits/3channels or (depth) 32bitsFloat/1channel, 16bits/1channel\n");
GLM_FUNC_DECL genType min(genType const &x, genType const &y)
Basic mathematics functions.
bool uIsFinite(const T &value)
QImage uCvMat2QImage(const cv::Mat &image, bool isBgr=true, uCvQtDepthColorMap colorMap=uCvQtDepthWhiteToBlack)
UCvMat2QImageThread(const cv::Mat &image, bool isBgr=true)
GLM_FUNC_DECL genType max(genType const &x, genType const &y)