23 #include <QtGui/QImage>
24 #include <QtGui/QColor>
25 #include <opencv2/core/core.hpp>
48 const cv::Mat & image,
55 if(!image.empty() && image.depth() == CV_8U)
57 if(image.channels()==3)
59 const unsigned char *
data = image.data;
60 if(image.channels() == 3)
62 qtemp = QImage(image.cols, image.rows, QImage::Format_RGB32);
63 for(
int y = 0;
y < image.rows; ++
y,
data += image.cols*image.elemSize())
65 for(
int x = 0;
x < image.cols; ++
x)
67 QRgb *
p = ((QRgb*)qtemp.scanLine (
y)) +
x;
70 *
p = qRgb(
data[
x * image.channels()+2],
data[
x * image.channels()+1],
data[
x * image.channels()]);
74 *
p = qRgb(
data[
x * image.channels()],
data[
x * image.channels()+1],
data[
x * image.channels()+2]);
80 else if(image.channels() == 1)
83 qtemp = QImage(image.data, image.cols, image.rows, image.cols, QImage::Format_Indexed8).copy();
84 QVector<QRgb> my_table;
85 for(
int i = 0;
i < 256;
i++)
86 my_table.push_back(qRgb(
i,
i,
i));
87 qtemp.setColorTable(my_table);
91 printf(
"Wrong image format, must have 1 or 3 channels\n");
94 else if(image.depth() == CV_32F && image.channels()==1)
97 const float *
data = (
const float *)image.data;
107 for(
unsigned int i=1;
i<image.total(); ++
i)
121 if(depthMax > 0 && depthMax > depthMin)
125 if(depthMin>0 && (depthMin < depthMax || depthMin <
max))
131 qtemp = QImage(image.cols, image.rows, QImage::Format_Indexed8);
132 for(
int y = 0;
y < image.rows; ++
y,
data += image.cols)
134 for(
int x = 0;
x < image.cols; ++
x)
160 QVector<QRgb> my_table;
161 my_table.reserve(256);
164 my_table.push_back(qRgb(0,0,0));
165 for(
int i = 1;
i < 256;
i++)
166 my_table.push_back(QColor::fromHsv(
i, 255, 255, 255).rgb());
170 for(
int i = 0;
i < 256;
i++)
171 my_table.push_back(qRgb(
i,
i,
i));
173 qtemp.setColorTable(my_table);
175 else if(image.depth() == CV_16U && image.channels()==1)
178 const unsigned short *
data = (
const unsigned short *)image.data;
180 if(depthMax>depthMin)
188 for(
unsigned int i=1;
i<image.total(); ++
i)
202 if(depthMax > 0 && depthMax > depthMin)
206 if(depthMin>0 && (depthMin < depthMax || depthMin*1000 <
max))
212 qtemp = QImage(image.cols, image.rows, QImage::Format_Indexed8);
213 for(
int y = 0;
y < image.rows; ++
y,
data += image.cols)
215 for(
int x = 0;
x < image.cols; ++
x)
241 QVector<QRgb> my_table;
242 my_table.reserve(256);
245 my_table.push_back(qRgb(0,0,0));
246 for(
int i = 1;
i < 256;
i++)
247 my_table.push_back(QColor::fromHsv(
i, 255, 255, 255).rgb());
251 for(
int i = 0;
i < 256;
i++)
252 my_table.push_back(qRgb(
i,
i,
i));
254 qtemp.setColorTable(my_table);
256 else if(!image.empty() && image.depth() != CV_8U)
258 printf(
"Wrong image format, must be 8_bits/3channels or (depth) 32bitsFloat/1channel, 16bits/1channel\n");