Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.
6838 Discussions

Anyone successfully converted a Firewire camera image?

hcostelha
Beginner
1,677 Views
I'm trying to convert an image in the format YUV422 given by a firewire camera to an RGB image, but unsuccessfull. No matter what I do I always get a very weird image.

I'm not sure which step to use, but I think that for an image width 320x240 the YUV422 image step would be 640, right?

This is what I do:

imgSize.width = 320;
imgSize.height = 240;

rgbImg = ippiMalloc_8u_C3( 320, 240, &step );
ippiYUV422ToRGB_8u_C2C3R( img, 640, rgbImg,
step, imgSize );

Thanks in advanced for any help.

Hugo
0 Kudos
8 Replies
hcostelha
Beginner
1,677 Views
I also tryed using the function ippiUYToYU422_8u_C2R firts to change the order in wich in wich values appear, but still with no success.
0 Kudos
Vladimir_Dudnik
Employee
1,677 Views
Hi,
do you know exactly format of data you got from your camera?
Regards,
Vladimir
0 Kudos
hcostelha
Beginner
1,677 Views
The fact that OpenCV uses BGR, IPP usually uses RGB, IPP uses a different pixel order with the YUV422 than firewire cameras (UY), can get very confusing, but finnaly I managed to get it working.

Sorry for the trouble and thanks for the help anyway.

Cheers.

Hugo
0 Kudos
Vladimir_Dudnik
Employee
1,677 Views
Oh, that's great that youfind solution. If it is IPP based, could you please share here you experience, it may help other people. And even if it is not IPP based it will be useful for us to know what we can improve or extend in IPP functionality.
Thanks,
Vladimir
0 Kudos
hcostelha
Beginner
1,677 Views
Sure,

In my program, besides 24-bit RGB images, I also need to use an BGR565 image, so my main concern was obatinning these images from the firewire camera. The main problem was converting a 24-bit RGB image to a BGR565 image (I don't think IPP has a function to do that, right?, or an ippiUY422ToRGB_8u_C2C3R?). I started testing it using OpenCV to show the image, to make sure that the conversion to RGB was going ok (one of the cases in the code below) and, after having it done successfully, I went to program the conversion from RGB to BGR565. One of my problems (probably lack of experience) was with the bit order when creating the RGB565 pixel value. I was a litle misguided by the IPP manual, since you have
G2 G1 G0 B4 B3 B2 B1 B0 | R4 R3 R2 R1 R0 G5 G4 G3
and actually I see it more has
G4 G3 G2 B7 B6 B5 B5 B3 | R7 R6 R5 R4 R3 G7 G6 G5
Nevertheless, it seems to me that although you have done a good job in increasing the available color conversion functions, there are still missing some.

This is more or less the code I had to use to be able to do it (I made a few changes to increase readability, so you might need to change things to become compilable).

Hope I could be of some help.

Cheers.

Hugo

---------------------------------> CODE START

Ipp8u *rgbImg, *imgYUV422_IPP;
int step, step1;
IppiSize imgSize;

rgbImg = ippiMalloc_8u_C3( width, height, &step );
imgYUV422_IPP = ippiMalloc_8u_C2( width, height, &step1 );
imgSize.width = width;
imgSize.height = height;

/* Actually step1 == width*2 */



/* Change pixel order */
ippiUYToYU422_8u_C2R( imgFirewire,
width*2,
tmpImg,
step1,
imgSize );

/* Convert to RGB */
ippiYUV422ToRGB_8u_C2C3R( tmpImg,
step1,
rgbImg,
step,
imgSize );

if (usingOpenCV )
{
/* Set iplImage with same data has ipp image */
cvSetData( iplImageRGB, rgbImg,
iplImageRGB->widthStep );

/* Convert to BGR */
cvCvtColor( iplImageRGB, iplImageBGR, CV_RGB2BGR );

/* Show image */
cvvNamedWindow("teste", 1);
cvvShowImage("teste", iplImageBGR);
}
else
{
/* Use a function of mine to convert from rgbImg to a
* BGR565 */
RGB24toBGR565( rgbImage, rgb565image, width, height);

/* Show the image using X*/
showImage(rgb565image)
}

RGB24toBGR565( rgbImage, rgb565image, width, height);
{
int i, r, g, b;

for ( i=0 ; i<2*(width)*(height) ; i+=2 )
{
r = *(rgbImage++);
g = *(rgbImage++);
b = *(rgbImage++);

/* BGR565
* -------- High --------- |--------- Low ---------
* R7 R6 R5 R4 R3 G7 G6 G5 | G4 G3 B7 B6 B5 B4 B3 B2
*/
rgb565image = (g<<3 & 0xe0) | (b>>3 & 0x1f);
rgb565image[i+1] = (r & 0xf8) | (g>>5 & 0x07);
}

---------------------------------> CODE END
0 Kudos
Vladimir_Dudnik
Employee
1,677 Views
Wow, thank you for so detailed description.
You are right, we do not have all the possible color-conversion functions. You know, as only we add some new cc function, we got several requests for new variants. It seems as endless process, so we are prefer to have some format conversion functions to make it as two step process. First, you need to convert data from some format to more common YCbCr or RGB/BGR and after that you can use general color-conversion algorithm. But you are right, 888 <-> 565/555 conversion is interesting case. We should think about such functionality. You can submit it as feature request through IPP tech support channel, so we can consider it in our plans.
Regards,
Vladimir
0 Kudos
costelha1
Beginner
1,677 Views
Just to let people know that in Intel IPP 5.0 beta there is a function called ippiCbYCr422ToRGB which solves this problem for a Firewire camera delivering UYV422 images.

Thanks for the help given and for the improvements in IPP 5.0 beta.
0 Kudos
Vladimir_Dudnik
Employee
1,677 Views
Hi,
thank you for mentioned it here!
Regards,
Vladimir
0 Kudos
Reply