VideoCapure里的read是grab和retrieve的结合,由下面的函数介绍可知grab是指向下一个帧,retrieve是解码并返回一个帧,而且retrieve比grab慢一些,所以当不需要当前的帧或画面时,可以使用grab跳过,与其使用read更省时间。因为有的时候缓冲区的画面是存在了延迟的。当不需要的时候可以多grab之后再read的话,就能比一直read更省时间,因为没有必要把不需要的帧解码,由介绍可知也可以使用grab实现硬件同步。

VideoCapture::grab

Grabs the next frame from video file or capturing device.

C++: bool VideoCapture::grab()
Python: cv2.VideoCapture.grab() → retval
C: int cvGrabFrame(CvCapture* capture)
Python: cv.GrabFrame(capture) → int

The methods/functions grab the next frame from video file or camera and return true (non-zero) in the case of success.

The primary use of the function is in multi-camera environments, especially when the cameras do not have hardware synchronization. That is, you call VideoCapture::grab() for each camera and after that call the slower method VideoCapture::retrieve() to decode and get frame from each camera. This way the overhead on demosaicing or motion jpeg decompression etc. is eliminated and the retrieved frames from different cameras will be closer in time.

Also, when a connected camera is multi-head (for example, a stereo camera or a Kinect device), the correct way of retrieving data from it is to call VideoCapture::grab first and then call VideoCapture::retrieve() one or more times with different values of the channel parameter. See https://github.com/opencv/opencv/tree/master/samples/cpp/openni_capture.cpp

VideoCapture::retrieve

Decodes and returns the grabbed video frame.

C++: bool VideoCapture::retrieve(Mat& image, int channel=0)
Python: cv2.VideoCapture.retrieve([image[, channel]]) → retval, image
C: IplImage* cvRetrieveFrame(CvCapture* capture, int streamIdx=0 )
Python: cv.RetrieveFrame(capture[, index]) → image

The methods/functions decode and return the just grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more frames in video file), the methods return false and the functions return NULL pointer.

Note

OpenCV 1.x functions cvRetrieveFrame and cv.RetrieveFrame return image stored inside the video capturing structure. It is not allowed to modify or release the image! You can copy the frame using cvCloneImage() and then do whatever you want with the copy.

VideoCapture::read

Grabs, decodes and returns the next video frame.

C++: VideoCapture& VideoCapture::operator>>(Mat& image)
C++: bool VideoCapture::read(Mat& image)
Python: cv2.VideoCapture.read([image]) → retval, image
C: IplImage* cvQueryFrame(CvCapture* capture)
Python: cv.QueryFrame(capture) → image

The methods/functions combine VideoCapture::grab() and VideoCapture::retrieve() in one call. This is the most convenient method for reading video files or capturing data from decode and return the just grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more frames in video file), the methods return false and the functions return NULL pointer.

Note

OpenCV 1.x functions cvRetrieveFrame and cv.RetrieveFrame return image stored inside the video capturing structure. It is not allowed to modify or release the image! You can copy the frame using cvCloneImage() and then do whatever you want with the copy.

参考: 点击打开链接

