您的位置:首页 > 运维架构

【NanoPi2试用体验】nanopi2下的二维码识别

2016-01-31 20:22 471 查看
用nanopi实现图像处理的方法有很多,不过最流行的肯定就是opencv了,以前我做树莓派的识别时还用过SimpleCV,不过不知道为何nanopi就是装不上:

1.安装SimpleCV

SimpleCV的安装十分简便,首先通过apt-get工具安装支持包:

$ sudo apt-get install ipython python-opencv python-scipy python-numpy python-pygame python-setuptools python-pip

2.通过pip命令下载并安装SimpleCV:

$ sudo pip install https://github.com/sightmachine/SimpleCV/zipball/develop
复制代码







不知道谁有经验呢?

一条路不行,还有第二条路:zbar,这是python的库

当初在树莓派上装,装的我要死要活,糊里糊涂的用上了,也没有整理下怎么做,这次死活也装不上了,于是只能再找方法。。

总有能装上的东西的(来自网络)

安装如下工具:

sudo apt-get install python-imaging

sudo apt-get install zbar-tools

sudo apt-get install qrencode

sudo apt-get install python-pygame

复制代码

qicode.py

#!/usr/bin/env python

#-*- coding: UTF-8 -*-

import os, signal, subprocess

strfile1 = "qrcode"

def erzeugen():

text=raw_input(u"enter QRCode in: ")

os.system("qrencode -o "+strfile1+".png '"+text+"'")

print u"QRCode is in: "+strfile1+".png"



def lesen():

zbarcam=subprocess.Popen("zbarcam --raw --nodisplay /dev/video0", stdout=subprocess.PIPE, shell=True, preexec_fn=os.setsid)

print u"zbarcam start successfully=..."

i=0

while i<5:

## while True:

qrcodetext=zbarcam.stdout.readline()

if qrcodetext!="":

print qrcodetext

i=i+1

## print u"successfully"

## break



os.killpg(zbarcam.pid, signal.SIGTERM) # close program

print u"zbarcam stop successfully"

return u"QRCode: "+qrcodetext

复制代码

main.py

#!/usr/bin/env python

#-*- coding: UTF-8 -*-

import qrcode

while (True):

print u"1: qrcode create"

print u"2: qrcode identify"

print u"3: quit"

select=int(raw_input(u"choose: "))

if select == 1:

qrcode.erzeugen()

elif select == 2:

result=qrcode.lesen().strip()

print result

elif select == 3:

print u"end..."

break

复制代码

执行代码

python main.py

复制代码




先生成二维码,再解码




我这里就写入数字21了,这里应该是不能输入中文的。

这是生成的文件了:




现在来读取:




读取成功~

一个基本的二维码识别基本完成了。

PS:由于家里没键盘,我只能用SecureCRT +显示屏 结合着调试,一开nanopi的虚拟键盘,界面就各种卡死,微微颤颤就做到这个样子吧,希望各位大牛多指导指导小弟 ^_^
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: