linux下usb camera图像采集(V4l2)

本文档展示了如何在Linux环境下使用V4L2(Video for Linux Two)API进行USB摄像头的图像采集,包括打开设备、获取设备信息、设置帧格式、映射内存和缓冲区管理等关键步骤。
摘要由CSDN通过智能技术生成
head.h
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <fcntl.h> /* low-level i/o */
  5. #include <unistd.h>
  6. #include <errno.h>
  7. #include <malloc.h>
  8. #include <sys/stat.h>
  9. #include <sys/types.h>
  10. #include <sys/time.h>
  11. #include <sys/mman.h>
  12. #include <sys/ioctl.h>
  13. #include <linux/videodev2.h>
  14. #define DEVICE "/dev/video"
  15. static struct v4l2_requestbuffers req;
  16. struct buffer
  17. {
  18.     void* start;
  19.     unsigned int length;
  20. };
  21. static struct buffer *buffers;
  22. static struct v4l2_buffer buf;

usb_camera.c
  1. #include "head.h"
  2. int main()
  3. {
  4.     int fd;
  5.     fd=open_device();
  6.     get_device_info(fd);
  7.     get_frame_fmt(fd);
  8.     get_current_frame_info(fd);
  9.     try_format_support(fd);
  10.     set_frame_format(fd);
  11.     apply_memory_buf(fd);
  12.     memory_mapping(fd);
  13.     buffer_enqueue(fd);
  14.     close(fd);
  15.     return 0;
  16. }
  17. int open_device()
  18. {
  19.     int fd;
  20.     
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值