在Linux环境下,你可以使用Video4Linux2 (V4L2) API来获取摄像头画面。
下面是一个示例程序,它打开了/dev/video0设备(通常是系统默认的摄像头设备),并使用IOCTL调用来设置摄像头的分辨率和帧率。然后,它通过read函数从设备中读取帧数据,并将其保存到文件中。
``` #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h>
#include <getopt.h> /* getopt_long() */
#include <fcntl.h> /* low-level i/o */ #include <unistd.h> #include <errno.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/time.h> #include <sys/mman.h> #include <sys/ioctl.h>
#include <linux/videodev2.h>
#define CLEAR(x) memset(&(x), 0, sizeof(x))
enum io_method { IO_METHOD_READ, IO_METHOD_MMAP, IO_METHOD_USERPTR, };
struct buffer { void *start; size_t length; };
static char *dev_na