-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path使用MATLAB调用摄像头并拍照—详细代码.html
782 lines (568 loc) · 29.4 KB
/
使用MATLAB调用摄像头并拍照—详细代码.html
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="keywords" content="python,matlab,yolo,yolov3,java,go,c++,c#" />
<meta name="description" content="孙全胜의Space" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>
使用MATLAB调用摄像头并拍照—详细代码 | 孙全胜의Space
</title>
<meta name="generator" content="hexo-theme-ayer">
<link rel="shortcut icon" href="/bitbug_favicon.ico" />
<link rel="stylesheet" href="/dist/main.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">
<link rel="stylesheet" href="/css/custom.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/pace.min.js"></script>
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-168079169-1', 'auto');
ga('send', 'pageview');
</script>
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?6101cdb197f4b6300cb90fa7e51accec";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
<link rel="alternate" href="/atom.xml" title="孙全胜의Space" type="application/atom+xml">
</head>
</html>
<body>
<canvas width="1777" height="841" style="position: fixed; left: 0px; top: 0px; z-index: 999; pointer-events: none;"></canvas>
<div id="app">
<main class="content on">
<section class="outer">
<article id="post-使用MATLAB调用摄像头并拍照—详细代码" class="article article-type-post" itemscope
itemprop="blogPost" data-scroll-reveal>
<div class="article-inner">
<header class="article-header">
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
使用MATLAB调用摄像头并拍照—详细代码
</h1>
</header>
<div class="article-meta">
<a href="/%E4%BD%BF%E7%94%A8MATLAB%E8%B0%83%E7%94%A8%E6%91%84%E5%83%8F%E5%A4%B4%E5%B9%B6%E6%8B%8D%E7%85%A7%E2%80%94%E8%AF%A6%E7%BB%86%E4%BB%A3%E7%A0%81.html" class="article-date">
<time datetime="2020-06-17T09:36:45.000Z" itemprop="datePublished">2020-06-17</time>
</a>
<div class="article-category">
<a class="article-category-link" href="/categories/MATLAB/">MATLAB</a>
</div>
<div class="word_count">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="ri-quill-pen-line"></i>
<span class="post-meta-item-text"> 字数统计:</span>
<span class="post-count">702</span>
</span>
</span>
<span class="post-time">
|
<span class="post-meta-item-icon">
<i class="ri-book-open-line"></i>
<span class="post-meta-item-text"> 阅读时长≈</span>
<span class="post-count">2 分钟</span>
</span>
</span>
</div>
</div>
<div class="article-entry" itemprop="articleBody">
<blockquote>
<p>大家也可以加我的交流群,所有资料我会在群里分享出来哦:977947271<br>2020/5/30:</p>
</blockquote>
<p>今天给大家介绍一下我第一次使用matlab进行摄像头拍照并进行图像处理的过程</p>
<p>下面是个简单的GUI:</p>
<p><img src="https://img-blog.csdnimg.cn/20200219115644543.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ1NTA0MTE5,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<a id="more"></a>
<p>虽然不使用GUI也可以实现这种功能,不过我建议初学者最好使用GUI来控制程序,之后有时间我会发布不使用GUI来实现这种功能的博文。</p>
<p>GUI界面的建立这里就不多说了。</p>
<p>这个GUI是由一个坐标轴和四个按钮组成,按钮分别是“打开摄像头”,“拍照并保存”,“关闭摄像头”,“图像处理”,对应代码中的pushbutton1/2/3/4。</p>
<p>目的是先打开摄像头,再拍摄照片到电脑中,最后调用图片去进行处理。</p>
<p>下面介绍代码:<br>这里是 pushbutton1 的callback</p>
<figure class="highlight python"><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><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">varargout{<span class="number">1</span>} = handles.output;</span><br><span class="line"><span class="keyword">global</span> vid</span><br><span class="line">%定义一个全局变量,<span class="keyword">global</span>的用法可以参照我的另一篇博文</span><br><span class="line">vid = videoinput(<span class="string">'winvideo'</span>,<span class="number">1</span>,<span class="string">'YUY2_640x480'</span>);</span><br><span class="line">%winvideo函数可参照另一篇文章中imaqhwinfo的用法</span><br><span class="line">set(vid,<span class="string">'FramesPerTrigger'</span>,<span class="number">1</span>);</span><br><span class="line">%用特定的帧数去显示视频</span><br><span class="line">set(vid,<span class="string">'TriggerRepeat'</span>,Inf);</span><br><span class="line">vidRes = get(vid,<span class="string">'VideoResolution'</span>);</span><br><span class="line">%二维数组,获取视频长宽</span><br><span class="line">nBands = get(ojb,<span class="string">'NumberOfBands'</span>);</span><br><span class="line">%获得图像的颜色层数</span><br><span class="line">axes(handles.axes1);</span><br><span class="line">%让视频显示在指定的axes1坐标中</span><br><span class="line"><span class="keyword">global</span> hImage</span><br><span class="line">%定义全局变量hImage</span><br><span class="line">hImage = image(zeros(vidRes(<span class="number">2</span>),vidRes(<span class="number">1</span>),nBands));</span><br><span class="line">%获得图像的句柄</span><br><span class="line">preview(vid,hImage);</span><br></pre></td></tr></table></figure>
<p>点开“打开摄像头后”在 axes1 中就可看到拍摄的画面</p>
<p>接下来介绍图片的保存:</p>
<figure class="highlight python"><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><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">global</span> vid;</span><br><span class="line">frame = getsnapshot(vid);</span><br><span class="line">%摄像头每一帧的画面</span><br><span class="line">frame = ycbcr2rgb(frame);</span><br><span class="line">%将捕获的图像转化为RGB格式的图像</span><br><span class="line">[filename,pathname] = uiputfile({<span class="string">'*.bmp'</span>,<span class="string">'BMP files'</span>:<span class="string">'*.jpg'</span>,<span class="string">'JPG files'</span>}<span class="string">'格式'</span>);</span><br><span class="line">%照片名称与储存路径</span><br><span class="line"><span class="keyword">if</span> isequal(filename,<span class="number">0</span>) || isequal(pathname,<span class="number">0</span>)</span><br><span class="line">%文件名与路径是否被占用</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line"><span class="keyword">else</span> </span><br><span class="line"> fpath = fullfile(pathname,filename);</span><br><span class="line">end</span><br><span class="line">imwrite(frame,fpath);</span><br></pre></td></tr></table></figure>
<p>其实这种操作的逻辑对于matlab 的GUI来说,都可以比较简便的解决</p>
<p>关闭摄像头:</p>
<figure class="highlight python"><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></pre></td><td class="code"><pre><span class="line">%很简单,在callback中写入一个函数即可</span><br><span class="line">close(findobj(<span class="string">'gca'</span>,<span class="string">'figure_csdn'</span>));</span><br><span class="line">%findobj(<span class="string">'PropertyName'</span>,<span class="string">'PropertyValue'</span>,...)</span><br><span class="line">返回figure的句柄</span><br></pre></td></tr></table></figure>
<p>对于想要对图像进行处理的话:</p>
<figure class="highlight python"><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></pre></td><td class="code"><pre><span class="line">%就需要在callback中写入读取上图保存的图片的代码</span><br><span class="line">x = imread(<span class="string">'name.jpg'</span>);</span><br><span class="line">imshow(x);</span><br><span class="line">%在进行相应的处理程序</span><br></pre></td></tr></table></figure>
<p>因为 gui 的代码冗长且很多地方无用,就无法将代码全部贴出来,但是对于有些基础的是可以看懂的,所有代码都放在相应的cb中进行。</p>
<p>之后会发出更复杂的定时拍照的程序 gui,希望有技术大佬可以帮助指点错误与不足。</p>
<p>如果有需要这篇文章中源码和 gui 的可以私信我。</p>
<p>欢迎大家指正不足。</p>
<!-- reward -->
</div>
<!-- copyright -->
<div class="declare">
<ul class="post-copyright">
<li>
<i class="ri-copyright-line"></i>
<strong>版权声明: </strong>
本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
</li>
</ul>
</div>
<footer class="article-footer">
<div class="share-btn">
<span class="share-sns share-outer">
<i class="ri-share-forward-line"></i>
分享
</span>
<div class="share-wrap">
<i class="arrow"></i>
<div class="share-icons">
<a class="weibo share-sns" href="javascript:;" data-type="weibo">
<i class="ri-weibo-fill"></i>
</a>
<a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
<i class="ri-wechat-fill"></i>
</a>
<a class="qq share-sns" href="javascript:;" data-type="qq">
<i class="ri-qq-fill"></i>
</a>
<a class="douban share-sns" href="javascript:;" data-type="douban">
<i class="ri-douban-line"></i>
</a>
<!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
<i class="icon icon-qzone"></i>
</a> -->
<a class="facebook share-sns" href="javascript:;" data-type="facebook">
<i class="ri-facebook-circle-fill"></i>
</a>
<a class="twitter share-sns" href="javascript:;" data-type="twitter">
<i class="ri-twitter-fill"></i>
</a>
<a class="google share-sns" href="javascript:;" data-type="google">
<i class="ri-google-fill"></i>
</a>
</div>
</div>
</div>
<div class="wx-share-modal">
<a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
<p>扫一扫,分享到微信</p>
<div class="wx-qrcode">
<img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://squansh.top/%E4%BD%BF%E7%94%A8MATLAB%E8%B0%83%E7%94%A8%E6%91%84%E5%83%8F%E5%A4%B4%E5%B9%B6%E6%8B%8D%E7%85%A7%E2%80%94%E8%AF%A6%E7%BB%86%E4%BB%A3%E7%A0%81.html" alt="微信分享二维码">
</div>
</div>
<div id="share-mask"></div>
<ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/MATLAB/" rel="tag">MATLAB</a></li></ul>
</footer>
</div>
<nav class="article-nav">
<a href="/MATLAB%20%E7%9A%84global%E5%87%BD%E6%95%B0%EF%BC%88%E5%85%A8%E5%B1%80%E5%8F%98%E9%87%8F%EF%BC%89%E2%80%94%E4%BB%8Epython%E5%92%8CMAT%E5%AE%9E%E4%BE%8B%E4%B8%AD%E8%AF%A6%E7%BB%86%E8%A7%A3%E9%87%8A.html" class="article-nav-link">
<strong class="article-nav-caption">上一篇</strong>
<div class="article-nav-title">
MATLAB 的global函数(全局变量)—从python和MAT实例中详细解释
</div>
</a>
<a href="/%E6%96%B0%E6%89%8B%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8anaconda%EF%BC%88python%EF%BC%89%E2%80%94%E7%AE%80%E5%8D%95%E4%BB%8B%E7%BB%8D.html" class="article-nav-link">
<strong class="article-nav-caption">下一篇</strong>
<div class="article-nav-title">新手如何使用anaconda(python)—简单介绍</div>
</a>
</nav>
<!-- valine评论 -->
<div id="vcomments-box">
<div id="vcomments">
</div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/Valine.min.js'></script>
<script>
new Valine({
el: '#vcomments',
app_id: 'bMSQYcOX9RQgHRwGmc2xl2iY-9Nh9j0Va',
app_key: 'fhWrk4asGBlMT45CQdjPoEx4',
path: window.location.pathname,
notify: true,
verify: true,
avatar: 'monsterid',
placeholder: '给我的文章加点评论吧~',
recordIP: true
});
const infoEle = document.querySelector('#vcomments .info');
if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
infoEle.childNodes.forEach(function (item) {
item.parentNode.removeChild(item);
});
}
</script>
<style>
#vcomments-box {
padding: 5px 30px;
}
@media screen and (max-width: 800px) {
#vcomments-box {
padding: 5px 0px;
}
}
#vcomments-box #vcomments {
background-color: #fff;
}
.v .vlist .vcard .vh {
padding-right: 20px;
}
.v .vlist .vcard {
padding-left: 10px;
}
</style>
</article>
</section>
<footer class="footer">
<div class="outer">
<ul>
<li>
<span id="timeDate">载入天数...</span><span id="times">载入时分秒...</span>
<script>
var now = new Date();
function createtime() {
var grt= new Date("06/01/2020 00:00:00");//在此处修改你的建站时间,格式:月/日/年 时:分:秒
now.setTime(now.getTime()+250);
days = (now - grt ) / 1000 / 60 / 60 / 24; dnum = Math.floor(days);
hours = (now - grt ) / 1000 / 60 / 60 - (24 * dnum); hnum = Math.floor(hours);
if(String(hnum).length ==1 ){hnum = "0" + hnum;} minutes = (now - grt ) / 1000 /60 - (24 * 60 * dnum) - (60 * hnum);
mnum = Math.floor(minutes); if(String(mnum).length ==1 ){mnum = "0" + mnum;}
seconds = (now - grt ) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum);
snum = Math.round(seconds); if(String(snum).length ==1 ){snum = "0" + snum;}
document.getElementById("timeDate").innerHTML = "本站已安全运行 "+dnum+" 天 ";
document.getElementById("times").innerHTML = hnum + " 小时 " + mnum + " 分 " + snum + " 秒";
}
setInterval("createtime()",250);
</script>
</li>
</ul>
<ul>
<li>
Copyrights ©
2020
<i class="ri-heart-fill heart_icon"></i> squansh
</li>
</ul>
<ul>
<li>
<span>
<span><i class="ri-user-3-fill"></i>访问人数:<span id="busuanzi_value_site_uv"></span></s>
<span class="division">|</span>
<span><i class="ri-eye-fill"></i>浏览次数:<span id="busuanzi_value_page_pv"></span></span>
</span>
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
</li>
</ul>
<ul>
</ul>
<ul>
<li>
<!-- cnzz统计 -->
<script type="text/javascript" src="https://s4.cnzz.com/z_stat.php?id=1278953980&web_id=1278953980"></script>
</li>
</ul>
</div>
</footer>
<div class="float_btns">
<div class="totop" id="totop">
<i class="ri-arrow-up-line"></i>
</div>
<div class="todark" id="todark">
<i class="ri-moon-line"></i>
</div>
</div>
</main>
<aside class="sidebar on">
<button class="navbar-toggle"></button>
<nav class="navbar">
<div class="logo">
<a href="/"><img src="/images/photo_side.svg" alt="孙全胜의Space"></a>
</div>
<ul class="nav nav-main">
<li class="nav-item">
<a class="nav-item-link" href="/">Home</a>
</li>
<li class="nav-item">
<a class="nav-item-link" href="/archives">Archives</a>
</li>
<li class="nav-item">
<a class="nav-item-link" href="/categories/">Categories</a>
</li>
<li class="nav-item">
<a class="nav-item-link" href="/tags">Tags</a>
</li>
<li class="nav-item">
<a class="nav-item-link" href="https://changyuqi.top/" target="_blank" rel="noopener">Sister</a>
</li>
<li class="nav-item">
<a class="nav-item-link" href="http://121.41.228.97/" target="_blank" rel="noopener">Bolo</a>
</li>
<li class="nav-item">
<a class="nav-item-link" href="https://quan_sheng_sun.gitee.io/resume" target="_blank" rel="noopener">Resume</a>
</li>
<li class="nav-item">
<a class="nav-item-link" href="https://jq.qq.com/?_wv=1027&k=KyptBBmy" target="_blank" rel="noopener">Qgroup</a>
</li>
<li class="nav-item">
<a class="nav-item-link" href="https://www.zhihu.com/people/jes331" target="_blank" rel="noopener">Zhi-h</a>
</li>
<li class="nav-item">
<a class="nav-item-link" href="https://weibo.com/5600672195" target="_blank" rel="noopener">Wei-b</a>
</li>
<li class="nav-item">
<a class="nav-item-link" href="https://blog.csdn.net/qq_45504119" target="_blank" rel="noopener">CSDN</a>
</li>
<li class="nav-item">
<a class="nav-item-link" href="mailto:[email protected]">E-mail</a>
</li>
</ul>
</nav>
<nav class="navbar navbar-bottom">
<ul class="nav">
<li class="nav-item">
<a class="nav-item-link nav-item-search" title="搜索">
<i class="ri-search-line"></i>
</a>
<a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
<i class="ri-rss-line"></i>
</a>
</li>
</ul>
</nav>
<div class="search-form-wrap">
<div class="local-search local-search-plugin">
<input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
<div id="local-search-result" class="local-search-result"></div>
</div>
</div>
<script type="text/javascript" src="//rf.revolvermaps.com/0/0/8.js?i=5uyif1eoo9j&m=0&c=ff0000&cr1=ffffff&f=arial&l=33&s=341&bv=85" async="async"></script>
</aside>
<!--浏览器搞笑标题-->
<script type="text/javascript" src="/js/FunnyTitle.js"></script>
<script>
if (window.matchMedia("(max-width: 768px)").matches) {
document.querySelector('.content').classList.remove('on');
document.querySelector('.sidebar').classList.remove('on');
}
</script>
<div id="mask"></div>
<!-- #reward -->
<div id="reward">
<span class="close"><i class="ri-close-line"></i></span>
<p class="reward-p"><i class="ri-cup-line"></i></p>
<div class="reward-box">
</div>
</div>
<script src="/js/jquery-2.0.3.min.js"></script>
<script src="/js/lazyload.min.js"></script>
<!-- Subtitle -->
<script>
try {
var typed = new Typed("#subtitle", {
strings: ['夜深了', '是否明天会悄然忘记', '夜却深了'],
startDelay: 0,
typeSpeed: 400,
loop: true,
backSpeed: 150,
showCursor: true
});
} catch (err) {
console.log(err)
}
</script>
<!-- Tocbot -->
<script src="/js/tocbot.min.js"></script>
<script>
tocbot.init({
tocSelector: '.tocbot',
contentSelector: '.article-entry',
headingSelector: 'h1, h2, h3, h4, h5, h6',
hasInnerContainers: true,
scrollSmooth: true,
scrollContainer: 'main',
positionFixedSelector: '.tocbot',
positionFixedClass: 'is-position-fixed',
fixedSidebarOffset: 'auto'
});
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/jquery.justifiedGallery.min.js"></script>
<script src="/dist/main.js"></script>
<!-- ImageViewer -->
<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
<!-- Background of PhotoSwipe.
It's a separate element as animating opacity is faster than rgba(). -->
<div class="pswp__bg"></div>
<!-- Slides wrapper with overflow:hidden. -->
<div class="pswp__scroll-wrap">
<!-- Container that holds slides.
PhotoSwipe keeps only 3 of them in the DOM to save memory.
Don't modify these 3 pswp__item elements, data is added later on. -->
<div class="pswp__container">
<div class="pswp__item"></div>
<div class="pswp__item"></div>
<div class="pswp__item"></div>
</div>
<!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
<div class="pswp__ui pswp__ui--hidden">
<div class="pswp__top-bar">
<!-- Controls are self-explanatory. Order can be changed. -->
<div class="pswp__counter"></div>
<button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
<button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>
<button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
<button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
<!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
<!-- element will get class pswp__preloader--active when preloader is running -->
<div class="pswp__preloader">
<div class="pswp__preloader__icn">
<div class="pswp__preloader__cut">
<div class="pswp__preloader__donut"></div>
</div>
</div>
</div>
</div>
<div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
<div class="pswp__share-tooltip"></div>
</div>
<button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
</button>
<button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
</button>
<div class="pswp__caption">
<div class="pswp__caption__center"></div>
</div>
</div>
</div>
</div>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/photoswipe-ui-default.min.js"></script>
<script>
function viewer_init() {
let pswpElement = document.querySelectorAll('.pswp')[0];
let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))
$imgArr.forEach(($em, i) => {
$em.onclick = () => {
// slider展开状态
// todo: 这样不好,后面改成状态
if (document.querySelector('.left-col.show')) return
let items = []
$imgArr.forEach(($em2, i2) => {
let img = $em2.getAttribute('data-idx', i2)
let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
let title = $em2.getAttribute('alt')
// 获得原图尺寸
const image = new Image()
image.src = src
items.push({
src: src,
w: image.width || $em2.width,
h: image.height || $em2.height,
title: title
})
})
var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
index: parseInt(i)
});
gallery.init()
}
})
}
viewer_init()
</script>
<!-- MathJax -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
processEscapes: true,
skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
}
});
MathJax.Hub.Queue(function() {
var all = MathJax.Hub.getAllJax(), i;
for(i=0; i < all.length; i += 1) {
all[i].SourceElement().parentNode.className += ' has-jax';
}
});
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
var ayerConfig = {
mathjax: true
}
</script>
<!-- Katex -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js"></script>
<!-- busuanzi -->
<script src="/js/busuanzi-2.3.pure.min.js"></script>
<!-- ClickLove -->
<script src="/js/clickLove.js"></script>
<!-- ClickBoom -->
<script src="/js/clickBoom.js"></script>
<!-- CodeCopy -->
<link rel="stylesheet" href="/css/clipboard.css">
<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
function wait(callback, seconds) {
var timelag = null;
timelag = window.setTimeout(callback, seconds);
}
!function (e, t, a) {
var initCopyCode = function(){
var copyHtml = '';
copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
copyHtml += '</button>';
$(".highlight .code pre").before(copyHtml);
$(".article pre code").before(copyHtml);
var clipboard = new ClipboardJS('.btn-copy', {
target: function(trigger) {
return trigger.nextElementSibling;
}
});
clipboard.on('success', function(e) {
let $btn = $(e.trigger);
$btn.addClass('copied');
let $icon = $($btn.find('i'));
$icon.removeClass('ri-file-copy-2-line');
$icon.addClass('ri-checkbox-circle-line');
let $span = $($btn.find('span'));
$span[0].innerText = 'COPIED';
wait(function () { // 等待两秒钟后恢复
$icon.removeClass('ri-checkbox-circle-line');
$icon.addClass('ri-file-copy-2-line');
$span[0].innerText = 'COPY';
}, 2000);
});
clipboard.on('error', function(e) {
e.clearSelection();
let $btn = $(e.trigger);
$btn.addClass('copy-failed');
let $icon = $($btn.find('i'));
$icon.removeClass('ri-file-copy-2-line');
$icon.addClass('ri-time-line');
let $span = $($btn.find('span'));
$span[0].innerText = 'COPY FAILED';
wait(function () { // 等待两秒钟后恢复
$icon.removeClass('ri-time-line');
$icon.addClass('ri-file-copy-2-line');
$span[0].innerText = 'COPY';
}, 2000);
});
}
initCopyCode();
}(window, document);
</script>
</div>
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"model":{"jsonPath":"/live2dw/assets/haruto.model.json"},"display":{"position":"right","width":260,"height":520},"mobile":{"show":false},"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>