Reprinted from: http://blog.csdn.net/sxjk1987/article/details/7470545
The standard V4L2 API
Http://v4l.videotechnology.com/dwg/v4l2.pdf
In the routine /home/dvevm_1_20/demos/imagegray , some concepts of image acquisition and display are involved.
A few major documents
Capture.c
Display.c
Video.c
The format used in the demo is Uyvy
V4l2_pix_fmt_uyvy (' UYVY ')
Name
V4l2_pix_fmt_uyvy--variationof v4l2_pix_fmt_yuyv with different order of samples in memory
Description
In this format, each of four bytes is twopixels. Each of four bytes is the Y ' s, a Cb and a Cr. Each Y goes to one of Thepixels, and the Cb and Cr belong to both pixels. As can see, the Cr and cbcomponents has half the horizontal resolution of the Y component.
Example 2-1. v4l2_pix_fmt_uyvy4x4 Pixel image
Byte Order. Each cell is one byte.
Start + 0: |
Cb00 |
Y ' 00 |
Cr00 |
Y ' 01 |
Cb01 |
Y ' 02 |
Cr01 |
Y ' 03 |
Start + 8: |
Cb10 |
Y ' 10 |
Cr10 |
Y ' 11 |
Cb11 |
Y ' 12 |
Cr11 |
Y ' 13 |
Start + 16: |
Cb20 |
Y ' 20 |
Cr20 |
Y ' 21 |
Cb21 |
Y ' 22 |
Cr21 |
Y ' 23 |
Start + 24: |
Cb30 |
Y ' 30 |
Cr30 |
Y ' 31 |
Cb31 |
Y ' 32 |
Cr31 |
Y ' 33 |
Color Sample location.
|
0 |
|
1 |
|
2 |
|
3 |
0 |
Y |
C |
Y |
|
Y |
C |
Y |
1 |
Y |
C |
Y |
|
Y |
C |
Y |
2 |
Y |
C |
Y |
|
Y |
C |
Y |
3 |
Y |
C |
Y |
|
Y |
C |
Y |
In Imagegray, the image is turned into grayscale in the FILECOPY_DEC.C this function has such code
static void Picturegray (void *pinbuf,void*poutbuf,unsigned int len)
{
unsigned int i;
unsigned int * pIn = (unsigned int*) pinbuf;
unsigned int *pout= (unsigned int*) poutbuf;
Len >>= 2;
for (i=0;i<len;i++)
{
*pout= *pin & 0xff00ff00 | 0x00800080;
pin++;
pout++;
}
}
From the above uyvy of the format can be seen, into a grayscale image is just the image four bytes with 0xff00ff00 phase and can be, has not understood why also add a 0x00800080 in the back or, I originally thought is not uyvy the format of the explanation is not the same, Looking for a half-day various formats between the difference between a lot, talk about this idea is not seen, finally on TI's website has such a reply
I want to transfer the input image Ofyuv422 format to a gray image
If you want a grayscale output in the ycbcrcolorspace of your input can just set the Cb and Cr values to 0x80and Leav E The Y as is, as Y are the brightness/luminance and is essentially Thegreyscale version of the "If you set the col" or values to a Constantmedian value of 0x80 your end up with a grayscale image.
For working with the EncodeDecode demo, ifall your want to do are make the output look grayscale than the small functionment Ioned above (and here) should still In the EncodeDecode demoyou is actually compressing and decompressing the video so you could performthis operation Betwee n Capture and compress or between decompress and display,either it should work as the frame buffer would be in the proper YCbCR 4:2:2format at both points. In YCbCr 4:2:2 you has a stream of bytes in the formcbycrycbycrycbycry ... and so on, where the Y values for luminance is For each pixel and each 2 pixels shares a Cb and Cr for chrominance. Since Agreyscale image is a image with only brightness/luminance and nochrominance/color all of you has to does is remove the Chrominance values,
Howeversince the display is expecting a image formatted in color we cannot take themout completely,
But rather we can make the chrominancevalues constant, and for greyscale/b&w you want them to all is mid pointvalues O F 0x80 (out of 0xFF).
The code below does just this, if yougive it a pointer to the YCBCR 4:2:2 frame buffer and the size of the buffer Itwill s Tep through and make all of the Cb and Cr values 0x80 so, the Imageappears greyscale on the output.
Bernie Thompson:
Make the image greyscale by setting Allchrominance to 0x80
void Process_imagebw (void* currentframe, int yrows, int xpixels)
{
int xx = 0;
for (xx = 0; xx < (Yrows * xpixels), xx+=2)//just operating on the chroma
{
* (((unsigned char*) currentframe) + xx) = 0x80; Set all Chromato midpoint 0x80
}
}//End PROCESS_IMAGEBW ()
For the YUV422 analysis collected by TVP5158, it is stored in UYVY format, because u,v is orthogonal because the image processing used in this subject is based on black-and-white image, so only the Y component is processed, then the first step is to extract Y to YUV422, if you want to retain Y component, Then you need to set the UV 0x80, such as white/black, y component set to ff/00, extract the brightness signal, you can make a simple two value.
UV is chromatic component, UV 0 will be all green, all for 0x80 when you can see the gray scale.
YUV Turn Grayscale