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)
93 if(!
uIsNan(data[i]) && data[i] > 0)
96 (data[i] > 0 && data[i]<
min))
101 (data[i] > 0 && data[i]>
max))
107 qtemp = QImage(image.cols, image.rows, QImage::Format_Indexed8);
108 for(
int y = 0; y < image.rows; ++y, data += image.cols)
110 for(
int x = 0; x < image.cols; ++x)
112 uchar * p = qtemp.scanLine (y) + x;
132 QVector<QRgb> my_table;
133 my_table.reserve(256);
136 my_table.push_back(qRgb(0,0,0));
137 for(
int i = 1; i < 256; i++)
138 my_table.push_back(QColor::fromHsv(i, 255, 255, 255).rgb());
142 for(
int i = 0; i < 256; i++)
143 my_table.push_back(qRgb(i,i,i));
145 qtemp.setColorTable(my_table);
147 else if(image.depth() == CV_16U && image.channels()==1)
150 const unsigned short * data = (
const unsigned short *)image.data;
151 unsigned short min=data[0],
max=data[0];
152 for(
unsigned int i=1; i<image.total(); ++i)
154 if(!
uIsNan(data[i]) && data[i] > 0)
157 (data[i] > 0 && data[i]<
min))
162 (data[i] > 0 && data[i]>
max))
169 qtemp = QImage(image.cols, image.rows, QImage::Format_Indexed8);
170 for(
int y = 0; y < image.rows; ++y, data += image.cols)
172 for(
int x = 0; x < image.cols; ++x)
174 uchar * p = qtemp.scanLine (y) + x;
194 QVector<QRgb> my_table;
195 my_table.reserve(256);
198 my_table.push_back(qRgb(0,0,0));
199 for(
int i = 1; i < 256; i++)
200 my_table.push_back(QColor::fromHsv(i, 255, 255, 255).rgb());
204 for(
int i = 0; i < 256; i++)
205 my_table.push_back(qRgb(i,i,i));
207 qtemp.setColorTable(my_table);
209 else if(!image.empty() && image.depth() != CV_8U)
211 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.
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)
bool uIsNan(const T &value)