VideoCapture源代码分析

2024-02-20 20:08

本文主要是介绍VideoCapture源代码分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

本文转自: http://blog.csdn.net/dsgthlr/article/details/42265107

[cpp] view plain copy print ?
  1. 获取摄像头图像代码  
获取摄像头图像代码
[cpp] view plain copy print ?
  1. #include "opencv2/opencv.hpp"  
  2.   
  3. using namespace cv;  
  4.   
  5. int main(intchar**)  
  6. {  
  7.     VideoCapture cap(0); // open the default camera  
  8.     if(!cap.isOpened())  // check if we succeeded  
  9.         return -1;  
  10.   
  11.     Mat edges;  
  12.     namedWindow("edges",1);  
  13.     for(;;)  
  14.     {  
  15.         Mat frame;  
  16.         cap >> frame; // get a new frame from camera  
  17.         cvtColor(frame, edges, COLOR_BGR2GRAY);  
  18.         GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);  
  19.         Canny(edges, edges, 0, 30, 3);  
  20.         imshow("edges", edges);  
  21.         if(waitKey(30) >= 0) break;  
  22.     }  
  23.     // the camera will be deinitialized automatically in VideoCapture destructor  
  24.     return 0;  
  25. }  
#include "opencv2/opencv.hpp"using namespace cv;int main(int, char**)
{VideoCapture cap(0); // open the default cameraif(!cap.isOpened())  // check if we succeededreturn -1;Mat edges;namedWindow("edges",1);for(;;){Mat frame;cap >> frame; // get a new frame from cameracvtColor(frame, edges, COLOR_BGR2GRAY);GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);Canny(edges, edges, 0, 30, 3);imshow("edges", edges);if(waitKey(30) >= 0) break;}// the camera will be deinitialized automatically in VideoCapture destructorreturn 0;
}
[cpp] view plain copy print ?
  1.   
</pre><div class="dp-highlighter bg_cpp"><div class="bar"><div class="tools"><strong>[cpp]</strong> <a target=_blank title="view plain" class="ViewSource" href="http://blog.csdn.net/dsgthlr/article/details/42265107#">view plain</a><a target=_blank title="copy" class="CopyToClipboard" href="http://blog.csdn.net/dsgthlr/article/details/42265107#">copy</a><a target=_blank title="print" class="PrintSource" href="http://blog.csdn.net/dsgthlr/article/details/42265107#">print</a><a target=_blank title="?" class="About" href="http://blog.csdn.net/dsgthlr/article/details/42265107#">?</a></div></div><ol class="dp-cpp"><li class="alt"><span><span>类成员:  </span></span></li></ol></div><pre class="cpp" style="display: none;" name="code">类成员:
[cpp] view plain copy print ?
  1. <pre name="code" class="cpp">class CV_EXPORTS_W VideoCapture  
  2. {  
  3. public:  
  4.     CV_WRAP VideoCapture();  
  5.     CV_WRAP VideoCapture(const String& filename);       <span style="white-space:pre">    </span>//open video from url;  
  6.     CV_WRAP VideoCapture(int device);                   //open device  
  7.   
  8.     virtual ~VideoCapture();  
  9.     CV_WRAP virtual bool open(const String& filename);<span style="white-space:pre">          </span><span style="font-family: Arial, Helvetica, sans-serif;">                        </span><span style="font-family: Arial, Helvetica, sans-serif;">  
  10. </span>    CV_WRAP virtual bool open(int device);<span style="white-space:pre">             </span><pre name="code" class="cpp"><span style="white-space:pre">                                    </span>//<span style="font-family: Arial, Helvetica, sans-serif;">VideoCapture cap(0)   等价于</span><pre name="code" class="cpp"><span style="font-family: Arial, Helvetica, sans-serif;"><span>                                                                      </span>//VideoCapture cap;</span>  
<pre name="code" class="cpp">class CV_EXPORTS_W VideoCapture
{
public:CV_WRAP VideoCapture();CV_WRAP VideoCapture(const String& filename);		<span style="white-space:pre">	</span>//open video from url;CV_WRAP VideoCapture(int device);					//open devicevirtual ~VideoCapture();CV_WRAP virtual bool open(const String& filename);<span style="white-space:pre">			</span><span style="font-family: Arial, Helvetica, sans-serif;">						</span><span style="font-family: Arial, Helvetica, sans-serif;">
</span>    CV_WRAP virtual bool open(int device);<span style="white-space:pre">				</span><pre name="code" class="cpp"><span style="white-space:pre">									</span>//<span style="font-family: Arial, Helvetica, sans-serif;">VideoCapture cap(0)   等价于</span><pre name="code" class="cpp"><span style="font-family: Arial, Helvetica, sans-serif;"><span>																		</span>//VideoCapture cap;</span>
[cpp] view plain copy print ?
  1. <span style="font-family: Arial, Helvetica, sans-serif;"><span>                                                                     </span>//cap.open(0);<span> </span></span>  
<span style="font-family: Arial, Helvetica, sans-serif;"><span>																		</span>//cap.open(0);<span>	</span></span>
 

CV_WRAP virtual bool isOpened() const; //check if open sucessed CV_WRAP virtual void release();//close the already opened file or camera.CV_WRAP virtual bool grab();//The primary use of the function is in multi-camera environments, CV_WRAP virtual bool retrieve(OutputArray image, int flag = 0); virtual VideoCapture& operator >> (CV_OUT Mat& image); virtual VideoCapture& operator >> (CV_OUT UMat& image);

 
[cpp] view plain copy print ?
  1.     CV_WRAP virtual bool read(OutputArray image);<span style="white-space:pre">           </span>//cap.read(frame);等价于  cap>>frame;  
  2.   
  3.     CV_WRAP virtual bool set(int propId, double value);  
  4.     CV_WRAP virtual double get(int propId);  
  5.   
  6. protected:  
  7.     Ptr<CvCapture> cap;  
  8.     Ptr<IVideoCapture> icap;  
  9. private:  
  10.     static Ptr<IVideoCapture> createCameraCapture(int index);  
  11. };  
    CV_WRAP virtual bool read(OutputArray image);<span style="white-space:pre">			</span>//cap.read(frame);等价于  cap>>frame;CV_WRAP virtual bool set(int propId, double value);CV_WRAP virtual double get(int propId);protected:Ptr<CvCapture> cap;Ptr<IVideoCapture> icap;
private:static Ptr<IVideoCapture> createCameraCapture(int index);
};


