29 #include <opencv2/core/core_c.h> 37 if(!image.empty() && image.depth() == CV_8U)
39 if(image.channels()==3)
41 const unsigned char * data = image.data;
42 if(image.channels() == 3)
44 qtemp = QImage(image.cols, image.rows, QImage::Format_RGB32);
45 for(
int y = 0;
y < image.rows; ++
y, data += image.cols*image.elemSize())
47 for(
int x = 0;
x < image.cols; ++
x)
49 QRgb * p = ((QRgb*)qtemp.scanLine (
y)) +
x;
52 *p = qRgb(data[
x * image.channels()+2], data[
x * image.channels()+1], data[
x * image.channels()]);
56 *p = qRgb(data[
x * image.channels()], data[
x * image.channels()+1], data[
x * image.channels()+2]);
62 else if(image.channels() == 1)
65 qtemp = QImage(image.data, image.cols, image.rows, image.cols, QImage::Format_Indexed8).copy();
66 QVector<QRgb> my_table;
67 for(
int i = 0; i < 256; i++) my_table.push_back(qRgb(i,i,i));
68 qtemp.setColorTable(my_table);
72 printf(
"Wrong image format, must have 1 or 3 channels\n");
81 if(!image.isNull() && image.depth() == 32 && image.format() == QImage::Format_RGB32)
85 cvImage = cv::Mat(image.height(), image.width(), CV_8UC3);
86 unsigned char * data = cvImage.data;
87 for(
int y = 0;
y < image.height(); ++
y, data+=cvImage.cols*cvImage.elemSize())
89 for(
int x = 0;
x < image.width(); ++
x)
91 QRgb rgb = image.pixel(
x,
y);
92 data[
x * channels+2] = qRed(rgb);
93 data[
x * channels+1] = qGreen(rgb);
94 data[
x * channels] = qBlue(rgb);
100 printf(
"Failed to convert image : depth=%d(!=32) format=%d(!=%d)\n", image.depth(), image.format(), QImage::Format_RGB32);
105 #if CV_MAJOR_VERSION < 3 109 if (image && image->depth == IPL_DEPTH_8U && cvGetSize(image).width>0)
111 const char * data = image->imageData;
112 qtemp= QImage(image->width, image->height,QImage::Format_RGB32);
114 for(
int y = 0;
y < image->height; ++
y, data +=image->widthStep )
116 for(
int x = 0;
x < image->width; ++
x)
119 *p = qRgb(data[
x * image->nChannels+2], data[
x * image->nChannels+1],data[
x * image->nChannels]);
123 else if(image && image->depth != IPL_DEPTH_8U)
125 printf(
"Wrong iplImage format, must be 8_bits\n");
133 IplImage * iplTmp = 0;
134 if(!image.isNull() && image.depth() == 32 && image.format() == QImage::Format_RGB32)
138 iplTmp = cvCreateImage(cvSize(image.width(), image.height()), IPL_DEPTH_8U, channels);
139 char * data = iplTmp->imageData;
140 for(
int y = 0;
y < image.height(); ++
y, data+=iplTmp->widthStep)
142 for(
int x = 0;
x < image.width(); ++
x)
144 QRgb rgb = image.pixel(
x,
y);
145 data[
x * channels+2] = qRed(rgb);
146 data[
x * channels+1] = qGreen(rgb);
147 data[
x * channels] = qBlue(rgb);
153 printf(
"Failed to convert image : depth=%d(!=32) format=%d(!=%d)\n", image.depth(), image.format(), QImage::Format_RGB32);
FINDOBJECT_EXP cv::Mat cvtQImage2CvMat(const QImage &image)
FINDOBJECT_EXP QImage cvtIplImage2QImage(const IplImage *image)
TFSIMD_FORCE_INLINE const tfScalar & y() const
TFSIMD_FORCE_INLINE const tfScalar & x() const
FINDOBJECT_EXP IplImage * cvtQImage2IplImage(const QImage &image)
FINDOBJECT_EXP QImage cvtCvMat2QImage(const cv::Mat &image, bool isBgr=true)