-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsmpOpenCV.html
More file actions
353 lines (321 loc) · 49.5 KB
/
smpOpenCV.html
File metadata and controls
353 lines (321 loc) · 49.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>教你在树莓派上安装OpenCV | Ran</title><meta name="keywords" content="树莓派"><meta name="author" content="Ran"><meta name="copyright" content="Ran"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><meta name="description" content="安装前提1.配置好树莓派的Raspbian操作系统本教程使用的系统是2018年6月27日树莓派官方发布的Raspbian-stretch操作系统,官方下载链接。 2.切换到国内的apt-get下载源和pip下载源防止下载速度过慢。 3.如果你有树莓派官方的摄像头Picamera,需按如下方法正确配置 如果没有官方摄像头,也不影响安装 在命令行输入以下命令,这个命令的意思是用nano编辑器打开m">
<meta property="og:type" content="article">
<meta property="og:title" content="教你在树莓派上安装OpenCV">
<meta property="og:url" content="https://www.ranas.cn/smpOpenCV.html">
<meta property="og:site_name" content="Ran">
<meta property="og:description" content="安装前提1.配置好树莓派的Raspbian操作系统本教程使用的系统是2018年6月27日树莓派官方发布的Raspbian-stretch操作系统,官方下载链接。 2.切换到国内的apt-get下载源和pip下载源防止下载速度过慢。 3.如果你有树莓派官方的摄像头Picamera,需按如下方法正确配置 如果没有官方摄像头,也不影响安装 在命令行输入以下命令,这个命令的意思是用nano编辑器打开m">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://www.ranas.cn/img/defaultcover.jpg">
<meta property="article:published_time" content="2020-03-07T16:01:16.000Z">
<meta property="article:modified_time" content="2020-12-02T16:10:14.562Z">
<meta property="article:author" content="Ran">
<meta property="article:tag" content="树莓派">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://www.ranas.cn/img/defaultcover.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://www.ranas.cn/smpOpenCV"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="preconnect" href="//zz.bdstatic.com"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css"><script>var GLOBAL_CONFIG = {
root: '/',
algolia: undefined,
localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容:${query}"}},
translate: undefined,
noticeOutdate: undefined,
highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
copy: {
success: '复制成功',
error: '复制错误',
noSupport: '浏览器不支持'
},
relativeDate: {
homepage: false,
post: false
},
runtime: '天',
date_suffix: {
just: '刚刚',
min: '分钟前',
hour: '小时前',
day: '天前',
month: '个月前'
},
copyright: undefined,
ClickShowText: undefined,
lightbox: 'mediumZoom',
Snackbar: undefined,
justifiedGallery: {
js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
},
isPhotoFigcaption: false,
islazyload: true,
isanchor: false
};
var saveToLocal = {
set: function setWithExpiry(key, value, ttl) {
const now = new Date()
const expiryDay = ttl * 86400000
const item = {
value: value,
expiry: now.getTime() + expiryDay,
}
localStorage.setItem(key, JSON.stringify(item))
},
get: function getWithExpiry(key) {
const itemStr = localStorage.getItem(key)
if (!itemStr) {
return undefined
}
const item = JSON.parse(itemStr)
const now = new Date()
if (now.getTime() > item.expiry) {
localStorage.removeItem(key)
return undefined
}
return item.value
}
}</script><script id="config_change">var GLOBAL_CONFIG_SITE = {
isPost: true,
isHome: false,
isHighlightShrink: false,
isToc: true,
postUpdate: '2020-12-03 00:10:14'
}</script><noscript><style type="text/css">
#nav {
opacity: 1
}
.justified-gallery img {
opacity: 1
}
#recent-posts time,
#post-meta time {
display: inline !important
}
</style></noscript><script>(function () { window.activateDarkMode = function () {
document.documentElement.setAttribute('data-theme', 'dark')
if (document.querySelector('meta[name="theme-color"]') !== null) {
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
}
}
window.activateLightMode = function () {
document.documentElement.setAttribute('data-theme', 'light')
if (document.querySelector('meta[name="theme-color"]') !== null) {
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
}
}
const autoChangeMode = 'false'
const t = saveToLocal.get('theme')
if (autoChangeMode === '1') {
const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified
if (t === undefined) {
if (isLightMode) activateLightMode()
else if (isDarkMode) activateDarkMode()
else if (isNotSpecified || hasNoSupport) {
const now = new Date()
const hour = now.getHours()
const isNight = hour <= 6 || hour >= 18
isNight ? activateDarkMode() : activateLightMode()
}
window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
if (saveToLocal.get('theme') === undefined) {
e.matches ? activateDarkMode() : activateLightMode()
}
})
} else if (t === 'light') activateLightMode()
else activateDarkMode()
} else if (autoChangeMode === '2') {
const now = new Date()
const hour = now.getHours()
const isNight = hour <= 6 || hour >= 18
if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
else if (t === 'light') activateLightMode()
else activateDarkMode()
} else {
if (t === 'dark') activateDarkMode()
else if (t === 'light') activateLightMode()
}const asideStatus = saveToLocal.get('aside-status')
if (asideStatus !== undefined) {
if (asideStatus === 'hide') {
document.documentElement.classList.add('hide-aside')
} else {
document.documentElement.classList.remove('hide-aside')
}
}})()</script><meta name="generator" content="Hexo 5.2.0"><link rel="alternate" href="/atom.xml" title="Ran" type="application/atom+xml">
</head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">稍等片刻</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" data-lazy-src="/img/tx.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">14</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">9</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">6</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 文章</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/messageboard/"><i class="fa-fw fa-fw fas fa-comment-dots"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" target="_blank" rel="noopener" href="https://w.ranas.cn"><i class="fa-fw fa-fw fas fa-cubes"></i><span> WordPress站点</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url(/img/defaultcover.jpg)"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">Ran</a></span><span id="menus"><div id="search_button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 文章</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/messageboard/"><i class="fa-fw fa-fw fas fa-comment-dots"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" target="_blank" rel="noopener" href="https://w.ranas.cn"><i class="fa-fw fa-fw fas fa-cubes"></i><span> WordPress站点</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><span class="close" id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></span></span></nav><div id="post-info"><h1 class="post-title">教你在树莓派上安装OpenCV</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2020-03-07T16:01:16.000Z" title="发表于 2020-03-08 00:01:16">2020-03-08</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2020-12-02T16:10:14.562Z" title="更新于 2020-12-03 00:10:14">2020-12-03</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%BC%80%E5%8F%91/">开发</a></span></div><div class="meta-secondline"> <span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="安装前提"><a href="#安装前提" class="headerlink" title="安装前提"></a>安装前提</h1><h3 id="1-配置好树莓派的Raspbian操作系统"><a href="#1-配置好树莓派的Raspbian操作系统" class="headerlink" title="1.配置好树莓派的Raspbian操作系统"></a>1.配置好树莓派的Raspbian操作系统</h3><p>本教程使用的系统是2018年6月27日树莓派官方发布的Raspbian-stretch操作系统,<a target="_blank" rel="noopener" href="https://www.raspberrypi.org/downloads/raspbian/">官方下载链接</a>。</p>
<h3 id="2-切换到国内的apt-get下载源和pip下载源"><a href="#2-切换到国内的apt-get下载源和pip下载源" class="headerlink" title="2.切换到国内的apt-get下载源和pip下载源"></a>2.切换到国内的apt-get下载源和pip下载源</h3><p>防止下载速度过慢。</p>
<h3 id="3-如果你有树莓派官方的摄像头Picamera,需按如下方法正确配置"><a href="#3-如果你有树莓派官方的摄像头Picamera,需按如下方法正确配置" class="headerlink" title="3.如果你有树莓派官方的摄像头Picamera,需按如下方法正确配置"></a>3.如果你有树莓派官方的摄像头Picamera,需按如下方法正确配置</h3><blockquote>
<p>如果没有官方摄像头,也不影响安装</p>
</blockquote>
<p><img src= "/img/loading.gif" data-lazy-src="https://upload-images.jianshu.io/upload_images/13714448-4b420067401c12f1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/400" alt="连接树莓派摄像头Picamera"></p>
<p>在命令行输入以下命令,这个命令的意思是用nano编辑器打开modules这个文件:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo nano /etc/modules</span><br></pre></td></tr></table></figure>
<p>在这个文件末尾添加一行</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">bcm2835-v4l2</span><br></pre></td></tr></table></figure>
<p>也就是这个效果</p>
<p><img src= "/img/loading.gif" data-lazy-src="https://upload-images.jianshu.io/upload_images/13714448-364a600885dd8cdf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240"></p>
<p>先按键盘上的<code>ctrl</code>+<code>o</code>,再按回车保存,再按<code>ctrl</code>+<code>x</code>退出nano编辑器回到命令行界面。</p>
<p>输入命令</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vcgencmd get_camera</span><br></pre></td></tr></table></figure>
<p>如果得到下面的结果,则证明摄像头连接成功</p>
<p><img src= "/img/loading.gif" data-lazy-src="https://upload-images.jianshu.io/upload_images/13714448-07e411efaac25994.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="检查摄像头是否被树莓派识别"></p>
<p>可以输入命令</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">raspistill -o image.jpg</span><br></pre></td></tr></table></figure>
<p>调用摄像头拍一张照片,命名为image.jpg,存储在/pi/home路径,也就是桌面左上角资源管理器一打开显示的那个路径。如果能看到摄像头上红灯亮,目录里面有照片,则进一步说明摄像头配置正确。</p>
<h1 id="在树莓派安装运行在Python2上的OpenCV"><a href="#在树莓派安装运行在Python2上的OpenCV" class="headerlink" title="在树莓派安装运行在Python2上的OpenCV"></a>在树莓派安装运行在Python2上的OpenCV</h1><h3 id="1、安装"><a href="#1、安装" class="headerlink" title="1、安装"></a>1、安装</h3><p> 打开树莓派的命令行界面,两个命令即可完成安装。执行第一条命令需要半个小时左右,请耐心等待。第二条命令执行只需要几秒钟。</p>
<blockquote>
<p>友情提示:</p>
<p>建议第一个命令用树莓派桌面上自带的命令行工具运行,而不要使用远程ssh连接。因为执行命令时间太长,中途如果ssh断线的话无法得知是否已经安装完毕。</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-get install libopencv-dev</span><br><span class="line">sudo apt-get install python-opencv</span><br></pre></td></tr></table></figure>
<h3 id="2、在Python2上测试OpenCV"><a href="#2、在Python2上测试OpenCV" class="headerlink" title="2、在Python2上测试OpenCV"></a>2、在Python2上测试OpenCV</h3><p>安装好之后,在命令行中输入<code>python</code>或者<code>python2</code>,回车</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> cv2</span><br></pre></td></tr></table></figure>
<p>如果出现下图的结果,说明Python2环境下的OpenCV安装成功。</p>
<p><img src= "/img/loading.gif" data-lazy-src="https://upload-images.jianshu.io/upload_images/13714448-202da54ab2900054.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="python2环境中运行opencv"></p>
<p>也可以输入</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cv2.__version__</span><br></pre></td></tr></table></figure>
<p>查看opencv版本号</p>
<p><img src= "/img/loading.gif" data-lazy-src="https://upload-images.jianshu.io/upload_images/13714448-f97eed06c60e3c03.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="查看python2的opencv版本"></p>
<blockquote>
<p>为啥叫cv2而不叫opencv呢?这是因为OpenCV是基于C/C++开发的,有两个版本,’’cv”版本的API是C语言开发的,’’cv2’’版本的API是基于C++语言开发的,为了保持向后兼容性所以叫”cv2”,但我们都知道cv2就是OpenCV本尊。</p>
</blockquote>
<p>也可以在桌面命令行里输入以下三个命令调用树莓派摄像头,把摄像头捕捉到的画面显示在桌面上,按<code>ctrl</code>+<code>c</code>键退出。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git clone https://github.com/TommyZihao/opencvtest.git</span><br><span class="line">cd opencvtest</span><br><span class="line">python2 testopencv.py</span><br></pre></td></tr></table></figure>
<p><img src= "/img/loading.gif" data-lazy-src="https://upload-images.jianshu.io/upload_images/13714448-4558d79be1004043.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="测试python2上的opencv:调用树莓派摄像头"></p>
<h1 id="在树莓派安装运行在Python3上的OpenCV"><a href="#在树莓派安装运行在Python3上的OpenCV" class="headerlink" title="在树莓派安装运行在Python3上的OpenCV"></a>在树莓派安装运行在Python3上的OpenCV</h1><h3 id="1、安装numpy"><a href="#1、安装numpy" class="headerlink" title="1、安装numpy"></a>1、安装numpy</h3><p>打开命令行界面,输入以下命令,安装Python科学计算库numpy</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo pip3 install numpy</span><br></pre></td></tr></table></figure>
<h3 id="2、在树莓派设置中把根目录扩大到整个SD卡"><a href="#2、在树莓派设置中把根目录扩大到整个SD卡" class="headerlink" title="2、在树莓派设置中把根目录扩大到整个SD卡"></a>2、在树莓派设置中把根目录扩大到整个SD卡</h3><p>命令行界面输入命令,进入树莓派配置界面。用上下键和左右键切换光标位置。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo raspi-config</span><br></pre></td></tr></table></figure>
<p><img src= "/img/loading.gif" data-lazy-src="https://upload-images.jianshu.io/upload_images/13714448-59742b839ab0c666.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="树莓派配置界面"></p>
<h4 id="第七行:Advanced-Options"><a href="#第七行:Advanced-Options" class="headerlink" title="第七行:Advanced Options"></a>第七行:Advanced Options</h4><p><img src= "/img/loading.gif" data-lazy-src="https://upload-images.jianshu.io/upload_images/13714448-1d3bb4659426dce8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Adcanved Options"></p>
<p>选择Expand Filesystem,将根目录扩展到这个SD卡,充分利用SD卡的存储空间。如果不进行这一步,后续命令会出现卡死。退出设置界面,重启树莓派。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo reboot</span><br></pre></td></tr></table></figure>
<h3 id="3、安装OpenCV所需的库"><a href="#3、安装OpenCV所需的库" class="headerlink" title="3、安装OpenCV所需的库"></a>3、安装OpenCV所需的库</h3><p>挨个运行下面八条命令。共需要七分钟(注意倒数第三条命令中要安装四个-dev软件包)。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-get install build-essential git cmake pkg-config -y</span><br><span class="line">sudo apt-get install libjpeg8-dev -y</span><br><span class="line">sudo apt-get install libtiff5-dev -y</span><br><span class="line">sudo apt-get install libjasper-dev -y</span><br><span class="line">sudo apt-get install libpng12-dev -y</span><br><span class="line"></span><br><span class="line">sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev -y</span><br><span class="line"></span><br><span class="line">sudo apt-get install libgtk2.0-dev -y</span><br><span class="line">sudo apt-get install libatlas-base-dev gfortran -y</span><br></pre></td></tr></table></figure>
<h3 id="4、下载OpenCV"><a href="#4、下载OpenCV" class="headerlink" title="4、下载OpenCV"></a>4、下载OpenCV</h3><p>在命令行输入以下三条命令,下载两个压缩包到树莓派的**/home/pi/Downloads**目录下。第一个压缩包86.8MB,第二个压缩包54.5MB:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">cd</span><br><span class="line"></span><br><span class="line">wget https://github.com/Itseez/opencv/archive/3.4.0.zip</span><br><span class="line"></span><br><span class="line">wget https://github.com/Itseez/opencv_contrib/archive/3.4.0.zip</span><br></pre></td></tr></table></figure>
<blockquote>
<p>如果下载速度很慢(比如每秒几个KB):</p>
<p>方法1:可以在电脑浏览器中输入wget后面的链接下载压缩包,再用Fillzilla或者U盘等方法把文件传输到树莓派的**/home/pi/Downloads**目录下(一定不能错)。</p>
<p>方法2::可以用电脑在<a target="_blank" rel="noopener" href="https://pan.baidu.com/s/182NYJzW1nCpnQ7ftSYYuSw">百度网盘链接</a>下载这两个压缩包之后再用Fillzilla或者U盘等方法把文件传输到树莓派的**/home/pi/Downloads**目录下(一定不能错)。</p>
</blockquote>
<p>解压这两个压缩包</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd /home/pi/Downloads</span><br><span class="line">unzip opencv-3.4.0.zip</span><br><span class="line">unzip opencv_contrib-3.4.0.zip</span><br></pre></td></tr></table></figure>
<h3 id="5、设置编译参数"><a href="#5、设置编译参数" class="headerlink" title="5、设置编译参数"></a>5、设置编译参数</h3><p>设置编译参数</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd /home/pi/Downloads/opencv-3.4.0</span><br><span class="line">mkdir build</span><br><span class="line">cd build</span><br></pre></td></tr></table></figure>
<p>设置CMAKE参数,注意,下面这是一行命令(包括最后那俩点儿),需要耐心等待十五分钟左右:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=/home/pi/Downloads/opencv_contrib-3.4.0/modules -D BUILD_EXAMPLES=ON -D WITH_LIBV4L=ON PYTHON3_EXECUTABLE=/usr/bin/python3.5 PYTHON_INCLUDE_DIR=/usr/include/python3.5 PYTHON_LIBRARY=/usr/lib/arm-linux-gnueabihf/libpython3.5m.so PYTHON3_NUMPY_INCLUDE_DIRS=/home/pi/.local/lib/python3.5/site-packages/numpy/core/include ..</span><br></pre></td></tr></table></figure>
<p>根据下图判断你是否配置成功了CMAKE。如果失败,可能是因为两个压缩包的路径没有严格按照上文的要求。如果成功,就可以开始最重要的编译了。</p>
<p><img src= "/img/loading.gif" data-lazy-src="https://upload-images.jianshu.io/upload_images/13714448-532012bb713dc869.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="CMAKE配置"></p>
<h3 id="6、编译"><a href="#6、编译" class="headerlink" title="6、编译"></a>6、编译</h3><p>最后一步,也是最重要的一步:编译</p>
<p>保证树莓派有至少5G的存储空间,建议本命令用树莓派桌面上的命令行工具运行,而不要使用远程ssh连接。因为执行命令时间太长,中途如果ssh断线的话无法得知是否已经安装完毕。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd /home/pi/Downloads/opencv-3.4.0/build</span><br><span class="line">make</span><br></pre></td></tr></table></figure>
<p><img src= "/img/loading.gif" data-lazy-src="https://upload-images.jianshu.io/upload_images/13714448-36df3d7c4c6c0db7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="开始编译"></p>
<p>编译两个小时之后,完成了40%</p>
<p><img src= "/img/loading.gif" data-lazy-src="https://upload-images.jianshu.io/upload_images/13714448-e938295662efec1e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="编译两个小时之后"></p>
<p>静待五个小时的编译。注意,在此期间,树莓派要供电充足,不要运行其它任务,以免因为内存不够什么的幺蛾子报错。</p>
<p><img src= "/img/loading.gif" data-lazy-src="https://upload-images.jianshu.io/upload_images/13714448-542b34f0f59da291.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="编译完成"></p>
<p><code>make</code>命令执行完成之后,执行下面的命令,执行命令需要一分钟:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo make insall</span><br></pre></td></tr></table></figure>
<h3 id="7、在Python3上测试OpenCV"><a href="#7、在Python3上测试OpenCV" class="headerlink" title="7、在Python3上测试OpenCV"></a>7、在Python3上测试OpenCV</h3><p>安装好之后,在命令行中输入<code>python3</code>,回车</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> cv2</span><br></pre></td></tr></table></figure>
<p>回车</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cv2.__version__</span><br></pre></td></tr></table></figure>
<p>回车</p>
<p>如果出现下图的结果,说明Python3环境下的OpenCV安装成功。</p>
<p><img src= "/img/loading.gif" data-lazy-src="https://upload-images.jianshu.io/upload_images/13714448-8b4162cec9589cd6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Python3的OpenCV安装完成"></p>
<h1 id="参考文献与扩展阅读"><a href="#参考文献与扩展阅读" class="headerlink" title="参考文献与扩展阅读"></a>参考文献与扩展阅读</h1><blockquote>
<p><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/3180a253fe3c">【树莓派】树莓派+OpenCV3.4 + python3.5 成功以及注意细节</a></p>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/u014397533/article/details/50910531">树莓派安装Python-OpenCV</a></p>
<p> <a target="_blank" rel="noopener" href="https://www.cnblogs.com/Pyrokine/p/8921285.html">基于树莓派3B+Python3.5的OpenCV3.4的配置教程</a></p>
</blockquote>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">Ran</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://www.ranas.cn/smpOpenCV.html">https://www.ranas.cn/smpOpenCV.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外,均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://www.ranas.cn" target="_blank">Ran</a>!</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E6%A0%91%E8%8E%93%E6%B4%BE/">树莓派</a></div><div class="post_share"><div class="social-share" data-image="/img/defaultcover.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏<div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/img/wechat.jpg" target="_blank"><img class="post-qr-code-img" data-lazy-src="/img/wechat.jpg" alt="wechat"/></a><div class="post-qr-code-desc">wechat</div></li><li class="reward-item"><a href="/img/alipay.jpg" target="_blank"><img class="post-qr-code-img" data-lazy-src="/img/alipay.jpg" alt="alipay"/></a><div class="post-qr-code-desc">alipay</div></li></ul></div></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/smpfm.html"><img class="prev-cover" data-lazy-src="/img/defaultcover.jpg" onerror="onerror=null;src='/img/404.jpg'"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">用树莓派搭建FM广播,播放音乐和实时语音</div></div></a></div><div class="next-post pull-right"><a href="/smpbtb.html"><img class="next-cover" data-lazy-src="/img/defaultcover.jpg" onerror="onerror=null;src='/img/404.jpg'"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">在树莓派上安装BOINC并参与SETI@home分布式计算项目</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/smpbtb.html" title="在树莓派上安装BOINC并参与SETI@home分布式计算项目"><img class="cover" data-lazy-src="/img/defaultcover.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-03-01</div><div class="title">在树莓派上安装BOINC并参与SETI@home分布式计算项目</div></div></a></div><div><a href="/smpfm.html" title="用树莓派搭建FM广播,播放音乐和实时语音"><img class="cover" data-lazy-src="/img/defaultcover.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-03-21</div><div class="title">用树莓派搭建FM广播,播放音乐和实时语音</div></div></a></div><div><a href="/smpkj.html" title="树莓派开机教程"><img class="cover" data-lazy-src="/img/defaultcover.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-03-01</div><div class="title">树莓派开机教程</div></div></a></div><div><a href="/smpset.html" title="一劳永逸配置树莓派"><img class="cover" data-lazy-src="/img/defaultcover.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-02-28</div><div class="title">一劳永逸配置树莓派</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside_content" id="aside_content"><div class="card-widget card-info"><div class="card-content"><div class="card-info-avatar is-center"><img class="avatar-img" data-lazy-src="/img/tx.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">Ran</div><div class="author-info__description">An ordinary web page based on hexo, but ordinary does not mean simple.</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">14</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">9</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">6</div></a></div></div><a class="button--animated" id="card-info-btn" href="mailto:[email protected]"><i class="fab fa-email"></i><span>我的邮箱</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://www.ranas.cn/atom.xml" target="_blank" title="rss"><i class="fas fa-rss"></i></a><a class="social-icon" href="https://wpa.qq.com/msgrd?v=3&uin=384965992&site=qq&menu=yes" target="_blank" title="QQ"><i class="fab fa-qq"></i></a></div></div></div><div class="card-widget card-announcement"><div class="card-content"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">欢迎来到Ranas,这是一个个人博客网页,如有问题可以联系我询问。</div></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="card-content"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%AE%89%E8%A3%85%E5%89%8D%E6%8F%90"><span class="toc-number">1.</span> <span class="toc-text">安装前提</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E9%85%8D%E7%BD%AE%E5%A5%BD%E6%A0%91%E8%8E%93%E6%B4%BE%E7%9A%84Raspbian%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F"><span class="toc-number">1.0.1.</span> <span class="toc-text">1.配置好树莓派的Raspbian操作系统</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E5%88%87%E6%8D%A2%E5%88%B0%E5%9B%BD%E5%86%85%E7%9A%84apt-get%E4%B8%8B%E8%BD%BD%E6%BA%90%E5%92%8Cpip%E4%B8%8B%E8%BD%BD%E6%BA%90"><span class="toc-number">1.0.2.</span> <span class="toc-text">2.切换到国内的apt-get下载源和pip下载源</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E5%A6%82%E6%9E%9C%E4%BD%A0%E6%9C%89%E6%A0%91%E8%8E%93%E6%B4%BE%E5%AE%98%E6%96%B9%E7%9A%84%E6%91%84%E5%83%8F%E5%A4%B4Picamera%EF%BC%8C%E9%9C%80%E6%8C%89%E5%A6%82%E4%B8%8B%E6%96%B9%E6%B3%95%E6%AD%A3%E7%A1%AE%E9%85%8D%E7%BD%AE"><span class="toc-number">1.0.3.</span> <span class="toc-text">3.如果你有树莓派官方的摄像头Picamera,需按如下方法正确配置</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%9C%A8%E6%A0%91%E8%8E%93%E6%B4%BE%E5%AE%89%E8%A3%85%E8%BF%90%E8%A1%8C%E5%9C%A8Python2%E4%B8%8A%E7%9A%84OpenCV"><span class="toc-number">2.</span> <span class="toc-text">在树莓派安装运行在Python2上的OpenCV</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1%E3%80%81%E5%AE%89%E8%A3%85"><span class="toc-number">2.0.1.</span> <span class="toc-text">1、安装</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2%E3%80%81%E5%9C%A8Python2%E4%B8%8A%E6%B5%8B%E8%AF%95OpenCV"><span class="toc-number">2.0.2.</span> <span class="toc-text">2、在Python2上测试OpenCV</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%9C%A8%E6%A0%91%E8%8E%93%E6%B4%BE%E5%AE%89%E8%A3%85%E8%BF%90%E8%A1%8C%E5%9C%A8Python3%E4%B8%8A%E7%9A%84OpenCV"><span class="toc-number">3.</span> <span class="toc-text">在树莓派安装运行在Python3上的OpenCV</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1%E3%80%81%E5%AE%89%E8%A3%85numpy"><span class="toc-number">3.0.1.</span> <span class="toc-text">1、安装numpy</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2%E3%80%81%E5%9C%A8%E6%A0%91%E8%8E%93%E6%B4%BE%E8%AE%BE%E7%BD%AE%E4%B8%AD%E6%8A%8A%E6%A0%B9%E7%9B%AE%E5%BD%95%E6%89%A9%E5%A4%A7%E5%88%B0%E6%95%B4%E4%B8%AASD%E5%8D%A1"><span class="toc-number">3.0.2.</span> <span class="toc-text">2、在树莓派设置中把根目录扩大到整个SD卡</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%AC%AC%E4%B8%83%E8%A1%8C%EF%BC%9AAdvanced-Options"><span class="toc-number">3.0.2.1.</span> <span class="toc-text">第七行:Advanced Options</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3%E3%80%81%E5%AE%89%E8%A3%85OpenCV%E6%89%80%E9%9C%80%E7%9A%84%E5%BA%93"><span class="toc-number">3.0.3.</span> <span class="toc-text">3、安装OpenCV所需的库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4%E3%80%81%E4%B8%8B%E8%BD%BDOpenCV"><span class="toc-number">3.0.4.</span> <span class="toc-text">4、下载OpenCV</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5%E3%80%81%E8%AE%BE%E7%BD%AE%E7%BC%96%E8%AF%91%E5%8F%82%E6%95%B0"><span class="toc-number">3.0.5.</span> <span class="toc-text">5、设置编译参数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6%E3%80%81%E7%BC%96%E8%AF%91"><span class="toc-number">3.0.6.</span> <span class="toc-text">6、编译</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#7%E3%80%81%E5%9C%A8Python3%E4%B8%8A%E6%B5%8B%E8%AF%95OpenCV"><span class="toc-number">3.0.7.</span> <span class="toc-text">7、在Python3上测试OpenCV</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE%E4%B8%8E%E6%89%A9%E5%B1%95%E9%98%85%E8%AF%BB"><span class="toc-number">4.</span> <span class="toc-text">参考文献与扩展阅读</span></a></li></ol></div></div></div><div class="card-widget card-recent-post"><div class="card-content"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/hexo-ran.html" title="hexo主题配置整合包发布"><img data-lazy-src="/img/topimg/hexo-ran.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="hexo主题配置整合包发布"/></a><div class="content"><a class="title" href="/hexo-ran.html" title="hexo主题配置整合包发布">hexo主题配置整合包发布</a><time datetime="2020-12-03T15:31:18.000Z" title="发表于 2020-12-03 23:31:18">2020-12-03</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/hexogithub.html" title="使用Hexo和Github Actions自动化博客更新"><img data-lazy-src="/img/topimg/hexoga.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="使用Hexo和Github Actions自动化博客更新"/></a><div class="content"><a class="title" href="/hexogithub.html" title="使用Hexo和Github Actions自动化博客更新">使用Hexo和Github Actions自动化博客更新</a><time datetime="2020-12-02T16:01:15.000Z" title="发表于 2020-12-03 00:01:15">2020-12-03</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/khfx.html" title="客户分析-价格段的选取"><img data-lazy-src="/img/defaultcover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="客户分析-价格段的选取"/></a><div class="content"><a class="title" href="/khfx.html" title="客户分析-价格段的选取">客户分析-价格段的选取</a><time datetime="2020-11-01T16:01:19.000Z" title="发表于 2020-11-02 00:01:19">2020-11-02</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/wpnoadmin.html" title="Wordpress后台管理员无法访问"><img data-lazy-src="/img/defaultcover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Wordpress后台管理员无法访问"/></a><div class="content"><a class="title" href="/wpnoadmin.html" title="Wordpress后台管理员无法访问">Wordpress后台管理员无法访问</a><time datetime="2020-10-31T16:01:16.000Z" title="发表于 2020-11-01 00:01:16">2020-11-01</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/wpsslerror.html" title="WordPress配置完SSL证书后台重定向过多"><img data-lazy-src="/img/topimg/wpsslerror.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="WordPress配置完SSL证书后台重定向过多"/></a><div class="content"><a class="title" href="/wpsslerror.html" title="WordPress配置完SSL证书后台重定向过多">WordPress配置完SSL证书后台重定向过多</a><time datetime="2020-10-31T16:01:15.000Z" title="发表于 2020-11-01 00:01:15">2020-11-01</time></div></div></div></div></div></div></div></main><footer id="footer" style="background-image: url(/img/defaultcover.jpg)"><div id="footer-wrap"><div class="copyright">©2018 - 2020 By Ran</div><div class="framework-info"><span>本站基于 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo 搭建</a><span class="footer-separator">|</span><span>主题由 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly 提供</a></div><div class="footer_custom_text">本站部署于中国大陆,请勿发布违反国家法律信息</div><div class="icp"><a target="_blank" rel="noopener" href="http://www.beian.miit.gov.cn/"><img class="icp-icon" src="/img/icp.png" alt="ICP"/><span>苏ICP备20005417号</span></a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"><div id="local-hits"></div><div id="local-stats"><div class="local-search-stats__hr" id="hr"><span>由</span> <a target="_blank" rel="noopener" href="https://github.com/wzpan/hexo-generator-search" style="color:#49B1F5;">hexo-generator-search</a>
<span>提供支持</span></div></div></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/medium-zoom/dist/medium-zoom.min.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="/js/search/local-search.js"></script><script>var preloader = {
endLoading: () => {
document.body.style.overflow = 'auto';
document.getElementById('loading-box').classList.add("loaded")
},
initLoading: () => {
document.body.style.overflow = '';
document.getElementById('loading-box').classList.remove("loaded")
}
}
window.addEventListener('load',()=> {preloader.endLoading()})</script><div class="js-pjax"><script>function loadValine () {
function initValine () {
let initData = {
el: '#vcomment',
appId: 'O3AJFzNUHIrvFvl5SKatWYG8-9Nh9j0Va',
appKey: '7N67EgVW766JcafR8k2CLwwF',
placeholder: 'Please leave your footprints',
avatar: 'monsterid',
meta: 'nick,mail,link'.split(','),
pageSize: '10',
lang: 'zh-CN',
recordIP: false,
serverURLs: '',
emojiCDN: '',
emojiMaps: "",
enableQQ: false,
path: window.location.pathname,
}
if (true) {
initData.requiredFields= ('nick,mail'.split(','))
}
if (false) {
const otherData = false
initData = Object.assign({}, initData, otherData)
}
const valine = new Valine(initData)
}
if (typeof Valine === 'function') initValine()
else $.getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js', initValine)
}
if ('Valine' === 'Valine' || !false) {
if (false) btf.loadComment(document.querySelector('#vcomment'),loadValine)
else setTimeout(() => loadValine(), 0)
} else {
function loadOtherComment () {
loadValine()
}
}</script><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script defer="defer" id="fluttering_ribbon" mobile="true" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = true;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="true"></script><script>(function(d, w, c) {
w.ChatraID = 'J7yHMLDRrQm9EgvcQ';
var s = d.createElement('script');
w[c] = w[c] || function() {
(w[c].q = w[c].q || []).push(arguments);
};
s.async = true;
s.src = 'https://call.chatra.io/chatra.js';
if (d.head) d.head.appendChild(s);
})(document, window, 'Chatra');
if (false) {
var chatBtnFn = () => {
var chatBtn = document.getElementById("chat_btn")
chatBtn.addEventListener("click", function(){
Chatra('openChat')
});
}
chatBtnFn()
} else {
if (false) {
function chatBtnHide () {
Chatra('hide')
}
function chatBtnShow () {
Chatra('show')
}
}
}</script><script>(function(){
const bp = document.createElement('script');
const curProtocol = window.location.protocol.split(':')[0];
if (curProtocol === 'https'){
bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
}
else{
bp.src = 'http://push.zhanzhang.baidu.com/push.js';
}
bp.dataset.pjax = ''
const s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(bp, s);
})()</script></div><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"model":{"scale":1,"hHeadPos":0.5,"vHeadPos":0.618},"display":{"superSample":2,"width":150,"height":300,"position":"left","hOffset":0,"vOffset":-20},"mobile":{"show":true,"scale":0.5},"react":{"opacityDefault":0.7,"opacityOnHover":0.2,"search":null},"path":"search.xml","field":"post","content":true,"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body></html>