最快的方法是将IplImage IPL_DEPTH_32S转换为QImage Format_RGB32 [英] Fastest method to convert IplImage IPL_DEPTH_32S to QImage Format_RGB32

查看:614
本文介绍了最快的方法是将IplImage IPL_DEPTH_32S转换为QImage Format_RGB32的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将IplImage IPL_DEPTH_32S转换为QImage Format_RGB32最快的方法是什么?



我需要从cam捕捉图片,并以30帧/秒的频率显示在窗体上。我试图使用QImage构造函数:

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

但图片已损坏。所以,我怎么能这么快(我认为把像素逐像素到QImage不是一个好的决定)?

解决方案

我开始,OpenCV默认使用 BGR格式。不是RGB!因此,在创建 QImage 之前,您需要将 IplImage 转换为RGB:

  cvtColor(image,image,CV_BGR2RGB); 

然后您可以:

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

请注意,上述构造函数不会像您所想的那样复制数据,因为文档规定:


缓冲区必须在QImage的整个生命周期内保持有效


具有性能问题的原因不是由于转化过程。这很可能是由你正在使用的绘图方法(这不是在问题中共享)。要总结很多blah blah blah,您应该呈现 QImage 到OpenGL纹理,让视频卡为你做所有的绘图。



你的问题有点误导,因为你的主要目标



另一个重要的事情要记住,当你说:


图片已损坏这是完全模糊的,它不帮助我们,因为有这个效果的一些原因,没有源代码是不可能肯定地告诉你做错了什么。共享原始图片和损坏的图片可能会给出一些问题所在的线索。



这是现在。祝你好运。


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 second. I tried to use QImage constructor:

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

but image was corrupted after this. So, how can I do this fast (I think putting pixel by pixel into QImage is not a good decision)?

解决方案

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.

这篇关于最快的方法是将IplImage IPL_DEPTH_32S转换为QImage Format_RGB32的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