linux下v4l2的usb摄像头四幅图像采集,linux下V4L2的USB摄像头四幅图像采集.doc

linux下V4L2的USB摄像头四幅图像采集

//#Rockie Cheng

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#define CLEAR(x) memset (&(x), 0, sizeof (x)) //宏定义清楚

struct buffer {

void * start;

size_t length;

}; //定义一个buffer结构体,这个结构体用于盛放申请到的内存首地址和长度

static char *dev_name = "/dev/video0";//摄像头设备名

static int fd = -1; //文件描述符fd

struct buffer *buffers = NULL;

static unsigned int n_buffers = 0;

FILE *file_fd; //

static unsigned long file_length;

static unsigned char *file_name;

//获取一帧数据,

static int read_frame (void)

{

struct v4l2_buffer buf; //用于盛放一帧数据的信息

unsigned int i;

CLEAR (buf);

buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

buf.memory = V4L2_MEMORY_MMAP;

int ff = ioctl (fd, VIDIOC_DQBUF, &buf); //从视频缓冲区的输出队列中取得一个已经保存有一帧视频数据的视频缓冲区

if(ff<0)

printf("failture\n"); //出列采集的帧缓冲

assert (buf.index < n_buffers);

printf ("buf.index dq is %d,\n",buf.index);

fwrite(buffers[buf.index].start, buffers[buf.index].length, 1, file_fd); //将其写入文件中

ff=ioctl (fd, VIDIOC_QBUF, &buf); //再将其入列,投放一个空的视频缓冲区到视频缓冲区输入队列中

if(ff<0)

printf("failture VIDIOC_QBUF\n");

return 1;

}

//主函数

int main (int argc,char ** argv)

{

struct v4l2_capability cap;

/*储存了硬件的信息,由驱动填写各个元素的值,包含:驱动名称,硬件名称,版本号,

硬件支持的功能:V4L2_CAP_VIDEO_CAPTURE(支持视频捕捉接口)*/

struct v4l2_format fmt;

/*流数据的格式,

struct v4l2_format

{

enum v4l2_buf_type type;

union

{

struct v4l2_pix_format pix;

// V4L2_BUF_TYPE_VIDEO_CAPTURE包含每幅图片的一行,一列所占的像素个数,width和heigth;

//像素格式与压缩类型pixelformat;一幅图像的数据所用的最大字节数imagesize=bytesline*heigth

struct v4l2_window win; // V4L2_BUF_TYPE_VIDEO_OVERLAY

struct v4l2_vbi_format vbi; // V4L2_BUF_TYPE_VBI_CAPTURE

struct v4l2_sliced_vbi_format sliced; // V4L2_BUF_TYPE_SLICED_VBI_CAPTURE

__u8

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值