QImage to Qpixmap conversion is too slow
-
Hi,
Can you give more information about how are these images created ? Passed around ?
Are they from a camera ?
Are you loading them from a file ?
Etc.They were loaded from a video file, then go into a processor where it will spit out packed RGB data frame by frame.
I found a stackoverflow answer about passing the
QImage
into aQOpenGLWidget
and then using itspaintEvent
to draw out the image, is this the way?https://stackoverflow.com/questions/20245865/render-qimage-with-opengl
-
What are you using to read your video file ?
Depending on that and the image format you could load the data directly into a texture and do the color space conversion in OpenGL rather than on the CPU side. -
What are you using to read your video file ?
Depending on that and the image format you could load the data directly into a texture and do the color space conversion in OpenGL rather than on the CPU side.@SGaist said in QImage to Qpixmap conversion is too slow:
What are you using to read your video file ?
Depending on that and the image format you could load the data directly into a texture and do the color space conversion in OpenGL rather than on the CPU side.That can be a future plan, but I want to do it one step at a time. For right now I need to know where to even start. The
Qimage
toQPixmap
conversion is cutting my playback speed in half. -
@SGaist said in QImage to Qpixmap conversion is too slow:
What are you using to read your video file ?
Depending on that and the image format you could load the data directly into a texture and do the color space conversion in OpenGL rather than on the CPU side.That can be a future plan, but I want to do it one step at a time. For right now I need to know where to even start. The
Qimage
toQPixmap
conversion is cutting my playback speed in half. -
@lansing
Hi
well try the OpenGLWidget::paintEvent code and see if its fast enough.
At least you don't have the conversion to pixmapHi This is what I have done so far:
class MyGLPainter : public QOpenGLWidget { Q_OBJECT public: MyGLPainter (QWidget *parent = nullptr); void paintEvent(QPaintEvent *) override; void drawImage(const QImage &image); private: QImage m_frameImage;
MyGLPainter::MyGLPainter (QWidget *parent): QOpenGLWidget(parent) { } void MyGLPainter::paintEvent(QPaintEvent *) { QPainter painter(this); painter.drawImage(m_frameImage.width(),m_frameImage.height(), m_frameImage); painter.end(); } void MyGLPainter::drawImage(const QImage &image) { m_frameImage = image; update(); }
But when I pass the image to
drawImage()
, the program will just crash. Am I doing this correctly? -
Hi This is what I have done so far:
class MyGLPainter : public QOpenGLWidget { Q_OBJECT public: MyGLPainter (QWidget *parent = nullptr); void paintEvent(QPaintEvent *) override; void drawImage(const QImage &image); private: QImage m_frameImage;
MyGLPainter::MyGLPainter (QWidget *parent): QOpenGLWidget(parent) { } void MyGLPainter::paintEvent(QPaintEvent *) { QPainter painter(this); painter.drawImage(m_frameImage.width(),m_frameImage.height(), m_frameImage); painter.end(); } void MyGLPainter::drawImage(const QImage &image) { m_frameImage = image; update(); }
But when I pass the image to
drawImage()
, the program will just crash. Am I doing this correctly? -
Do you update your image from a different thread? If so you should learn about threading: Threading Basics
-
Do you update your image from a different thread? If so you should learn about threading: Threading Basics
HI, is this related to the crash?
-
HI, is this related to the crash?
-
@lansing
Hi
then something is wrong with the image then.
Else why crash on copy.can you try with Image that you are 100% sure is valid ?
Hi, I have set the image to one in my resource folder for testing, now it has crashed at line
m_frameImage = image
. I have changed the image argument fromconst QImage &
toQImage*
, I don't know if that have a effect on it. But in debug, it did show my image dimension.QImage *img= new QImage(":/cross.png"); myGLPainter->drawImage(img);
-
Hi, I have set the image to one in my resource folder for testing, now it has crashed at line
m_frameImage = image
. I have changed the image argument fromconst QImage &
toQImage*
, I don't know if that have a effect on it. But in debug, it did show my image dimension.QImage *img= new QImage(":/cross.png"); myGLPainter->drawImage(img);
-
Hi, I have set the image to one in my resource folder for testing, now it has crashed at line
m_frameImage = image
. I have changed the image argument fromconst QImage &
toQImage*
, I don't know if that have a effect on it. But in debug, it did show my image dimension.QImage *img= new QImage(":/cross.png"); myGLPainter->drawImage(img);
@lansing said in QImage to Qpixmap conversion is too slow:
myGLPainter
Where do you initialize this variable?
-
Hi, I have set the image to one in my resource folder for testing, now it has crashed at line
m_frameImage = image
. I have changed the image argument fromconst QImage &
toQImage*
, I don't know if that have a effect on it. But in debug, it did show my image dimension.QImage *img= new QImage(":/cross.png"); myGLPainter->drawImage(img);
@lansing said in QImage to Qpixmap conversion is too slow:
QImage *img= new QImage(":/cross.png");
myGLPainter->drawImage(img);That's the wrong thing to do as you will leak images doing so.
Beside the initialization issue pointed by @Christian-Ehrlicher can you provide the stack trace of your crash ?