opencv read grab retrieve 关系相关推荐

  1. [OpenCV] cv::VideoCapture中read和grab+retrieve的区别

    说明: read:直接获取下一帧数据编码后的图像. grab+retriebe:获取下一帧的数据(grab)到一个用户无法访问的内存区,根据通道号进行编码生成相应的图像(retrieve). 例子: ...

  2. OpenCV与相机的关系

    经常碰到朋友,尤其是计算机视觉初学者朋友问到我关于OpenCV怎么获取图片,怎么把OpenCV跟相机结合起来这一类的问题.本人不才,不过,在平时的工作中,都接触到这方面,今天特意发文章给有些朋友们解惑 ...

  3. Python OpenCV 计算机视觉:1~5

    原文:OpenCV Computer Vision with Python 协议:CC BY-NC-SA 4.0 译者:飞龙 本文来自[ApacheCN 计算机视觉 译文集],采用译后编辑(MTPE) ...

  4. openCV学习-自动处理图片 视频

    本文包括: mac环境的配置 一些学习和用法 读取视频 & 保存视频 & 磨皮测试 ** mac环境的配置: ** 安装: python-opencv依赖numpy.matplotli ...

  5. Ubuntu14.04配置pylon及Opencv并抓取图像显示

    Ubuntu14.04配置pylon及Opencv并抓取图像显示 文章目录 Ubuntu14.04配置pylon及Opencv并抓取图像显示 软件工具 安装Opencv 配置pkg-config 配置 ...

  6. 在Eclipse中使用OpenCV Java

    在Eclipse中使用OpenCV Java 在Eclipse中使用OpenCV Java 配置Eclipse 测试新Java项目上的配置 运行具有OpenCV和MKL依赖关系的Java代码 在Ecl ...

  7. QT与openCV,与PCL结合!

    (1):详解QT多媒体框架:给予视频播放器 原文链接:http://mobile.51cto.com/symbian-271123.htm 对于使用主框架的QT程序,实现Qimage的转换可借鉴下面程 ...

  8. Linux内核虚拟摄像头,Qt Opencv 在Linux下摄像头简单示例v1.0

    下面写的文章也许网上也有类似的,但是大多数都没有给出思路及背景,让初学者每次都只能学到一点皮毛,不少知识需要大量搜索零碎地拼凑起来.题外话,虽然现在是碎片化信息时代,但正是这样信息整合能力也显得非常重 ...

  9. Firefly AIO-3399Pro C开发板交叉编译OpenCV 3.4.10及FFmpeg、x264等依赖库,实现视频播放等功能

    文章目录 前言 一.开发部署环境 二.安装前的相关包下载及环境准备 1. Qt交叉编译环境搭建 2.安装环境所需依赖包 3. 交叉编译OpenCV所需x264.FFmpeg等依赖库 3.1 nasm编 ...

最新文章

  1. 制作win2000能用的 schtasks.exe
  2. 从Android的结构看HarmonyOS
  3. java plus方法_Java中MyBatis Plus知识点总结
  4. 外部情况错综复杂,联想靠什么过「久日子」
  5. 【SCOI 2009】生日快乐
  6. 采用三层架构(JAVA)设计学生管理系统
  7. git已有项目修改提交
  8. Java Excel导出
  9. 【转】XP/2000无法使用“缩略图查看”、右键无“设置桌面背景”选项问题详解...
  10. FlexViewer2.3中拉帘Widget下载
  11. 那些你不知道的 LVS 秘密!
  12. logo是啥_logo是什么?
  13. sklearn 线性回归_机器学习初级算法(二)——线性回归
  14. DcotrineFixtureBundle学习
  15. 【优化算法】改进型的LMS算法-NLMS算法【含Matlab源码 631期】
  16. 软件项目实施进度计划表
  17. c语言公路竖曲线要素代码,竖曲线要素
  18. python井字棋_python实现井字棋游戏
  19. 所谓的1261考核法算不算是末尾淘汰?
  20. 微信会员卡如何为不同用户设置不同有效期?

热门文章

  1. echarts折线图无数据断开解决方法
  2. C3P0 连接问题 An attempt by a client to checkout a Connection has timed out.
  3. 数据结构课程设计(魔王语言(c语言)的简单代码)
  4. bzoj 2244: [SDOI2011]拦截导弹 cdq分治
  5. 【181125】VC++ 绘制立方体的生成与控制旋转程序源代码
  6. 美团、阿里正在你看不见的地方争抢4万亿蛋糕
  7. gyp: No Xcode or CLT version detected 报错
  8. [m0leCon beginner 2022] 部分
  9. linux mysql添加视图_Linux下MySQL的简单使用(二)
  10. 软件测试相关简要记录