Coder Social home page Coder Social logo

-python-'s Introduction

树莓派二维码识别

你需要一块树莓派和原装摄像头


Author 王磊
E-mail [email protected]

使用

首先导入库zbarlight和PIL等库。
然后复制代码:


摄像头:

camera = PiCamera()
camera.start_preview()                      #启动摄像头
sleep(0.5)                                  #预热并对焦
camera.capture('/home/pi/Desktop/cc.png')   #储存捕捉的图像
camera.stop_preview()

图像识别:

img = Image.open("/home/pi/Desktop/cc.png") #打开捕捉的图像
img.show()                                 

file_path = '/home/pi/Desktop/cc.png'
with open(file_path, 'rb') as image_file:   #加载捕捉的图像
    image = Image.open(image_file)
    image.load()

codes = zbarlight.scan_codes('qrcode', image) #解析二维码并打印
print('QR codes: %s' % codes)

图像流处理:

stream=io.BytesIO()                    #使用io
  with picamera.PiCamera() as camera:
      camera.start_preview()
      sleep(2)                         #两秒做对焦最低0.2
      camera.capture(stream,format="jpeg") #获得jpeg照片流
      stream.seek(0)                       #将流指针指向初始端           
      image=Image.open(stream)             
      codes = zbarlight.scan_codes('qrcode', image)
    print('QR codes: %s' % codes)

网络请求:

apiurl = '你的网址'
apiheaders = {'U-ApiKey': '你的key'}
response = requests.get(apiurl,params={"key1": 'value1', "key2": value2...}) #get方法请求对应的参数  
temp = response.json()  #json返回值  
print(temp)
code=temp['code']
print(code)

蜂鸣器及继电器等:

GPIO.setwarnings(False)  
PIN_NO = 13 #GPIO编号,可自定义  
PIN_aa=11   #GPIO编号,可自定义
GPIO.setmode(GPIO.BOARD)  
GPIO.setup(PIN_NO, GPIO.OUT)  
GPIO.setup(PIN_aa, GPIO.OUT)
GPIO.output(PIN_aa, GPIO.HIGH)

-python-'s People

Contributors

wanglei6111 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

angious fwl998877

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.