#!/usr/bin/env python # coding: u8 import os import zbar import Image import urllib import uuid import requests import sys import tornado.httpserver import tornado.ioloop import tornado.options import tornado.web import requests import sys import re from tornado.options import define, options define("port", default=9000, help="run on the given port", type=int) def qrRead(url): proxies = {"http": "http://weibh:loveme@134.44.36.120:2012/",} uuid1 = uuid.uuid1() filename=str(uuid1)+".jpg" #print uuid1 #urllib.urlretrieve(url, filename) r=requests.get(url,proxies=proxies,stream=True) with open(filename, ‘wb‘) as f: for chunk in r.iter_content(chunk_size=1024): if chunk: # filter out keep-alive new chunks f.write(chunk) f.flush() f.close() # create a reader scanner = zbar.ImageScanner() # configure the reader scanner.parse_config(‘enable‘) # obtain image data pil = Image.open(filename).convert(‘L‘) width, height = pil.size #pil.show() raw = pil.tostring() # wrap image data image = zbar.Image(width, height, ‘Y800‘, raw) # scan the image for barcodes scanner.scan(image) tmpdata=‘‘ # extract results for symbol in image: # do something useful with results print symbol.type, ‘图片内容为:\n%s‘ % symbol.data tmpdata=tmpdata+symbol.data # clean up del(image) os.remove(filename) return tmpdata class MainHandler(tornado.web.RequestHandler): def get(self): #self.write(‘hello‘+sys.argv[1]) self.set_header("Content-Type", "text/plain") #url = ‘http://www.prepolino.ch/sprache/trennen/bilder/test.gif‘ #qrRead(url) url=self.get_argument("url") self.write(qrRead(url)) def post(self): self.set_header("Content-Type", "text/plain") #url = ‘http://www.prepolino.ch/sprache/trennen/bilder/test.gif‘ #qrRead(url) url=self.get_argument("url") self.write(qrRead(url)) def main(port): tornado.options.parse_command_line() application = tornado.web.Application([ (r"/", MainHandler), ]) http_server = tornado.httpserver.HTTPServer(application) http_server.listen(port) tornado.ioloop.IOLoop.instance().start() if __name__ == ‘__main__‘: port=int(sys.argv[1]) main(port)
tornado zbar 二维码识别 ,配合nginx 反向代理,supervisord 监控
tornado zbar 二维码识别 ,配合nginx 反向代理,supervisord 监控
原文:http://www.cnblogs.com/zihuxinyu/p/3540767.html