资源简介
linux下v4l2实现图片采集
在开发板上要交互编译
最好是静态交互
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include “v4l2grab.h“
#define TRUE 1
#define FALSE 0
#define FILE_VIDEO “/dev/video0“
#define BMP “image_bmp.bmp“
#define YUV “image_yuv.yuv“
#define IMAGEWIDTH 640
#define IMAGEHEIGHT 480
static int fd;
static struct v4l2_capability cap;
struct v4l2_fmtdesc fmtdesc;
struct v4l2_format fmtfmtack;
struct v4l2_streamparm setfps;
struct v4l2_requestbuffers req;
struct v4l2_buffer buf;
enum v4l2_buf_type type;
unsigned char frame_buffer[IMAGEWIDTH*IMAGEHEIGHT*3];
struct buffer
{
void * start;
unsigned int length;
} * buffers;
int init_v4l2(void)
{
int i;
int ret = 0;
//opendev
if ((fd = open(FILE_VIDEO O_RDWR)) == -1)
{
printf(“Error opening V4L interface\n“);
return (FALSE);
}
//query cap
if (ioctl(fd VIDIOC_QUERYCAP &cap) == -1)
{
printf(“Error opening device %s: unable to query device.\n“FILE_VIDEO);
return (FALSE);
}
else
{
printf(“driver:\t\t%s\n“cap.driver);
printf(“card:\t\t%s\n“cap.card);
printf(“bus_info:\t%s\n“cap.bus_info);
printf(“version:\t%d\n“cap.version);
printf(“capabilities:\t%x\n“cap.capabilities);
if ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == V4L2_CAP_VIDEO_CAPTURE)
{
printf(“Device %s: supports capture.\n“FILE_VIDEO);
}
if ((cap.capabilities & V4L2_CAP_STREAMING) == V4L2_CAP_STREAMING)
{
printf(“Device %s: supports streaming.\n“FILE_VIDEO);
}
}
//emu all support fmt
fmtdesc.index=0;
fmtdesc.type=V4L2_BUF_TYPE_VIDEO_CAPTURE;
printf(“Support format:\n“);
while(ioctl(fdVIDIOC_ENUM_FMT&fmtdesc)!=-1)
{
printf(“\t%d.%s\n“fmtdesc.index+1fmtdesc.description);
fmtdesc.index++;
}
//set fmt
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
fmt.fmt.pix.height = IMAGEHEIGHT;
fmt.fmt.pix.width = IMAGEWIDTH;
fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
if(ioctl(fd VIDIOC_S_FMT &fmt) == -1)
{
printf(“Unable to set format\n“);
return FALSE;
}
if(ioctl(fd VIDIOC_G_FMT &fmt) == -1)
{
printf(“Unable to get format\n“);
return FALSE;
}
{
printf(“fmt.type:\t\t%d\n“fmt.type);
printf(“pix.pixelformat:\t%c%c%c%c\n“fmt.fmt.pix.pixelformat & 0xFF (fmt.fmt.pix.pixelformat >> 8) & 0xFF(fmt.fmt.pix.pixelformat >> 16) & 0xFF (fmt.fmt.pix.pixelformat >> 24) & 0xFF);
printf(“pix.height:\t\t%d\n“fmt.fmt.pix.height);
printf(“pix.width:\t\t%d\n“fmt.fmt.pix.width);
printf(“pix.field:\t\t%d\n“fmt.fmt.pix.field);
}
//set fps
setfps.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
setfps.parm.capture.timeperframe.numerator = 10;
setfps.
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-08-28 10:14 lab_v4l2_yuyv\
文件 616493 2016-08-26 20:47 lab_v4l2_yuyv\v4
文件 621895 2016-08-27 22:16 lab_v4l2_yuyv\v4l2grab
文件 9833 2016-08-28 10:14 lab_v4l2_yuyv\v4l2grab.c
文件 1981 2012-12-18 06:37 lab_v4l2_yuyv\v4l2grab.h
文件 11741 2012-12-19 04:39 lab_v4l2_yuyv\zed-camera
- 上一篇:基于DAC0832的信号发生器C程序
- 下一篇:CPIII DMS Inst
评论
共有 条评论