PDA

View Full Version : QPixmap conversion from OpenCV



mooreaa
3rd November 2011, 21:47
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!)


unsigned char* qImageBuffer = (unsigned char*)(ipl_img->imageData);
QImage* temp = new QImage((const unsigned char*)qImageBuffer, ipl_img->width, ipl_img->height, ipl_img->widthStep, QImage::Format_RGB888);
QPixmap TEMP_pixmap;
TEMP_pixmap.convertFromImage( *temp );
this->setPixmap( TEMP_pixmap );


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.

stampede
4th November 2011, 10:17
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.