这篇关于VideoCapture源代码分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/729396

相关文章

MyBatis Plus 中 update_time 字段自动填充失效的原因分析及解决方案(最新整理)

《MyBatisPlus中update_time字段自动填充失效的原因分析及解决方案(最新整理)》在使用MyBatisPlus时,通常我们会在数据库表中设置create_time和update... 目录前言一、问题现象二、原因分析三、总结:常见原因与解决方法对照表四、推荐写法前言在使用 MyBATis

Python主动抛出异常的各种用法和场景分析

《Python主动抛出异常的各种用法和场景分析》在Python中,我们不仅可以捕获和处理异常,还可以主动抛出异常,也就是以类的方式自定义错误的类型和提示信息,这在编程中非常有用,下面我将详细解释主动抛... 目录一、为什么要主动抛出异常?二、基本语法:raise关键字基本示例三、raise的多种用法1. 抛

github打不开的问题分析及解决

《github打不开的问题分析及解决》:本文主要介绍github打不开的问题分析及解决,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、找到github.com域名解析的ip地址二、找到github.global.ssl.fastly.net网址解析的ip地址三

Mysql的主从同步/复制的原理分析

《Mysql的主从同步/复制的原理分析》:本文主要介绍Mysql的主从同步/复制的原理分析,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录为什么要主从同步?mysql主从同步架构有哪些?Mysql主从复制的原理/整体流程级联复制架构为什么好?Mysql主从复制注意

java -jar命令运行 jar包时运行外部依赖jar包的场景分析

《java-jar命令运行jar包时运行外部依赖jar包的场景分析》:本文主要介绍java-jar命令运行jar包时运行外部依赖jar包的场景分析,本文给大家介绍的非常详细,对大家的学习或工作... 目录Java -jar命令运行 jar包时如何运行外部依赖jar包场景:解决:方法一、启动参数添加: -Xb

Apache 高级配置实战之从连接保持到日志分析的完整指南

《Apache高级配置实战之从连接保持到日志分析的完整指南》本文带你从连接保持优化开始,一路走到访问控制和日志管理,最后用AWStats来分析网站数据,对Apache配置日志分析相关知识感兴趣的朋友... 目录Apache 高级配置实战:从连接保持到日志分析的完整指南前言 一、Apache 连接保持 - 性

Linux中的more 和 less区别对比分析

《Linux中的more和less区别对比分析》在Linux/Unix系统中,more和less都是用于分页查看文本文件的命令,但less是more的增强版,功能更强大,:本文主要介绍Linu... 目录1. 基础功能对比2. 常用操作对比less 的操作3. 实际使用示例4. 为什么推荐 less?5.

spring-gateway filters添加自定义过滤器实现流程分析(可插拔)

《spring-gatewayfilters添加自定义过滤器实现流程分析(可插拔)》:本文主要介绍spring-gatewayfilters添加自定义过滤器实现流程分析(可插拔),本文通过实例图... 目录需求背景需求拆解设计流程及作用域逻辑处理代码逻辑需求背景公司要求,通过公司网络代理访问的请求需要做请

Java集成Onlyoffice的示例代码及场景分析

《Java集成Onlyoffice的示例代码及场景分析》:本文主要介绍Java集成Onlyoffice的示例代码及场景分析,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要... 需求场景:实现文档的在线编辑,团队协作总结:两个接口 + 前端页面 + 配置项接口1:一个接口,将o

IDEA下"File is read-only"可能原因分析及"找不到或无法加载主类"的问题

《IDEA下Fileisread-only可能原因分析及找不到或无法加载主类的问题》:本文主要介绍IDEA下Fileisread-only可能原因分析及找不到或无法加载主类的问题,具有很好的参... 目录1.File is read-only”可能原因2.“找不到或无法加载主类”问题的解决总结1.File