本文介绍了YUV数据转换为图像格式Opencl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在一个项目中,我使用YUV作为输入,并且必须将此信息传递给内核以处理该功能.我曾研究过类似的问题,但从未找到准确解决我所关注问题的答案.我尝试了一种简单的方法,将YUV转换为用于Opencl处理的图像格式.但是,当我尝试打印已转换为图像的数据时,我得到的第一个值正确,然后再得到三个零,然后得到第5个像素值.我不明白写作是问题还是阅读部分.我对如何进行此操作感到困惑.如果有人能帮助我,我将不胜感激,或者如果您能给我有关如何将YUV转换为2D图像的示例,我将不胜感激.我是否有必要将YUV转换为RGB,以便在设备上进行处理.如果有人需要,我也可以发布示例代码.谢谢您的提前帮助.

I have been working on a project where I use YUV as an input and have to pass this information to the Kernel in order to process the function. I had looked into similar questions but never found an accurate answer to my concern. I have tried a simple method to convert the YUV into an Image format for Opencl Processing. However, when I try to print the data which has been converted into the image I get first value correct then another three as zeroes and then I get the 5th pixel value correct. I dont understand whether writing is the problem or the reading part. I am confused as to how to proceed on this. If anyone could help me I would be really grateful or if you can give me example on how to convert YUV into an 2D image. Is it necessary for me to convert YUV into RGB in order to process it on the device. I can also post the sample code if anyone needs it. Thank you for any help in advance.

/*Kernel Code*/

int2 position;
uint4 Input;
for(int i = 0; i < Frame_Height; i++){ 
for(int j = 0; j < Frame_Width; j+=4){ 
position = (int2)(j,i);
Input.s0 = (uint)YUV_Data[j];
Input.s1 = (uint)YUV_Data[j+1];
Input.s2 = (uint)YUV_Data[j+2];
Input.s3 = (uint)YUV_Data[j+3];
write_imageui( 2D_Image, position, Input );
}
YUV_Data += Frame_Width;
}

YUV_Data是未签名的字符.这里YUV_Data是包含输入YUV图像的缓冲区,但是我只处理代码中的Y元素.

YUV_Data is an unsigned char.Here YUV_Data is the buffer which contains input YUV Image, but I am just processing only Y element in the code.

推荐答案

我们的方法是在OpenCL Buffer 中传递YUV数据,然后运行将其转换为RGB的内核. OpenCL 图像,用于进一步的RGB处理. Some YUV格式可以作为图像传递;如果您可以随便这样做(但很多人不喜欢,例如v210,那么我们总是使用Buffers).在处理链的最后,如果我们再次需要YUV,我们将运行一个将RGB [A]图像转换为YUV缓冲区的内核.

The way we do it is we pass YUV data in an OpenCL Buffer, and run a kernel that converts it to RGB in an OpenCL Image which is used for further RGB processing. Some YUV formats could be passed as an Image; if yours can then feel free to do so (but many can't, such as v210, so we always use Buffers). At the end of our processing chain if we need YUV again we run a kernel that converts an RGB[A] Image into a YUV Buffer.

这篇关于YUV数据转换为图像格式Opencl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 14:28