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. python脚本例子_python dict 字典 以及 赋值 引用的一些实例(详解)
  2. 教你如何不显示excel中#N/A
  3. unfold3d自动展uv_Maya2018超实用建模及UV展开功能视频教程
  4. 使用try_catch_finally处理流中的异常
  5. Java内存模型–快速概述和注意事项
  6. 【剑指offer】面试题62:圆圈中最后剩下的数字(Java)
  7. python 3.7.4 shell_centos7上Virtualenv从python3.4升级到Python3.7.4
  8. python+gensim︱jieba分词、词袋doc2bow、TFIDF文本挖掘
  9. 基于python的图书管理系统设计与实现论文_基于JAVA的图书馆管理系统设计[毕业论文_].doc...
  10. PMP考试-计算题公式汇总-(第6版)
  11. lcd12864资料
  12. 管家婆系统怎么创建提醒服务器,管家婆辉煌Ⅱ++10.1 -管家婆软件官方网站
  13. 运行代码时出现的问题
  14. GaN制备Micro-led(二)——光子晶体倒装 Micro-LED 制备的关键工艺(纳米压印光刻、干法刻蚀、介质薄膜沉积、物理气相沉积)
  15. 语句块是什么意思python_《语》字意思读音、组词解释及笔画数 - 新华字典 - 911查询...
  16. UserAgent 解析
  17. Typro使用以及安装教程来啦
  18. 电商营销策略介绍,电商营销手段有哪些
  19. MySQL入门学习的第一节(SQL语句)
  20. statement的意思和用法

热门文章

  1. 首次回收重型猎鹰火箭全部助推器,SpaceX再创历史!...
  2. Disruptor无锁ringbuff实现
  3. 多元线性回归与高斯误差模型的同源关系
  4. 最长递增子序列问题 nyoj 17单调递增最长子序列 nyoj 79拦截导弹
  5. 推荐一个下载神器(官网资料下载必备)
  6. .net 流——使用流进行文件复制
  7. 【情态动词练习题】Can / Could you
  8. MEM/MBA数学基础(03)整式与分式 运算
  9. 华为VS谷歌:万物互联,谁主沉浮?
  10. 基于Litepal数据库开发的记事软件