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

相关文章

怎样通过分析GC日志来定位Java进程的内存问题

《怎样通过分析GC日志来定位Java进程的内存问题》:本文主要介绍怎样通过分析GC日志来定位Java进程的内存问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、GC 日志基础配置1. 启用详细 GC 日志2. 不同收集器的日志格式二、关键指标与分析维度1.

MySQL中的表连接原理分析

《MySQL中的表连接原理分析》:本文主要介绍MySQL中的表连接原理分析,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、背景2、环境3、表连接原理【1】驱动表和被驱动表【2】内连接【3】外连接【4编程】嵌套循环连接【5】join buffer4、总结1、背景

python中Hash使用场景分析

《python中Hash使用场景分析》Python的hash()函数用于获取对象哈希值,常用于字典和集合,不可变类型可哈希,可变类型不可,常见算法包括除法、乘法、平方取中和随机数哈希,各有优缺点,需根... 目录python中的 Hash除法哈希算法乘法哈希算法平方取中法随机数哈希算法小结在Python中,

Java Stream的distinct去重原理分析

《JavaStream的distinct去重原理分析》Javastream中的distinct方法用于去除流中的重复元素,它返回一个包含过滤后唯一元素的新流,该方法会根据元素的hashcode和eq... 目录一、distinct 的基础用法与核心特性二、distinct 的底层实现原理1. 顺序流中的去重

关于MyISAM和InnoDB对比分析

《关于MyISAM和InnoDB对比分析》:本文主要介绍关于MyISAM和InnoDB对比分析,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录开篇:从交通规则看存储引擎选择理解存储引擎的基本概念技术原理对比1. 事务支持:ACID的守护者2. 锁机制:并发控制的艺

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