Results 1 to 7 of 7

Thread: need to convert Raw Image Data direct to QPixmap

  1. #1
    Join Date
    Apr 2011
    Posts
    39
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default need to convert Raw Image Data direct to QPixmap

    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)?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: need to convert Raw Image Data direct to QPixmap

    I guess you may need to have a QImageIOPlugin

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: need to convert Raw Image Data direct to QPixmap

    Quote Originally Posted by syclopse View Post
    ... 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?

  4. #4
    Join Date
    Apr 2011
    Posts
    39
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: need to convert Raw Image Data direct to QPixmap

    ya but I want to display that QImage on QLabel,
    and that is not possible without QPixmap.

  5. #5
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: need to convert Raw Image Data direct to QPixmap

    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.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: need to convert Raw Image Data direct to QPixmap

    Quote Originally Posted by syclopse View Post
    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.

  7. #7
    Join Date
    Apr 2011
    Posts
    39
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: need to convert Raw Image Data direct to QPixmap

    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 ....

Similar Threads

  1. How to convert JPEG image into binary data?
    By Gokulnathvc in forum Newbie
    Replies: 1
    Last Post: 7th June 2011, 08:43
  2. Creating a QPixmap object from raw image data
    By eumel1990 in forum Newbie
    Replies: 3
    Last Post: 29th May 2011, 09:04
  3. How to convert image data type to plain text and back ?
    By aircraftstories in forum Qt Programming
    Replies: 3
    Last Post: 13th April 2011, 16:00
  4. Replies: 2
    Last Post: 29th September 2008, 00:08
  5. Replies: 4
    Last Post: 28th August 2008, 13:13

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.