1

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 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.

Harrisson
  • 255
  • 2
  • 21
  • 1
    You gotta post some code, so that we have something to talk about. – Mikhail Mar 13 '17 at 08:45
  • @Mikhail, Sure, I will post in sometime. – Harrisson Mar 13 '17 at 08:57
  • 1
    I presume you realise that the `U` and `V` components of `YUV` are often subsampled, so they are not present for every `Y` sample? Have you tried converting the image in straight, sequential CPU code? – Mark Setchell Mar 13 '17 at 10:12
  • @Mark, No actually, I did not try it on the CPU. However, Let me correct, I am currently using only Y component. So it shouldnt be a problem. Can only Y be allowed to be converted to the image – Harrisson Mar 13 '17 at 10:23
  • @Mark, I have tried the straight sequential CPU code as well and this time all I am getting is 3 zeros followed by 1 and same sequence is repeated for the whole image. – Harrisson Mar 14 '17 at 07:45
  • @Harrisson did you test yuv to rgb routines here: http://stackoverflow.com/questions/17892346/how-to-convert-rgb-yuv-rgb-both-ways – huseyin tugrul buyukisik Mar 14 '17 at 14:57
  • @Huseyin, no not yet I could give it a try – Harrisson Mar 14 '17 at 15:36

2 Answers2

1

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.

Dithermaster
  • 6,223
  • 1
  • 12
  • 20
0

I have resolved the issue with respect to the concern. I didnt have to convert into any other format. I used the same YUV format read it perfectly on the device side as well. The only extra inclusion I did was include CL_RGBA as image_format.

Harrisson
  • 255
  • 2
  • 21