这一段时间在做摄像头控制方面的工作,需要在Linux下实现对摄像头名称和分辨率的获取,同时对亮度、对比度、曝光值等参数进行控制,同时还需要对获取的帧画面进行处理。目前除了图像处理方面,简单的使用V4l2获取设备属性并可以打开摄像头进行参数控制,以及将读取的原始YUYV2帧数据转换为RGB24格式显示在QLabel上都可以实现,今天先在这里做个总结。
1.对于V4l2常用的结构体以及相关的命令符,网上都有很多参考,对照着官网文档慢慢理解也都能顺下来,下边也就放一点自己学习期间的理解,可能还有错误的地方,不过也没时间细看了,放着以后有时间再来完善吧。
-----------------------------------------------------------------------V4L2常用结构体说明----------------------------------------------------------------------
结构体来源:/usr/include/linux/videodev2.h文件。
*************************************************************************************************************************************************
struct v4l2_capability {
__u8 driver[16]; //驱动名称
__u8 card[32]; //设备名称
__u8 bus_info[32]; //总线信息
__u32 version; //驱动版本号
__u32 capabilities; //设备具备的功能
__u32 device_caps; //通过特定设备(节点)访问的功能(不知道用处,网上其它资料没有该字段)
__u32 reserved[3]; //保留字段
};
说明:该结构体常用来获取设备信息,使用VIDIOC_QUERYCAP命令符,包括驱动名、设备名以及版本号等等,其中capabilities成员表示设备支持的操作模式,比如V4L2_CAP_VIDEO_CAPTURE代表着该设备是一个视频捕捉设备,可以通过(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)来判定该设备是否具备改能力。由于V4L2涵盖了各种设备,不只是摄像头设备,不同的设备具备的能力也不一定相同,因此有需要时也可以来判定指定设备的能力。
/* Values for 'capabilities' field */
#define V4L2_CAP_VIDEO_CAPTURE 0x00000001 /* Is a video capture device */
#define V4L2_CAP_VIDEO_OUTPUT 0x00000002 /* Is a video output device */
#define V4L2_CAP_VIDEO_OVERLAY 0x00000004 /* Can do video overlay */
#define V4L2_CAP_VBI_CAPTURE 0x00000010 /* Is a raw VBI capture device */
#define V4L2_CAP_VBI_OUTPUT 0x00000020 /* Is a raw VBI output device */
#define V4L2_CAP_SLICED_VBI_CAPTURE 0x00000040 /* Is a sliced VBI capture device */
#define V4L2_CAP_SLICED_VBI_OUTPUT 0x00000080 /* Is a sliced VBI output device */
#define V4L2_CAP_RDS_CAPTURE 0x00000100 /* RDS data capture */
#define V4L2_CAP_VIDEO_OUTPUT_OVERLAY 0x00000200 /* Can do video output overlay */
#define V4L2_CAP_HW_FREQ_SEEK 0x00000400 /* Can do hardware frequency seek */
#define V4L2_CAP_RDS_OUTPUT 0x00000800 /* Is an RDS encoder */
/* Is a video capture device that supports multiplanar formats */
#define V4L2_CAP_VIDEO_CAPTURE_MPLANE 0x00001000
/* Is a video output device that supports multiplanar formats */
#define V4L2_CAP_VIDEO_OUTPUT_MPLANE 0x00002000
/* Is a video mem-to-mem device that supports multiplanar formats */
#define V4L2_CAP_VIDEO_M2M_MPLANE 0x00004000
/* Is a video mem-to-mem device */
#define V4L2_CAP_VIDEO_M2M 0x00008000
#define V4L2_CAP_TUNER 0x00010000 /* has a tuner */
#define V4L2_CAP_AUDIO 0x00020000 /* has audio support */
#define V4L2_CAP_RADIO 0x00040000 /* is a radio device */
#define V4L2_CAP_MODULATOR 0x00080000 /* has a modulator */
#define V4L2_CAP_SDR_CAPTURE 0x00100000 /* Is a SDR capture device */
#define V4L2_CAP_EXT_PIX_FORMAT 0x00200000 /* Supports the extended pixel format */
#define V4L2_CAP_SDR_OUTPUT 0x00400000 /* Is a SDR output device */
#define V4L2_CAP_READWRITE 0x01000000 /* read/write systemcalls */
#define V4L2_CAP_ASYNCIO 0x02000000 /* async I/O */
#define V4L2_CAP_STREAMING 0x04000000 /* streaming I/O ioctls */
#define V4L2_CAP_DEVICE_CAPS 0x80000000 /* sets device capabilities field */
*************************************************************************************************************************************************
struct v4l2_fmtdesc {
__u32 index; /* Format number */
__u32 type; /* enum v4l2_buf_type */
__u32 flags;
__u8 &nbs