Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

High performance QImage output to display

I'm trying to make video output (sequence of frames) to any qt visible widget. At beginning i thought that QLabel will be enough for this point... but i was wrong. Converting to pixmap is too overloading for processor at large images: 1080p for example.

Any other solution? (not QLabel?)

Example of code for one frame:

QImage m_outputFrameImage(width, height, QImage::Format_RGB888);
memcpy(m_outputFrameImage.bits(), m_frameRGB->data[0], height * width * 3);
QPixmap pixmap = QPixmap::fromImage(m_outputFrameImage); // BAD, slow and high load
/* Bad too (Same code?)
    QPainter painter;
    painter.begin(&pixmap);
    painter.drawImage(0, 0, m_outputFrameImage);
    painter.end();
*/
labelVideo->setPixmap(pixmap);
like image 786
DEgITx Avatar asked Jun 25 '12 17:06

DEgITx


People also ask

How do I display QPixmap?

A QPixmap can be used to show an image in a PyQT window. QPixmap() can load an image, as parameter it has the filename. To show the image, add the QPixmap to a QLabel. QPixmap supports all the major image formats: BMP,GIF,JPG,JPEG,PNG,PBM,PGM,PPM,XBM and XPM.

How do I display an image in Qt widget?

There isn't a widget specifically made for displaying images, but this can be done with the label widget. We do this with the pixmap property. QPixmap pic("/path/to/your/image"); ui->label->setPixmap(pic);

What is QImage C++?

The QImage class provides a hardware-independent image representation that allows direct access to the pixel data, and can be used as a paint device.

How do I crop an image in QT?

Since you use QPixmap, you can use its copy method and supply it with a QRect to perform the actual crop. Show activity on this post. Just use of the QPixmap's copy() functions.


1 Answers

Yes, render the frames to a QGLWidget and let the video card handle it. That's how Qt MultimediaKit, Phonon and others do it.

Some time ago I shared some code that demonstrated how to accomplish this task: Image scaling (KeepAspectRatioByExpanding) through OpenGL

like image 186
karlphillip Avatar answered Oct 11 '22 11:10

karlphillip