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;
98 float min=depthMax>depthMin?depthMin:data[0],
max=depthMax>depthMin?depthMax:data[0];
99 if(depthMax <= depthMin)
101 for(
unsigned int i=1; i<image.total(); ++i)
117 qtemp = QImage(image.cols, image.rows, QImage::Format_Indexed8);
118 for(
int y = 0; y < image.rows; ++y, data += image.cols)
120 for(
int x = 0;
x < image.cols; ++
x)
122 uchar * p = qtemp.scanLine (y) +
x;
142 QVector<QRgb> my_table;
143 my_table.reserve(256);
146 my_table.push_back(qRgb(0,0,0));
147 for(
int i = 1; i < 256; i++)
148 my_table.push_back(QColor::fromHsv(i, 255, 255, 255).rgb());
152 for(
int i = 0; i < 256; i++)
153 my_table.push_back(qRgb(i,i,i));
155 qtemp.setColorTable(my_table);
157 else if(image.depth() == CV_16U && image.channels()==1)
160 const unsigned short *
data = (
const unsigned short *)image.data;
161 unsigned short min=depthMax>depthMin?(
unsigned short)(depthMin*1000):data[0],
max=depthMax>depthMin?(
unsigned short)(depthMax*1000):data[0];
162 if(depthMax<=depthMin)
164 for(
unsigned int i=1; i<image.total(); ++i)
180 qtemp = QImage(image.cols, image.rows, QImage::Format_Indexed8);
181 for(
int y = 0; y < image.rows; ++y, data += image.cols)
183 for(
int x = 0;
x < image.cols; ++
x)
185 uchar * p = qtemp.scanLine (y) +
x;
205 QVector<QRgb> my_table;
206 my_table.reserve(256);
209 my_table.push_back(qRgb(0,0,0));
210 for(
int i = 1; i < 256; i++)
211 my_table.push_back(QColor::fromHsv(i, 255, 255, 255).rgb());
215 for(
int i = 0; i < 256; i++)
216 my_table.push_back(qRgb(i,i,i));
218 qtemp.setColorTable(my_table);
220 else if(!image.empty() && image.depth() != CV_8U)
222 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)
QImage uCvMat2QImage(const cv::Mat &image, bool isBgr=true, uCvQtDepthColorMap colorMap=uCvQtDepthWhiteToBlack, float depthMin=0, float depthMax=0)
Basic mathematics functions.
bool uIsFinite(const T &value)
UCvMat2QImageThread(const cv::Mat &image, bool isBgr=true)
GLM_FUNC_DECL genType max(genType const &x, genType const &y)