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:
Qt Code:
  1. void Video::IplImageToQPixmap(IplImage *iplImage, QPixmap *qp)
  2. {
  3. uchar *qImageBuffer = NULL;
  4. int width = iplImage->width;
  5. int widthStep = iplImage->widthStep;
  6. int height = iplImage->height;
  7. //OpenCV image is stored with 3 byte color pixels (3 channels).
  8. qImageBuffer = (uchar *) malloc(width * height * 4 * sizeof(uchar));
  9. uchar *QImagePtr = qImageBuffer;
  10. const uchar *iplImagePtr = (const uchar *) iplImage->imageData;
  11. for (int y = 0; y < height; y++)
  12. {
  13. for (int x = 0; x < width; x++)
  14. {
  15. QImagePtr[0] = iplImagePtr[0];
  16. QImagePtr[1] = iplImagePtr[1];
  17. QImagePtr[2] = iplImagePtr[2];
  18. QImagePtr[3] = 255;
  19. QImagePtr += 4;
  20. iplImagePtr += 3;
  21. }
  22. iplImagePtr += widthStep - 3 * width;
  23. }
  24. delete QImagePtr;
  25.  
  26.  
  27. *qp = QPixmap::fromImage(QImage(qImageBuffer, width, height, QImage::Format_ARGB32));
  28. delete qImageBuffer;
  29. }
To copy to clipboard, switch view to plain text mode