video4linux(v4l)使用摄像头的实例基础教程与体会(四)

获得图像前的初始化工作v4l_grab_init();该函数十分简单直接粘上去,其中将。vd->frame_using[0]vd->frame_using[1]都设为FALSE,表示两帧的截取都没有开始。

int v4l_grab_init(v4l_device *vd, int width, int height)  

{  

   vd->mmap.width = width;   

   vd->mmap.height = height;   

   vd->mmap.format = vd->picture.palette;   

   vd->frame_current = 0;  

   vd->frame_using[0] = FALSE;  

   vd->frame_using[1] = FALSE;  

  

   return v4l_grab_frame(vd, 0);  

}

       真正获得图像的函数extern int v4l_grab_frame(v4l_device *, int);

int v4l_grab_frame(v4l_device *vd, int frame)  

{  

   if (vd->frame_using[frame]) {  

      fprintf(stderr, "v4l_grab_frame: frame %d is already used./n", frame);  

      return -1;  

   }  

  

   vd->mmap.frame = frame;  

   if (ioctl(vd->fd, VIDIOCMCAPTURE, &(vd->mmap)) < 0) {  

      perror("v4l_grab_frame");  

      return -1;  

   }  

   vd->frame_using[frame] = TRUE;  

   vd->frame_current = frame;  

   return 0;  

}  

读到这里,应该觉得这个函数也是相当的简单。最关键的一步即为调用ioctl(vd->fd, VIDIOCMCAPTURE, &(vd->mmap)),调用后相应的图像就已经获取完毕。其他的代码是为了完成双缓冲就是截取两帧图像用的,可以自己理解下。

       在截取图像后还要进行同步操作,就是调用extern int v4l_grab_sync(v4l_device *);函数,该函数如下

int v4l_grab_sync(v4l_device *vd)  

{  

   if (ioctl(vd->fd, VIDIOCSYNC, &(vd->frame_current)) < 0) {  

      perror("v4l_grab_sync");  

   }  

   vd->frame_using[vd->frame_current] = FALSE;  

   return 0;  

}  

该函数返回0说明你想要获取的图像帧已经获取完毕。

图像存在了哪里?

       最终我们使用v4l的目的是为了获取设备中的图像,那么图像存在哪里?从上面的文章可以知道,vd.map指针所指就是你要获得的第一帧图像。图像的位置,存在vd.map+vd.mbuf.offsets[vd.frame_current]处。其中vd.frame_current=0,即为第一帧的位置,vd.frame_current=1,为第二帧的位置。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
NU/Linux Rapid Embedded Programming by Rodolfo Giometti English | 29 Mar. 2017 | ASIN: B01IBPRA94 | 732 Pages | AZW3 | 12.68 MB An annotated guide to program and develop GNU/Linux Embedded systems quickly About This Book Rapidly design and build powerful prototypes for GNU/Linux Embedded systems Become familiar with the workings of GNU/Linux Embedded systems and how to manage its peripherals Write, monitor, and configure applications quickly and effectively, manage an external micro-controller, and use it as co-processor for real-time tasks Who This Book Is For This book targets Embedded System developers and GNU/Linux programmers who would like to program Embedded Systems and perform Embedded development. The book focuses on quick and efficient prototype building. Some experience with hardware and Embedded Systems is assumed, as is having done some previous work on GNU/Linux systems. Knowledge of scripting on GNU/Linux is expected as well. What You Will Learn Use embedded systems to implement your projects Access and manage peripherals for embedded systems Program embedded systems using languages such as C, Python, Bash, and PHP Use a complete distribution, such as Debian or Ubuntu, or an embedded one, such as OpenWrt or Yocto Harness device driver capabilities to optimize device communications Access data through several kinds of devices such as GPIO's, serial ports, PWM, ADC, Ethernet, WiFi, audio, video, I2C, SPI, One Wire, USB and CAN Practical example usage of several devices such as RFID readers, Smart card readers, barcode readers, z-Wave devices, GSM/GPRS modems Usage of several sensors such as light, pressure, moisture, temperature, infrared, power, motion In Detail Embedded computers have become very complex in the last few years and developers need to be able to easily manage embedded computer projects by focusing on problem solving; they should not have to waste time finding supported peripherals or learning how to manage them. This book shows yo
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值