利用R329识别二维码
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">在安装有</font><font face="Calibri">armbian</font><font face="宋体">的操作系统的</font><font face="Calibri">R329</font><font face="宋体">开发板,可以做通过板上的摄像头识别二维码。</font></span></span></span></span></p><p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">首先安装开发库:</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:Calibri">apt-get install libzbar-dev</span></span><span style="font-size:10.5000pt"><span style="font-family:宋体"> <font face="Calibri">--fix-missing</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">出现打印信息</font></span></span></span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:Calibri"> Certificate verification failed: The certificate is NOT trusted. The certificate chain uses expired certificate. Could not handshake: Error in the certificate verification. </span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">看起来像是</font><font face="Calibri">ca-certificates</font><font face="宋体">没有安装,尝试</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:Calibri">apt update</span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:Calibri">apt install ca-certificates</span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">更新认证功能后,正常安装。</font></span></span></span></span></p>
<p style="text-align:justify"> </p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">再安装</font><font face="Calibri">python</font><font face="宋体">库:</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="Calibri">p</font></span></span><span style="font-size:10.5000pt"><span style="font-family:Calibri">ip</span></span><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="Calibri">3</font></span></span><span style="font-size:10.5000pt"><span style="font-family:Calibri"> istall pyzbar</span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"> </p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">环境搭建完成后,进行代码开发,程序流程如需:</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">实时从摄像头获取视频帧;</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">处理该视频帧,通过增强和膨胀获得一个优化后的图片;</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">在图片中找到二维码中标识点,进而定位二维码的图案;</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">然后后使用</font><font face="Calibri">pyzbar</font><font face="宋体">进行识别;</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">如果识别二维码成功,将识别结果和识别所用时间在屏幕上显示出来,同时停止视频采集。</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">如果识别失败,再获取一帧图像,重复上述操作。</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"> </p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">实际使用时发现,摄像头采集的图片效果质量较差,大部分二维码是无法识别的,且即使可成功识别,效率也非常低,几乎都需要</font><font face="Calibri">16</font><font face="宋体">秒左右进行运算,由于效率原因,这个代码的实用价值有限。计划考虑进一步提升代码效率。</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">另外在开发代码时,没有考虑旋转,因此采集到图片中的二维码需要几乎和屏幕保持相同的方向才能正确识别。为了显示效果,还是提前执行</font></span></span><span style="font-size:10.5000pt"><span style="font-family:Calibri">echo -e "\033[?25l" > /dev/tty0</span></span><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">关闭掉屏幕光标。</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"> </p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">附上成功识别的几个图片。</font></span></span></span></span></p>
<p style="text-align:justify"> </p>
<p style="text-align:justify"> </p>
<p style="text-align:justify"> </p>
<p style="text-align:justify"> </p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">取出临时图片</font></span></span></span></span></p>
<p style="text-align:justify"> </p>
<p style="text-align:justify"> </p>
<p>能识别已经挺不错的了!</p>
页:
[1]