I'm trying to convert a OpenCV IplImage or a QT QImage into a CByteImage but all I get is a gray image. This is how I do it for an QImage but it is a smiliar way for a IplImage:
QImage *tempQImage = new QImage("1.PNG");
CByteImage *destCBImage = new CByteImage(tempQImage.width(), tempQImage.height(), CByteImage::eRGB24, true);
destCBImage->pixels = (unsigned char *) tempQImage.bits();
The QImage is in QImage format RGB888 (RGB 24bit).
Can anybody help me.
your code looks fine. Could you send me your test image 1.PNG, so I can check (you can find my e-mail-address on the contact page on http://ivt.sourceforge.net\)?
the problem is that Qt doesn't represent the image as 24 bit RGB but as 32 bit RGBA.
Below you find code for both Qt and OpenCV (assuming that 1.PNG is a color image). I tested both with the image you sent me and it works fine.
Note that you can also use the function IplImageAdaptor::Adapt from IVT/src/Image/IplImageAdaptor.h in the case of OpenCV.
CByteImage image(qtImage.width(), qtImage.height(), CByteImage::eRGB24);
// convert from 32 bit RGBA to 23 bit RGB
const unsigned char *input = (unsigned char *) qtImage.bits();
const int nOutputBytes = 3 * qtImage.width() * qtImage.height();
for (int i = 0, offset = 0; i < nOutputBytes; i += 3, offset += 4)
image.pixels[i] = input[offset];
image.pixels[i + 1] = input[offset + 1];
image.pixels[i + 2] = input[offset + 2];
IplImage *pIPLImage = cvLoadImage("1.PNG");
CByteImage image(pIPLImage->width, pIPLImage->height, CByteImage::eRGB24, true);
image.pixels = (unsigned char *) pIPLImage->imageData;
It works fine. Thank you very much for your help Pedram!
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.