• PUDN用户
    了解作者
  • Unix_Linux
    开发工具
  • 1KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 74
    下载次数
  • 2005-09-12 17:04
    上传日期
linux下使用摄像头,采集图像,支持网眼的各类型号的摄像头
test_cam.rar
  • test_cam.c
    3KB
  • www.pudn.com.txt
    218B
内容介绍
#include <fcntl.h> #include <sys/types.h> #include <sys/ioctl.h> #include <stdio.h> #include <unistd.h> #include <assert.h rel='nofollow' onclick='return false;'> #include <linux/videodev.h> typedef struct{ int fd; int use_mmap; int width, height; int frame_rate; int frame_size; struct video_capability capability; struct video_buffer buffer; struct video_window vwin; struct video_picture picture; struct video_mmap vmmap; struct video_mbuf vmbuf; unsigned char *frame_buffer; int dev; int capturing; int buffer_size ; } video_device; #define DEFAULT_DEVICE "/dev/v4l/video0" ; int camera_open(char *dev, video_device *vd); int camera_close(video_device *vd); int camera_get_capability(video_device *vd); int camera_get_picture(video_device *vd); //int camera_grab_init(v4l_device *vd, int input, int norm); unsigned char * camera_grab_image(video_device *vd); //int camera_grab_sync(v4l_device *vd); //int camera_mmap_init(v4l_device *vd); //int camera_get_mbuf(v4l_device *vd); video_device vd; int camera_open (char *dev, video_device *vd) { printf("step1 \n"); //if (!dev) //dev = DEFAULT_DEVICE; if ((vd->fd = open("/dev/v4l/video0", O_RDWR))<0) { printf("open error \n"); return -1; } printf("step2 \n"); if (camera_get_capability(vd)<0) { printf("camera_get_capability error \n"); return -1; } printf("step3 \n"); if (camera_get_picture(vd)<0) { printf("camera_get_picture error \n"); return -1; } printf("step4 \n"); return 0; } int camera_get_capability(video_device *vd) { if (ioctl(vd->fd, VIDIOCGCAP, &(vd->capability))<0) { return -1; } return 0; } int camera_get_picture(video_device *vd) { if (ioctl(vd->fd, VIDIOCGPICT, &(vd->picture))<0) { return -1; } return 0; } int camera_close(video_device *vd) { close(vd->fd); return 0; } unsigned char * camera_grab_image(video_device *vd) { int len; int i; //assert(vd != (video_device *)0); if (vd->use_mmap) { if (!vd->capturing) { // 等待请求获取完整的帧 for (i = 0; i< vd->vmbuf.frames; ++i) { vd->vmmap.frame = i; if (ioctl(vd, VIDIOCMCAPTURE, &vd->vmmap)) { perror("VIDIOCMCAPTURE"); return 0; } } // 从零开始读 vd->vmmap.frame = 0; vd->capturing = 1; } // 给ioctl()传入VIDIOCSYNC,检查帧是否已经获取完成 if (ioctl(vd->dev, VIDIOCSYNC, &vd->vmmap.frame)) { //perror("VIDIOCSYNC:"); return 0; } return vd->frame_buffer + vd->vmbuf.offsets[vd->vmmap.frame]; } // 否则去读取确切的大小 len = read(vd->dev, vd->frame_buffer, vd->buffer_size); if(len<=0) return 0; if (len!=vd->buffer_size) { fprintf(stderr, "Expected to read %d bytes, actually read %d\n", vd->buffer_size, len); return 0; } return vd->frame_buffer; } int main() { if (camera_open("/dev/v4l/video0", &vd)) return -1; while(1){ sleep(1); camera_grab_image(&vd); } camera_close(&vd); return 1; }
评论
    相关推荐
    • 基于Linux摄像头编程
      基于Linux摄像头编程,编程步骤:打开摄像头驱动,设置摄像头的采集通道,获取摄像头的采集格式,申请缓冲块,定义自己封装的结构体指针分配堆空间,开始摄像头采集,将画面入队,循环显示视频流 不断的入队出队,...
    • Linux uvc 摄像头驱动
      这是一个Linux内核的摄像头驱动程序,是大家学习些驱动的好例子。。网上好多编译不过的。此驱动ubuntu下编译通过的
    • Linux摄像头驱动
      Linux2.4内核下的多款摄像头驱动,通过验证,完全成功!!! 特别添加中星微307B的驱动部分!!!
    • linux usb摄像头驱动
      linux usb摄像头驱动linux usb摄像头驱动
    • linux 摄像头
      linux下图像处理的代码,v4l2grab,在real6410开发板下测试通过
    • linux模拟摄像头
      ubuntu下,qt工程,可以打开模拟摄像头,打开格式为MJPG
    • zc301 摄像头 linux 实例
      zc301 摄像头linux 操作系统下获取图片的示例,可以在此基础上进行修改
    • Linux摄像头驱动
      Linux OmnVision 9650的驱动, 大家如果开发Linux摄像头驱动可以参考
    • linux摄像头采集驱动
      linux摄像头采集驱动spcaview.rar
    • 摄像头linux驱动
      桌面\OK6410摄像头测试程序\摄像头linux驱动\gspca-2.13.6.tar.gz