PDA

View Full Version : need to convert Raw Image Data direct to QPixmap



syclopse
4th July 2011, 11:41
Hi,

For a computer vision class I'm writing a program to capture images from a webcam using opencv and then displaying it in a Qt GUI. The capture all works, and I copy the 3 channel OpenCV image to the 4 byte aligned format necessary for Qt in my capture thread.

This works fine and displays correctly, but I really don't like the fact that I'm creating a QImage only to then have it converted to a QPixmap for painting which wastes time (about 5-8% CPU time of a Athlon 64 3200 running at 1GHz)

QPixmap has a loadFromData function but it seems to expect an image encoded in PNG/GIF/JPG and won't take my raw 0xffRRGGBB data.
Is there any way to load a QPixmap from raw data like that or paint that data on screen in a more direct manner (OpenGL is not an option)?

Santosh Reddy
5th July 2011, 06:35
I guess you may need to have a QImageIOPlugin

ChrisW67
5th July 2011, 07:34
... I copy the 3 channel OpenCV image to the 4 byte aligned format necessary for Qt in my capture thread.
Can you load the QImage from your (presumably) 24-bit RGB raw data using format QImage::Format_RGB888 (rather than QImage::Format_RGB32 or QImage::Format_ARGB32) without this pre-processing stage?

syclopse
5th July 2011, 09:11
ya but I want to display that QImage on QLabel,
and that is not possible without QPixmap.

stampede
5th July 2011, 09:24
I don't think you can copy the pixel data directly to QPixmap, because QPixmap internal storage depends on the underlying window system:

Depending on the system, QPixmap is stored using a RGB32 or a premultiplied alpha format. If the image has an alpha channel, and if the system allows, the preferred format is premultiplied alpha. Note also that QPixmap, unlike QImage, may be hardware dependent.

Note that the pixel data in a pixmap is internal and is managed by the underlying window system.
If you want to use QPixmap, you need to convert.
If you want to display the IplImage data directly without conversions, use OpenGL.

ChrisW67
6th July 2011, 00:52
ya but I want to display that QImage on QLabel, and that is not possible without QPixmap. No, you cannot go straight from raw RGB to QPixmap, but you can try to make the route you must take more efficient. In your other thread you are complaining about CPU effort required to get the data to where you want it and yet seem to be doing a bunch of work that appears to not be needed. You didn't mention this processing stage in the other thread so I brought it up here.

syclopse
18th July 2011, 13:57
you can use the function QPixmap::loadfromdata(),
using this function you can directly convert the raw data to QPixmap,
so the processing of converting the raw data to QImage and QImage to QPixmap will be reduced,
try it ....