Fastest method to convert IplImage IPL_DEPTH_32S to QImage Format_RGB32

前端 未结 3 678
失恋的感觉
失恋的感觉 2021-01-28 08:27

What is the fastest method to convert IplImage IPL_DEPTH_32S to QImage Format_RGB32?

I need to catch pictures from cam and show it on form with frequency 30 frames in se

3条回答
  •  無奈伤痛
    2021-01-28 08:58

    Before I start, OpenCV uses the BGR format by default. Not RGB! So before creating the QImage you need to convert your IplImage to RGB with:

    cvtColor(image, image, CV_BGR2RGB);
    

    Then you can:

    QImage qImage((uchar*) image->imageData, image->width, image->height, QImage::Format_RGB32);
    

    Note that the constructor above doesn't copy the data as you might be thinking, as the docs states:

    The buffer must remain valid throughout the life of the QImage

    So if you are having performance issues are not because of the conversion procedure. It is most probably caused by the drawing method you are using (which wasn't shared in the question). To summarize a lot of blah blah blah, you should render the QImage to an OpenGL texture and let the video card do all the drawing for you.

    Your question is a bit misleading because your primary objective is not to find the fastest conversion method, but one that actually works since yours don't.

    Another important thing to keep in mind, when you said:

    image was corrupted after this

    you must know that this is completely vague, and it doesn't help us at all because there is a number of causes for this effect, and without the source code is impossible to tell with certainty what are you doing wrong. Sharing the original and the corrupted image might gives some clues to where the problem is.

    That's it for now. Good luck.

提交回复
热议问题