我有一个电视采集卡,其中有一个 YUV 格式的提要.我在这里看到了与此问题类似的其他帖子,并尝试尝试所有可能的方法,但它们都没有提供清晰的图像.目前最好的结果是使用 OpenCV cvCvtColor(scr, dst, CV_YUV2BGR)
函数调用.
I have a TV capture card that has a feed coming in as a YUV format. I've seen other posts here similar to this question and attempted to try every possible method stated, but neither of them provided a clear image. At the moment the best results were with the OpenCV cvCvtColor(scr, dst, CV_YUV2BGR)
function call.
我目前不知道 YUV 格式,老实说让我有点困惑,因为它看起来存储 4 个频道,但只有 3 个?我已经包含了捕获卡中的图像,希望有人能够理解可能发生的事情,我可以用它来填补空白.
I am currently unaware of the YUV format and to be honest confuses me a little bit as it looks like it stores 4 channels, but is only 3? I have included an image from the capture card to hope that someone can understand what is possibly going on that I could use to fill in the blanks.
该提要通过 DeckLink Intensity Pro 卡进入,并在 Windows 7 环境中使用 OpenCV 的 C++ 应用程序中访问.
The feed is coming in through a DeckLink Intensity Pro card and being accessed in a C++ application in using OpenCV in a Windows 7 environment.
更新
我查看了有关此信息的维基百科文章,并尝试在我的应用程序中使用该公式.下面是带有从它接收到的输出的代码块.非常感谢任何建议.
I have looked at a wikipedia article regarding this information and attempted to use the formula in my application. Below is the code block with the output received from it. Any advice is greatly appreciated.
BYTE* pData;
videoFrame->GetBytes((void**)&pData);
m_nFrames++;
printf("Num Frames executed: %d
", m_nFrames);
for(int i = 0; i < 1280 * 720 * 3; i=i+3)
{
m_RGB->imageData[i] = pData[i] + pData[i+2]*((1 - 0.299)/0.615);
m_RGB->imageData[i+1] = pData[i] - pData[i+1]*((0.114*(1-0.114))/(0.436*0.587)) - pData[i+2]*((0.299*(1 - 0.299))/(0.615*0.587));
m_RGB->imageData[i+2] = pData[i] + pData[i+1]*((1 - 0.114)/0.436);
}
在我看来,您正在将 YUV422 流解码为 YUV444.尝试对您提供的代码进行此修改:
It looks to me like you're decoding a YUV422 stream as YUV444. Try this modification to the code you provided:
for(int i = 0, j=0; i < 1280 * 720 * 3; i+=6, j+=4)
{
m_RGB->imageData[i] = pData[j] + pData[j+3]*((1 - 0.299)/0.615);
m_RGB->imageData[i+1] = pData[j] - pData[j+1]*((0.114*(1-0.114))/(0.436*0.587)) - pData[j+3]*((0.299*(1 - 0.299))/(0.615*0.587));
m_RGB->imageData[i+2] = pData[j] + pData[j+1]*((1 - 0.114)/0.436);
m_RGB->imageData[i+3] = pData[j+2] + pData[j+3]*((1 - 0.299)/0.615);
m_RGB->imageData[i+4] = pData[j+2] - pData[j+1]*((0.114*(1-0.114))/(0.436*0.587)) - pData[j+3]*((0.299*(1 - 0.299))/(0.615*0.587));
m_RGB->imageData[i+5] = pData[j+2] + pData[j+1]*((1 - 0.114)/0.436);
}
我不确定你的常数是否正确,但最坏的情况是你的颜色会消失 - 图像应该是可识别的.
I'm not sure you've got your constants correct, but at worst your colors will be off - the image should be recognizable.
这篇关于OpenCV中将YUV转换为BGR或RGB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!