View Full Version : mirrored pixmap??

5th August 2009, 19:20
Hi there,

I am using QT4 and opencv in windows for my master's project.

I managed to find some code for converting an IplImage from opencv to a pixmap for use in a QT GUI which has been working. I am now using it on the fly to display video (so far surprisingly working well in real-time). However, with exactly the same code it is showing up in the window somehow mirrored vertically across the midpoint of the pixmap.

The only thiing different is as I am streaming video from a frame grabber, the IplImage is created in a seperate thread from the main program using CvCapture and connected to the QT label using a signal/slot.

Any help would be much appreciated, thanks

Code below:

void Video::IplImageToQPixmap(IplImage *iplImage, QPixmap *qp)
uchar *qImageBuffer = NULL;
int width = iplImage->width;
int widthStep = iplImage->widthStep;
int height = iplImage->height;
//OpenCV image is stored with 3 byte color pixels (3 channels).
qImageBuffer = (uchar *) malloc(width * height * 4 * sizeof(uchar));
uchar *QImagePtr = qImageBuffer;
const uchar *iplImagePtr = (const uchar *) iplImage->imageData;
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++)
QImagePtr[0] = iplImagePtr[0];
QImagePtr[1] = iplImagePtr[1];
QImagePtr[2] = iplImagePtr[2];
QImagePtr[3] = 255;
QImagePtr += 4;
iplImagePtr += 3;
iplImagePtr += widthStep - 3 * width;
delete QImagePtr;

*qp = QPixmap::fromImage(QImage(qImageBuffer, width, height, QImage::Format_ARGB32));
delete qImageBuffer;