-
Notifications
You must be signed in to change notification settings - Fork 0
/
306 学用OpenCV笔记——01.从何学起.html
21 lines (20 loc) · 126 KB
/
306 学用OpenCV笔记——01.从何学起.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<html>
<head>
<title>306 学用OpenCV笔记——01.从何学起</title>
<basefont face="Tahoma" size="2" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="exporter-version" content="Evernote Windows/270217 (zh-CN); Windows/6.1.7600;"/>
<style>
body, td {
font-family: Tahoma;
font-size: 10pt;
}
</style>
</head>
<body>
<a name="2063"/>
<h1>306 学用OpenCV笔记——01.从何学起</h1>
<div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><p style="margin: 0px; padding: 5px 0px; line-height: 22px; color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; background-color: rgb(255, 255, 255);">用视觉识别可以做很多好玩的东西,比如有趣的互动艺术。不仅如此视觉识别的应用非常广泛,很感兴趣。OpenCV是个免费开源的视觉库,感谢OpenCV降低了门槛,让我这个外行菜鸟也可以学着玩玩视觉识别。</p><div style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; line-height: 21px; background-color: rgb(255, 255, 255);"><b style="font-weight: 600;">OpenCV</b> (Open Source Computer Vision Library: <a href="http://opencv.org/" style="color: rgb(0, 68, 153); text-decoration: none;">http://opencv.org</a>)</div><div style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; line-height: 21px; background-color: rgb(255, 255, 255);">Learning OpenCV – O’REILLY ,据说这是本OpenCV入门的好书。电子版下载:<a href="http://ishare.iask.sina.com.cn/f/6667035.html" style="color: rgb(0, 68, 153); text-decoration: none;">http://ishare.iask.sina.com.cn/f/6667035.html</a></div><div style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; line-height: 21px; background-color: rgb(255, 255, 255);">呃..,看了一看,发现函数名啊什么的跟我用的OpenCV2.4.5都已经不一样了啊,尝试写代码都不知怎么下手啊</div><div style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; line-height: 21px; background-color: rgb(255, 255, 255);">打开OpenCV China网站翻译的中文手册(<a href="http://www.opencv.org.cn/" style="color: rgb(0, 68, 153); text-decoration: none;">http://www.opencv.org.cn</a>),呃…,一样的,是OpenCV1.x的文档。最新的也只是OpenCV2.3.2,而且只翻译了很少一部分(2013-06-11)。对我这新手来说1.x文档没用(我装的是最新版本的2.4.5),2.3.2的文档还是能帮助熟悉OpenCV的。</div><div style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; line-height: 21px; background-color: rgb(255, 255, 255);">好吧,先把2.3.x中文部分的看了,然后有需要的就自己用dict.cn慢慢啃官方最新的OpenCV2.4.5的英文文档吧</div><div style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; line-height: 21px; background-color: rgb(255, 255, 255);">学习资料:</div><blockquote style="margin: 10px 0px; padding: 10px; border: 1px dashed rgb(221, 221, 221); background-color: rgb(250, 250, 250); color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; line-height: 21px;"><div>OpenCV2.3.2文档(部分有中文翻译)<a href="http://www.opencv.org.cn/opencvdoc/2.3.2/html/index.html" style="color: rgb(0, 68, 153); text-decoration: none;">http://www.opencv.org.cn/opencvdoc/2.3.2/html/index.html</a></div><div>官方OpenCV2.4.5文档 <a href="http://docs.opencv.org/" style="color: rgb(0, 68, 153); text-decoration: none;">http://docs.opencv.org/</a> (OpenCV 2.4.5.0 documentation)</div></blockquote><div style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; line-height: 21px; background-color: rgb(255, 255, 255);">学习资料:</div><div style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; line-height: 21px; background-color: rgb(255, 255, 255);">core模块. 核心功能 : <a href="http://www.opencv.org.cn/opencvdoc/2.3.2/html/doc/tutorials/core/mat%20-%20the%20basic%20image%20container/mat%20-%20the%20basic%20image%20container.html#" style="color: rgb(0, 68, 153); text-decoration: none;">http://www.opencv.org.cn/opencvdoc/2.3.2/html/doc/tutorials/core/mat%20-%20the%20basic%20image%20container/mat%20-%20the%20basic%20image%20container.html#</a></div><div style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; line-height: 21px; background-color: rgb(255, 255, 255);">core module. The Core Functionality : <a href="http://docs.opencv.org/doc/tutorials/core/table_of_content_core/table_of_content_core.html#table-of-content-core" style="color: rgb(0, 68, 153); text-decoration: none;">http://docs.opencv.org/doc/tutorials/core/table_of_content_core/table_of_content_core.html#table-of-content-core</a></div><div style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; line-height: 21px; background-color: rgb(255, 255, 255);"><b style="font-weight: 600;">图像在OpenCV里存在的形式</b></div><blockquote style="margin: 10px 0px; padding: 10px; border: 1px dashed rgb(221, 221, 221); background-color: rgb(250, 250, 250); color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; line-height: 21px;"><p style="margin: 0px; padding: 5px 0px 0px; line-height: 22px;">一副数字图像是由若干像素组成,若干像素的颜色值就形成了一个数值矩阵</p></blockquote><blockquote style="margin: 10px 0px; padding: 10px; border: 1px dashed rgb(221, 221, 221); background-color: rgb(250, 250, 250); color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; line-height: 21px;"><p style="margin: 0px; padding: 5px 0px 0px; line-height: 22px;">OpenCV 其主要目的就是通过处理和操作这些数值矩阵,来获取更高级的信息。因此,OpenCV如何存储并操作图像是首先要学习的。</p></blockquote><div style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; line-height: 21px; background-color: rgb(255, 255, 255);"><b style="font-weight: 600;">Mat</b> - 通用的矩阵类(基本图像容器)</div><blockquote style="margin: 10px 0px; padding: 10px; border: 1px dashed rgb(221, 221, 221); background-color: rgb(250, 250, 250); color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; line-height: 21px;"><p style="margin: 0px; padding: 5px 0px 0px; line-height: 22px;"> 基本上讲 Mat 是一个类,由两个数据部分组成:</p></blockquote><blockquote style="margin: 10px 0px; padding: 10px; border: 1px dashed rgb(221, 221, 221); background-color: rgb(250, 250, 250); color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; line-height: 21px;"><blockquote style="margin: 10px 0px; padding: 10px; border: 1px dashed rgb(221, 221, 221);"><div>一个矩阵信息头(包含矩阵尺寸,存储方法,存储地址等信息)</div><div>一个指向存储所有像素值的矩阵(根据所选存储方法的不同矩阵可以是不同的维数)的指针。</div></blockquote></blockquote><blockquote style="margin: 10px 0px; padding: 10px; border: 1px dashed rgb(221, 221, 221); background-color: rgb(250, 250, 250); color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; line-height: 21px;"><div>OpenCV函数中输出矩阵的内存分配是自动完成的(如果不特别指定的话)。</div><div>使用OpenCV的C++接口时不需要考虑内存释放问题。</div><div>赋值运算符和拷贝构造函数( ctor )只拷贝信息头和矩阵指针 ,而不拷贝矩阵。</div><div>使用函数 clone() 或者 copyTo() 来拷贝矩阵本身(而不只是信息头和矩阵指针)。</div></blockquote><p style="margin: 0px; padding: 5px 0px; line-height: 22px; color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; background-color: rgb(255, 255, 255);">存储图像方法</p><blockquote style="margin: 10px 0px; padding: 10px; border: 1px dashed rgb(221, 221, 221); background-color: rgb(250, 250, 250); color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; line-height: 21px;"><div>存储像素值,需要指定颜色空间和数据类型</div><div>颜色空间:灰度级(黑白),彩色(RGB,HSV,HLS,YCrCb,CIE L*a*b)</div><div>数据类型:char(单字节)、float(4字节,32位)、double(8字节,64位)</div></blockquote><p style="margin: 0px; padding: 5px 0px; line-height: 22px; color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; background-color: rgb(255, 255, 255);">创建一个 Mat 对象</p><blockquote style="margin: 10px 0px; padding: 10px; border: 1px dashed rgb(221, 221, 221); background-color: rgb(250, 250, 250); color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; line-height: 21px;"><div>Mat() 构造函数</div><div>Create() function: 函数</div><div>MATLAB形式的初始化方式: zeros(), ones(), :eyes()</div><div>randu() 来对一个矩阵使用随机数填充,需要指定随机数的上界和下界:</div></blockquote><p style="margin: 0px; padding: 5px 0px; line-height: 22px; color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; background-color: rgb(255, 255, 255);">显示 Mat 对象</p><blockquote style="margin: 10px 0px; padding: 10px; border: 1px dashed rgb(221, 221, 221); background-color: rgb(250, 250, 250); color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; line-height: 21px;"><div>为了debug,我们会希望看到矩阵的实际值。为此,可以通过 Mat 的运算符 << 来实现,但这只对二维矩阵有效。</div></blockquote><p style="margin: 0px; padding: 5px 0px; line-height: 22px; color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; background-color: rgb(255, 255, 255);">基本看懂了,准备在Python里试试创建一个矩阵(Mat)对象。呃..,cv2.?没有 Mat 方法啊</p><div style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', Tahoma, Arial; font-size: 14px; line-height: 21px; background-color: rgb(255, 255, 255);">去手册找找,看了半天还是一头雾水,不知道如何下手。直接找个示例代码看看,发现edge.py比较简洁有用,适合入门研究。
<p style="margin: 0px; padding: 5px 0px; line-height: 22px;"></p><div>示例程序 :edge.py ,</div><p style="margin: 0px; padding: 5px 0px; line-height: 22px;"></p><div style="text-align: left; box-sizing: border-box; overflow: hidden !important; position: relative !important; direction: ltr !important; width: 626px; padding: 0px; margin: 10px 0px; font-family: Monaco, MonacoRegular, 'Courier New', monospace; border: 1px solid rgb(153, 153, 153) !important; text-shadow: none !important; background-color: rgb(253, 253, 253) !important; float: none; clear: both; font-size: 12px !important; line-height: 15px !important; height: auto;"><div style="border: 0px; padding: 0px; margin: 0px; width: 624px; overflow: hidden; max-height: 500px; position: relative; z-index: 1; background-position: 0px 50%;"><table style="border: none !important; padding: 0px !important; margin: 0px 0px 0px -25px !important; background-image: none !important; width: auto !important; border-spacing: 0px !important; border-collapse: collapse !important;"><tbody><tr style="padding: 0px !important; border: none !important; vertical-align: top !important; margin: 0px !important; background-position: 0px 50%;"><td style="vertical-align: top !important; border: 0px; padding: 0px !important; margin: 0px !important; background-color: rgb(223, 239, 255) !important; color: rgb(84, 153, 222) !important;"><div style="border: 0px; padding: 0px; margin: 0px; background-position: 0px 50%;"><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">1</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">2</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">3</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">4</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">5</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">6</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">7</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">8</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">9</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">10</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">11</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">12</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">13</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">14</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">15</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">16</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">17</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">18</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">19</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">20</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">21</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">22</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">23</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">24</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">25</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">26</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">27</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">28</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">29</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">30</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">31</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">32</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">33</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">34</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">35</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">36</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">37</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">38</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">39</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">40</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">41</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">42</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">43</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">44</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">45</div></div></td><td style="vertical-align: top !important; border: 0px; padding: 0px !important; margin: 0px !important; width: 625px; background-position: 0px 50%;"><div style="background-image: none !important; border: none !important; padding: 0px; margin: 0px; color: rgb(0, 0, 0); white-space: pre; overflow: visible;"><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(255, 128, 0) !important;">#/usr/bin/env python</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"> </div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">'''</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">This sample demonstrates Canny edge detection.</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"> </div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">Usage:</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">edge.py [</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"> </div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">Trackbars control edge thresholds.</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"> </div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">'''</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"> </div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">import</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">cv2</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">import</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">video</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">import</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">sys</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"> </div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">if</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">__name__</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">==</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">'__main__'</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">:</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">print</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">__doc__</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"> </div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">try</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">:</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">fn</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">=</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">sys</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">argv</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">[</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(206, 0, 0) !important;">1</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">]</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">except</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">:</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">fn</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">=</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(206, 0, 0) !important;">0</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"> </div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">def</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">nothing</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">*</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important;">arg</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">:</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">pass</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"> </div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">namedWindow</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">'edge'</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">createTrackbar</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">'thrs1'</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">'edge'</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(206, 0, 0) !important;">2000</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(206, 0, 0) !important;">5000</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important;">nothing</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">createTrackbar</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">'thrs2'</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">'edge'</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(206, 0, 0) !important;">4000</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(206, 0, 0) !important;">5000</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important;">nothing</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"> </div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cap</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">=</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">video</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">create_capture</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important;">fn</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">while</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">True</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">:</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important;">flag</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">img</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">=</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cap</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">read</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">gray</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">=</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">cvtColor</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important;">img</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important;">COLOR_BGR2GRAY</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">thrs1</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">=</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">getTrackbarPos</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">'thrs1'</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">'edge'</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">thrs2</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">=</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">getTrackbarPos</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">'thrs2'</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">'edge'</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">edge</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">=</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">Canny</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important;">gray</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important;">thrs1</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important;">thrs2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">apertureSize</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">=</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(206, 0, 0) !important;">5</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">vis</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">=</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">img</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">copy</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important;">vis</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">/=</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(206, 0, 0) !important;">2</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">vis</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">[</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important;">edge</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">!=</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(206, 0, 0) !important;">0</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">]</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">=</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(206, 0, 0) !important;">0</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(206, 0, 0) !important;">255</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(206, 0, 0) !important;">0</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">imshow</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">'edge'</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important;">vis</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">ch</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">=</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">waitKey</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(206, 0, 0) !important;">5</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">if</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">ch</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">==</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(206, 0, 0) !important;">27</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">:</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">break</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cap</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">release</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">destroyAllWindows</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div></div></td></tr></tbody></table></div></div><p style="margin: 0px; padding: 5px 0px; line-height: 22px;"> </p><div>以下是代码里(调用的一些功能语句)</div><div>import cv2</div><div>import video</div><div>import sys</div><div>sys.argv</div><blockquote style="margin: 10px 0px; padding: 10px; border: 1px dashed rgb(221, 221, 221); background-color: rgb(250, 250, 250); background-position: initial initial; background-repeat: initial initial;"><p style="margin: 0px; padding: 5px 0px 0px; line-height: 22px;">一般的,argv 是命令行传入的参数。在这里是?</p></blockquote><p style="margin: 0px; padding: 5px 0px; line-height: 22px;">cv2.nameWindow</p><div>cv2.createTrackbar</div><div>cv2.getTrackbarPos</div><div>cv2.cvtColor</div><div>cv2.Canny</div><div>cv2.imshow</div><div>cv2.waitKey</div><div>cv2.destroyAllWindows</div><div>cap=video.create_capture()</div><div>cap.read()</div><div>img.copy</div><div>查手册,哦,发现这些都属于OpenCV API 的使用(XD 真是小白啊),这下知道从哪里查询cv2提供的所有方法函数了,OpenCV API Reference : <a href="http://docs.opencv.org/modules/refman.html" style="color: rgb(0, 68, 153); text-decoration: none;">http://docs.opencv.org/modules/refman.html</a></div><div>虽然还是没搞定 Mat,不过那不重要了,从这里入手,学习如何处理图像,自然后面就知道了</div><div>学着写个代码试试:显示摄像头画面</div><p style="margin: 0px; padding: 5px 0px; line-height: 22px;"></p><div style="text-align: left; box-sizing: border-box; overflow: hidden !important; position: relative !important; direction: ltr !important; width: 626px; padding: 0px; margin: 10px 0px; font-family: Monaco, MonacoRegular, 'Courier New', monospace; border: 1px solid rgb(153, 153, 153) !important; text-shadow: none !important; background-color: rgb(253, 253, 253) !important; float: none; clear: both; font-size: 12px !important; line-height: 15px !important; height: auto;"><div style="border: 0px; padding: 0px; margin: 0px; width: 624px; overflow: hidden; max-height: 500px; position: relative; z-index: 1; background-position: 0px 50%;"><table style="border: none !important; padding: 0px !important; margin: 0px 0px 0px -25px !important; background-image: none !important; width: auto !important; border-spacing: 0px !important; border-collapse: collapse !important;"><tbody><tr style="padding: 0px !important; border: none !important; vertical-align: top !important; margin: 0px !important; background-position: 0px 50%;"><td style="vertical-align: top !important; border: 0px; padding: 0px !important; margin: 0px !important; background-color: rgb(223, 239, 255) !important; color: rgb(84, 153, 222) !important;"><div style="border: 0px; padding: 0px; margin: 0px; background-position: 0px 50%;"><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">1</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">2</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">3</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">4</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">5</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">6</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">7</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">8</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">9</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">10</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">11</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">12</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">13</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">14</div></div></td><td style="vertical-align: top !important; border: 0px; padding: 0px !important; margin: 0px !important; width: 625px; background-position: 0px 50%;"><div style="background-image: none !important; border: none !important; padding: 0px; margin: 0px; color: rgb(0, 0, 0); white-space: pre; overflow: visible;"><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">import</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">cv2</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">import</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">video</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"> </div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cap</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">=</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">video</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">create_capture</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">namedWindow</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">"camera"</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"> </div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">while</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">True</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">:</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">img</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">=</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cap</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">read</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">imshow</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">"camera"</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important;">img</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">ch</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">=</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">waitKey</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(206, 0, 0) !important;">5</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">if</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">ch</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">==</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(206, 0, 0) !important;">27</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">:</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">break</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cap</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">release</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important;">destroyAllWindows</span></div></div></td></tr></tbody></table></div></div><p style="margin: 0px; padding: 5px 0px; line-height: 22px;"></p><div>出现错误:</div><blockquote style="margin: 10px 0px; padding: 10px; border: 1px dashed rgb(221, 221, 221); background-color: rgb(250, 250, 250); background-position: initial initial; background-repeat: initial initial;"><p style="margin: 0px; padding: 5px 0px 0px; line-height: 22px;">import video</p></blockquote><blockquote style="margin: 10px 0px; padding: 10px; border: 1px dashed rgb(221, 221, 221); background-color: rgb(250, 250, 250); background-position: initial initial; background-repeat: initial initial;"><p style="margin: 0px; padding: 5px 0px 0px; line-height: 22px;">ImportError: No module named video</p></blockquote><div>原来video不是基本库,查看video.py源代码,改为:</div><p style="margin: 0px; padding: 5px 0px; line-height: 22px;"></p><div style="text-align: left; box-sizing: border-box; overflow: hidden !important; position: relative !important; direction: ltr !important; width: 626px; padding: 0px; margin: 10px 0px; font-family: Monaco, MonacoRegular, 'Courier New', monospace; border: 1px solid rgb(153, 153, 153) !important; text-shadow: none !important; background-color: rgb(253, 253, 253) !important; float: none; clear: both; font-size: 12px !important; line-height: 15px !important; height: auto;"><div style="border: 0px; padding: 0px; margin: 0px; width: 624px; overflow: hidden; max-height: 500px; position: relative; z-index: 1; background-position: 0px 50%;"><table style="border: none !important; padding: 0px !important; margin: 0px 0px 0px -25px !important; background-image: none !important; width: auto !important; border-spacing: 0px !important; border-collapse: collapse !important;"><tbody><tr style="padding: 0px !important; border: none !important; vertical-align: top !important; margin: 0px !important; background-position: 0px 50%;"><td style="vertical-align: top !important; border: 0px; padding: 0px !important; margin: 0px !important; background-color: rgb(223, 239, 255) !important; color: rgb(84, 153, 222) !important;"><div style="border: 0px; padding: 0px; margin: 0px; background-position: 0px 50%;"><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">1</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">2</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">3</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">4</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">5</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">6</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">7</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">8</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">9</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">10</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">11</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">12</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">13</div></div></td><td style="vertical-align: top !important; border: 0px; padding: 0px !important; margin: 0px !important; width: 625px; background-position: 0px 50%;"><div style="background-image: none !important; border: none !important; padding: 0px; margin: 0px; color: rgb(0, 0, 0); white-space: pre; overflow: visible;"><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">import</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">cv2</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"> </div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cap</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">=</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">VideoCapture</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">namedWindow</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">"camera"</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"> </div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">while</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">True</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">:</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">img</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">=</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cap</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">read</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">imshow</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">"camera"</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important;">img</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">ch</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">=</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">waitKey</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(206, 0, 0) !important;">5</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">if</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">ch</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">==</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(206, 0, 0) !important;">27</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">:</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">break</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cap</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">release</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important;">destroyAllWindows</span></div></div></td></tr></tbody></table></div></div><p style="margin: 0px; padding: 5px 0px; line-height: 22px;"></p><div>错误:</div><div> cv2.imshow(“camera”,img)</div><div>TypeError: mat is not a numerical tuple</div><div>数据结构不对,直接用cv2试了半天还是不行,复制video.py,import video,用img=video.read()也还是不行,同样的错误</div><div>再看edge.py的代码,算是终于看明白这一句:flag, img = cap.read()</div><div>.read()返回两个数据,retval(应该是return value)是一个返回值,image是返回的图像。所以代码里的flag是用来存储函数返回值的变量,然后才是img保存返回的图像。</div><div>如果只用一个变量来存储.read()的返回值,就是retval+image两种数据,所以无法图片,提示数据类型错误。不过也从侧面看出Python语言的方便性。</div><div>以下是完整OK的代码,其它的一些错误也纠正了,并添加了注释</div><p style="margin: 0px; padding: 5px 0px; line-height: 22px;"></p><div style="text-align: left; box-sizing: border-box; overflow: hidden !important; position: relative !important; direction: ltr !important; width: 626px; padding: 0px; margin: 10px 0px; font-family: Monaco, MonacoRegular, 'Courier New', monospace; border: 1px solid rgb(153, 153, 153) !important; text-shadow: none !important; background-color: rgb(253, 253, 253) !important; float: none; clear: both; font-size: 12px !important; line-height: 15px !important; height: auto;"><div style="border: 0px; padding: 0px; margin: 0px; width: 624px; overflow: hidden; max-height: 500px; position: relative; z-index: 1; background-position: 0px 50%;"><table style="border: none !important; padding: 0px !important; margin: 0px 0px 0px -25px !important; background-image: none !important; width: auto !important; border-spacing: 0px !important; border-collapse: collapse !important;"><tbody><tr style="padding: 0px !important; border: none !important; vertical-align: top !important; margin: 0px !important; background-position: 0px 50%;"><td style="vertical-align: top !important; border: 0px; padding: 0px !important; margin: 0px !important; background-color: rgb(223, 239, 255) !important; color: rgb(84, 153, 222) !important;"><div style="border: 0px; padding: 0px; margin: 0px; background-position: 0px 50%;"><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">1</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">2</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">3</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">4</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">5</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">6</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">7</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">8</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">9</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">10</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">11</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">12</div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;">13</div><div style="font-family: inherit; background-color: rgb(200, 225, 250) !important; border: 0px; padding: 0px 5px; margin: 0px; text-align: center; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(49, 124, 197) !important;">14</div></div></td><td style="vertical-align: top !important; border: 0px; padding: 0px !important; margin: 0px !important; width: 625px; background-position: 0px 50%;"><div style="background-image: none !important; border: none !important; padding: 0px; margin: 0px; color: rgb(0, 0, 0); white-space: pre; overflow: visible;"><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">import</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">cv2</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"> </div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cap</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">=</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">VideoCapture</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(206, 0, 0) !important;">0</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(255, 128, 0) !important;">#create a video capture object. ID=0 is default camera</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">namedWindow</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">"camera"</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(255, 128, 0) !important;">#create a window object</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">while</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">True</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">:</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(255, 128, 0) !important;">#loop to get video frame</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">if</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">not</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cap</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">isOpened</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">:</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(255, 128, 0) !important;">#check camera</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">print</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">'camera not opened'</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">break</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important;">flag</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">img</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">=</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cap</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">read</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(255, 128, 0) !important;">#get video frame</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">imshow</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 128, 0) !important;">"camera"</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">,</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important;">img</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(255, 128, 0) !important;">#show the video frame</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">if</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">waitKey</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(206, 0, 0) !important;">5</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">==</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(206, 0, 0) !important;">27</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 111, 224) !important;">:</span> <span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(255, 128, 0) !important;">#press Esc key to quit</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(128, 0, 128) !important;">break</span></div><div style="font-family: inherit; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important; background-position: 0px 50%;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cap</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">release</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div><div style="font-family: inherit; background-color: rgb(247, 247, 247) !important; border: 0px; padding: 0px 5px; margin: 0px; font-size: inherit !important; line-height: inherit !important; height: inherit !important;"><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 45, 122) !important;">cv2</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">.</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(0, 78, 208) !important;">destroyAllWindows</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">(</span><span style="font-family: inherit; font-size: inherit !important; line-height: inherit !important; height: inherit !important; color: rgb(51, 51, 51) !important;">)</span></div></div></td></tr></tbody></table></div></div><p style="margin: 0px; padding: 5px 0px; line-height: 22px;"></p><div>发现这段程序显示的图像是左右翻着的,也就是我抬左手,视频上显示的是右边的手。那么就需要对读取的图像进行一次左右镜像的处理。</div><div>通过搜索发现可以使用cv2.flip()实现此功能。</div><div>cv2.flip()语法参考(<a href="http://docs.opencv.org/modules/core/doc/operations_on_arrays.html#cv2.flip" style="color: rgb(0, 68, 153); text-decoration: none;">http://docs.opencv.org/modules/core/doc/operations_on_arrays.html#cv2.flip</a>)</div><div>cv2.flip(src, flipCode[, dst]) → dst</div><blockquote style="margin: 10px 0px; padding: 10px; border: 1px dashed rgb(221, 221, 221); background-color: rgb(250, 250, 250); background-position: initial initial; background-repeat: initial initial;"><p style="margin: 0px; padding: 5px 0px 0px; line-height: 22px;">flip()的说明是,在水平方向或垂直方向或者两个轴向翻转一个二维数组。</p></blockquote><blockquote style="margin: 10px 0px; padding: 10px; border: 1px dashed rgb(221, 221, 221); background-color: rgb(250, 250, 250); background-position: initial initial; background-repeat: initial initial;"><p style="margin: 0px; padding: 5px 0px 0px; line-height: 22px;">flipcode:0 x轴镜像,即图像上下翻转。 1 y轴镜像,即图像左右翻转。-1 x轴+y轴镜像,即垂直翻转且水平翻转。</p></blockquote><div>只要添加一行代码就OK:</div><blockquote style="margin: 10px 0px; padding: 10px; border: 1px dashed rgb(221, 221, 221); background-color: rgb(250, 250, 250); background-position: initial initial; background-repeat: initial initial;"><div>img=cv2.flip(img,1) #flip image around horizontal</div></blockquote><div>完成这个程序,开始找到点摸索学习的门道了</div></div><br></div>
</div></body></html>