如何YUY2转换为位图中的C ++ [英] How to convert yuy2 to a BITMAP in C++

查看:247
本文介绍了如何YUY2转换为位图中的C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用一个安全摄像头DLL中检索来自摄像头的图像。该DLL调用我的程序传递图像缓冲区作为参数的函数,但图像是YUY2格式。我需要这个缓冲区转换为RGB,但我想尽我的公式在互联网上找到,但没有成功。每个例子中,我试图(包括<一个href=\"http://msdn.microsoft.com/en-us/library/aa904813(VS.80).aspx#yuvformats_2\">http://msdn.microsoft.com/en-us/library/aa904813(VS.80).aspx#yuvformats_2)给我错误的颜色。

I'm using a security camera DLL to retreive the image from the camera. The DLL call a function of my program passing the image buffer as a parameter, but the image is in yuy2 format. I need to convert this buffer to RGB, but I tried every formula I found on Internet with no success. Every example I tried (including http://msdn.microsoft.com/en-us/library/aa904813(VS.80).aspx#yuvformats_2) gives me wrong colors.

我能缓冲区转换为仅使用像素的Y分量的BW的形象,但我真的需要彩色图像。我调试(仅组装)的显示在屏幕上的图像的DLL,它使用的DirectDraw做到这一点。

I'm able to convert the buffer to a BW image using only the Y component of the pixel, but I really need the color picture. I debugged (assembly only) the DLL that shows the image in the screen and it uses DirectDraw to do this.

推荐答案

此公式工作:

int C = luma - 16;
int D = cr - 128;
int E = cb - 128;
r = (298*C+409*E+128)/256;
g = (298*C-100*D-208*E+128)/256;
b = (298*C+516*D+128)/256;

我得到这个从MATLAB的例子。

I got this from a matlab example.

该疑难杂症是:在内存,Windows位图不是RGB,他们是BGR。如果你正在写一个内存缓冲区,你需要做的是这样的:

The gotcha is: in memory, Windows bitmaps aren't RGB, they are BGR. If you are writing to a memory buffer, you need to do something like this:

rgbbuffer[rgbindex] = (char)b;
rgbbuffer[rgbindex + 1] = (char)g;
rgbbuffer[rgbindex + 2] = (char)r;

这篇关于如何YUY2转换为位图中的C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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