Results 1 to 2 of 2

Thread: QPixmap conversion from OpenCV

  1. #1

    Default QPixmap conversion from OpenCV

    Hello,

    We have a program that captures video data and we want to be able to render that data (from OpenCV's IplImage format) into a QGraphicsScene.

    Currently we can get that conversion by going through a QImage which involves a fair amount of additional data movement. Unfortunately this method also causes threading issues (under Mac OS X) where we get an error "QPixmap: It is not safe to use pixmaps outside the GUI thread". We don't see this warning running on Windows. The rendering of the QGraphicsPixmapItem is done with signaling to allow the GUI thread to add the updated tile to the QGraphicsScene.


    Right now we have a class that inherits from QGraphicsPixmapItem and the snippet below converts from an IplImage to a QImage to a QPixmap into our QGraphicsPixmapItem subclass. (Horribly inefficient!)
    Qt Code:
    1. unsigned char* qImageBuffer = (unsigned char*)(ipl_img->imageData);
    2. QImage* temp = new QImage((const unsigned char*)qImageBuffer, ipl_img->width, ipl_img->height, ipl_img->widthStep, QImage::Format_RGB888);
    3. QPixmap TEMP_pixmap;
    4. TEMP_pixmap.convertFromImage( *temp );
    5. this->setPixmap( TEMP_pixmap );
    To copy to clipboard, switch view to plain text mode 

    My question is if anyone knows how we might be able to write a direct conversion into a QPixmap or QGraphicsPixmapItem (from any basic image buffer)? Preferably this would be thread-safe under Windows & Mac OS even if we do this processing outside the GUI thread.

    Thanks in advance.

  2. #2
    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: QPixmap conversion from OpenCV

    We have a program that captures video data and we want to be able to render that data (from OpenCV's IplImage format) into a QGraphicsScene.
    If I can suggest something - drop the QPixmap and QGraphicsPixmapItem, you don't really need that for this task. You can create your own QGraphicsItem subclass (not QGraphicsPixmapItem) that will draw the QImage directly (QPainter has few drawImage(...) methods for that). This way it will be safe to use this class outside the GUI thread, and you can get rid of QImage -> QPixmap conversion as well.

Similar Threads

  1. Hex Conversion
    By umulingu in forum Newbie
    Replies: 5
    Last Post: 5th March 2010, 18:07
  2. Replies: 4
    Last Post: 28th August 2008, 13:13
  3. Replies: 1
    Last Post: 21st August 2008, 07:44
  4. Replies: 5
    Last Post: 9th April 2007, 14:26
  5. Reg - Conversion of Qt3 to Qt4
    By suresh in forum Qt Programming
    Replies: 10
    Last Post: 28th August 2006, 23:10

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.