标准的V4L2 API

http://v4l.videotechnology.com/dwg/v4l2.pdf

在例程/home/dvevm_1_20/demos/ImageGray中,涉及到图像采集及显示的一些概念

主要的几个文件

capture.c

display.c

video.c

在demo里面采集用到的格式是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 four bytes is twopixels. Each four bytes is two Y's, a Cb and a Cr. Each Y goes to one of thepixels, and the Cb and Cr belong to both pixels. As you can see, the Cr and Cbcomponents have half the horizontal resolution of the Y component.

Example 2-1. V4L2_PIX_FMT_UYVY4 × 4 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

在imagegray里面把图片变成灰度是在filecopy_dec.c这个函数里面有这样的代码

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++;

}

}

从上面的UYVY的格式解释里面可以看到,变成灰度图像只是把图像四个字节跟0xff00ff00相与就可以了,一直没明白为什么还要在后面加上一个0x00800080相或,我原来一直以为是不是UYVY的格式解释不一样,找了半天各种格式之间区别的不少,讲到这个点子上的倒没看到,最后在TI的网站上有这样的回复

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  you can just set the Cb and Cr values to 0x80and leave the Y as is, as Y is the brightness/luminance and is essentially thegreyscale version of the image so if you set the color values to
a constantmedian value of 0x80 you end up with a grayscale image.

For working with the encodedecode demo, ifall you want to do is make the output look grayscale than the small functionmentioned above (and here) should still work for you. In the encodedecode demoyou are actually compressing and decompressing the video so you
could performthis operation between capture and compress or between decompress and display,either way should work as the frame buffer will be in the proper YCbCR 4:2:2format at both points. In YCbCr 4:2:2 you have a stream of bytes in the formCbYCrYCbYCrYCbYCrY...
and so on, where the Y values for luminance arefor each pixel and each 2 pixels shares a Cb and Cr for chrominance. Since agreyscale image is an image with only brightness/luminance and nochrominance/color all you have to do is remove the chrominance values,

howeversince the display is expecting an 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 be mid pointvalues of 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 step through and make all of the Cb and Cr values 0x80 so that 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)*2; xx+=2)//just operating on the chroma

      {

*( ( (unsigned char*)currentFrame ) + xx ) = 0x80; //set all chromato midpoint 0x80

         }

} // End process_imagebw()

对TVP5158采集到的YUV422分析,它是以UYVY格式存放的,因为U,V是正交化的由于本课题用到的图像处理基于黑白图像,所以只需对Y分量进行处理,那么第一步就是对YUV422提取出Y,如果要保留Y分量,那么需将UV置为0x80,如需置白/黑色,Y分量设为FF/00,提取出亮度信号后,即可作简单的二值化.

UV是色差分量,UV为0就会全是绿色,全为0x80的时候才能看到灰度图。

【DSP开发】【图像处理】Gray与YUV之间的转换关系的更多相关文章

  1. C# 图像处理:Bitmap 与 Image 之间的转换

    Image img = this.pictureBox1.Image; Bitmap map = new Bitmap(img); Image img = Bitmap; Image和Bitmap类概 ...

  2. iOS开发之--NSData与UIImage之间的转换

    //NSData转换为UIImage NSData *imageData = [NSData dataWithContentsOfFile: imagePath]; UIImage *image = ...

  3. jsonObject关于xml,json,bean之间的转换关系

    1.json转换为JAVA @Test public void jsonToJAVA() { System.out.println("json字符串转java代码"); Strin ...

  4. Android开发系列之屏幕密度和单位转换

    由于Android的开源性,所以目前市面上面Android手机的分辨率特别多,这样的话就给我适配带来了一定的难度.要想做好适配,我们首先应该明白什么是分辨率.PPI.屏幕大小等概念,还有在不同的屏幕密 ...

  5. rem、em、px之间的转换

    rem是相对于根元素<html>,这样就意味着,我们只需要在根元素确定一个参考值,这个参考值设置为多少,完全可以根据您自己的需求来定. 我们知道,浏览器默认的字号16px,来看一些px单位 ...

  6. Python-时间戳、元组时间的格式、自定义时间格式之间的转换

    一.时间戳.元组时间的格式.自定义时间格式之间的转换 1.下面是三者之间的转换关系: 2.代码如下: import time import datetime print(time.time()) #获 ...

  7. DSP开发资源总结,经典书籍,论坛

    OMAP4开发资源总结: 一.TI OMAP4官网介绍: http://www.ti.com.cn/general/cn/docs/wtbu/wtbuproductcontent.tsp?templa ...

  8. (转)FFMPEG 实现 YUV,RGB各种图像原始数据之间的转换(swscale)

    雷霄骅分类专栏: FFMPEG FFmpeg 本文链接:https://blog.csdn.net/leixiaohua1020/article/details/14215391 FFMPEG中的sw ...

  9. 【DSP开发】CCS数据格式 load

    CCS支持的.dat文件详解(转载于hellodsp) CCS支持的.dat文件的格式为: 定数 数据格式 起始地址 页类型 数据块大小 1651 其后是文件内容,每行表示一个数据. 定数固定为&qu ...

随机推荐

  1. Java-Base64工具类

    /* * Base64 encoding and decoding. * Copyright (C) 2001-2004 Stephen Ostermiller * http://ostermille ...

  2. NServiceBus:使用自定义log4net

    安装扩展包:NServiceBus.Log4Net Endpoint.cs增加注入 log4net.Config.BasicConfigurator.Configure(); NServiceBus. ...

  3. 题解 [ZJOI2008]树的统计Count

    [ZJOI2008]树的统计Count Description 一棵树上有n个节点,编号分别为1到n,每个节点都有一个权值w.我们将以下面的形式来要求你对这棵树完成一些操作: I. CHANGE u ...

  4. 对Sting类型的探讨

    string类型经常和基本数据类型一起被我们熟练运用,但却不被归为基本数据类型,他是特殊的引用类型.引用数据类型还有类,接口.数组.枚举类型和注解类型. 我们来看下jdk对他的解释: String是在 ...

  5. Image图片自适应 Image resizeMode属性

    cover比较安全 cover模式只求在显示比例不失真的情况下填充整个显示区域.可以对图片进行放大或者缩小,超出显示区域的部分不显示, 也就是说,图片可能部分会显示不了.contain模式是要求显示整 ...

  6. poj 2976 Dropping tests (最大化平均值:二分查找)

    #include<iostream> #include<algorithm> #include<stdio.h> #include<math.h> #d ...

  7. POI2012 BEZ-Minimalist Security | noi.ac #537 Graph

    题目链接:戳我 首先注意这张图有可能不连通!! 然后我们考虑对于每一个联通块,首先任意确定一个点,给它设最终值为x,然后进行搜索.(因为对于一个联通块而言,我们知道一个点的最终值,那么整个联通块上面点 ...

  8. 推荐系统系列(五):Deep Crossing理论与实践

    背景 特征工程是绕不开的话题,巧妙的特征组合也许能够为模型带来质的提升.但同时,特征工程耗费的资源也是相当可观的,对于后期模型特征的维护.模型线上部署不太友好.2016年,微软提出Deep Cross ...

  9. 十八、MySQL 数据排名查询某条数据是总数据的第几条

    ) as rowno )) b ORDER BY a.zjf DESC 注意:mysql的下标是从0开始的 参考文章: https://blog.csdn.net/warylee/article/de ...

  10. Routing(exchange--direct)

    引言 它是一种完全按照routing key(路由关键字)进行投递的:当消息中的routing key和队列中的binding key完全匹配时,才进行会将消息投递到该队列中 1.模型 2.创建生产者 ...