opencv从缓冲区读取jpeg映像 [英] opencv read jpeg image from buffer

查看:2431
本文介绍了opencv从缓冲区读取jpeg映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含jpeg图片数据的 unsigned char * 缓冲区。我想使用c + +和opencv显示该图像。如果我这样做:

I have an unsigned char* buffer containing data of a jpeg image. I would like to display that image using c++ and opencv. If i do:

Mat img(Size(640, 480), CV_8UC3, data);
namedWindow("image", 1);
imShow("image", img);

我得到一个嘈杂的像素混乱。

I get a noisy mess of pixels.

我想这是因为数据是jpeg(带头)。因为这样工作:

I suppose it's because the data is jpeg (with a header). Because this works:

Mat imgbuf(Size(640, 480), CV_8UC3, data);
Mat img = imdecode(imgbuf, CV_LOAD_IMAGE_COLOR);

但是我不能使用imdecode函数,因为它是基于GTK 2的highgui.h,在我的项目中我使用GTK 3。

BUT I cannot use the imdecode function as it is from highgui.h which is based upon GTK 2, and in my project I use GTK 3.

那么,如何显示缓冲区数据?有没有办法解码jpeg图像而不是在opencv中的imdecode,如果这是问题。我真的不想重建opencv与Qt ...

So, how can I display the buffer data? Is there a way to decode the jpeg image other than imdecode in opencv, if that's the problem. I don't really want to have to rebuild opencv with Qt...

任何其他建议?

(使用Linux)

谢谢!

推荐答案

使用 libjpeg /tkimg/tkimg/libjpeg/libjpeg.docrel =nofollow> libjpeg API文档下的解压缩详细信息。

I have decompressed the JPEG image using libjpeg using the standard procedure described in the libjpeg API documentation under 'Decompression details'.

解压缩数据后你可以使用它来构造 cv :: Mat 。注意,解压缩的图像是RGB格式,而openCV使用BGR格式,因此 cvtColor()操作格式 CV_RGB2BGR

After having decompressed the data you can use it to construct the cv::Mat. Mind you, the decompressed image is in RGB format, whereas openCV uses a BGR format so a cvtColor() operation with format CV_RGB2BGR is needed.

这篇关于opencv从缓冲区读取jpeg映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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