Camera 驱动和编程


了解了framebuffer,摄像头便只是fb的数据来源而已。

先了解些相关的概念:

V4L2(video 4 linux 2)  

可以支持多种设备,它可以有以下几种接口:

  1. 视频采集接口(video capture interface):这种应用的设备可以是高频头或者摄像头.V4L2的最初设计就是应用于这种功能的.

  2. 视频输出接口(video output interface):可以驱动计算机的外围视频图像设备--像可以输出电视信号格式的设备.

  3. 直接传输视频接口(video overlay interface):它的主要工作是把从视频采集设备采集过来的信号直接输出到输出设备之上,而不用经过系统的CPU.

  4. 视频间隔消隐信号接口(VBI interface):它可以使应用可以访问传输消隐期的视频信号.

  5. 收音机接口(radio interface):可用来处理从AM或FM高频头设备接收来的音频流.

 

Video4linux下视频编程的流程:

(1)打开视频设备:

(2)读取设备信息

(3)更改设备当前设置(没必要的话可以不做)

(4)进行视频采集,两种方法:

a.内存映射

b.直接从设备读取

(5)对采集的视频进行处理

(6)关闭视频设备。

/* 这样的流程地球人都晓得 */

 

 

关键步骤介绍 :

(1)打开视频:

Open(”/dev/video0”,vdàfd);

关闭视频设备用close(”/dev/video0”,vdàfd);

(2)video_capability中信息

ioctl(vd->fd, VIDIOCGCAP, &(vd->capability))

成功后可读取vd->capability各分量 eg.

(3)读video_picture中信息

ioctl(vd->fd, VIDIOCGPICT, &(vd->picture));

(4)改变video_picture中分量的值 (可以不做的)

先为分量赋新值,再调用VIDIOCSPICT

Eg.

vd->picture.colour = 65535;

if(ioctl(vd->fd, VIDIOCSPICT, &(vd->picture)) < 0)

{

perror("VIDIOCSPICT");

return -1;

}

(5)初始化channel (可以不做的)

必须先做得到vd->capability中的信息

for (i = 0; i < vd->capability.channels; i++)

{

vd->channel[i].channel = i;

if (ioctl(vd->fd, VIDIOCGCHAN, &(vd->channel[i])) < 0)

{

perror("v4l_get_channel:");

return -1;

}

}

/* 通过ioctl,将struct v4l_struct作为参数的设备操作而已,那么重点将是整个结构体:struct v4l_struct*/

 

typedef struct v4l_struct

{

int fd;

struct video_capability capability;

struct video_channel channel[4];

struct video_picture picture;

struct video_window window;

struct video_capture capture;

struct video_buffer buffer;

struct video_mmap mmap;

struct video_mbuf mbuf;

unsigned char *map;

int frame;

int framestat[2];

}vd;

 

/* 那么,对该结构体的了解便成了关键*/

Video4linux支持的数据结构及其用途

(1)video_capability 包含设备的基本信息(设备名称、支持的最大最小分辨率、信号源信息等),包含的分量:

name[32] //设备名称

maxwidth ,

maxheight,

minwidth,

minheight

Channels //信号源个数

type //是否能capture,彩色还是黑白,是否能裁剪等等。值如VID_TYPE_CAPTURE等

(2)video_picture设备采集的图象的各种属性

brightness 0~65535

hue

colour

contrast

whiteness

depth // 24

palette // VIDEO_PALETTE_RGB24

(3)video_channel 关于各个信号源的属性

Channel //信号源的编号

name

tuners

Type // VIDEO_TYPE_TV | IDEO_TYPE_CAMERA

Norm制式

(4)video_window //包含关于capture area的信息

x x windows 中的坐标.

y x windows 中的坐标.

width The width of the image capture.

height The height of the image capture.

chromakey A host order RGB32 value for the chroma key.

flags Additional capture flags.

clips A list of clipping rectangles. (Set only)

clipcount The number of clipping rectangles. (Set only)

(5)video_mbuf //利用mmap进行映射的帧的信息

size //每帧大小

Frames //最多支持的帧数

Offsets //每帧相对基址的偏移

(6)video_buffer 最底层对buffer的描述

void *baseBase // physical address of the buffer

int height // Height of the frame buffer

int width // Width of the frame buffer

int depth // Depth of the frame buffer

int bytesperline // Number of bytes of memory between the start of two adjacent lines

实际显示的部分一般比它描述的部分小

(7)video_mmap //用于mmap

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 下一页

相关内容