tornado zbar 二维码识别 ,配合nginx 反向代理,supervisord 监控
tornado zbar 二维码识别 ,配合nginx 反向代理,supervisord 监控
1、zbar识别二维码程序,python2.6.6
#!/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)
2、下面给出我的supervisord的配置。请各位看官根据自己的实际情况修改对应的root用户。
;/etc/supervisord.conf
[unix_http_server]
file = /var/run/supervisor.sock
chmod = 0777
chown= root:dabao [inet_http_server]
# Web管理界面设定
port=127.0.0.1:9001
username = dabao
password = dabao [supervisorctl]
; 必须和'unix_http_server'里面的设定匹配
serverurl = unix:///var/run/supervisord.sock [supervisord]
logfile=/var/log/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=true ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
user=root ; (default is current user, required if root)
childlogdir=/var/log/ ; ('AUTO' child log dir, default $TEMP) [rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [program:groupworker]
command=python3 /home/dabao/8887.py 88%(process_num)02d
process_name=%(program_name)s_%(process_num)02d
numprocs=3
numprocs_start=1
autostart = true
startsecs = 5
redirect_stderr = true
stdout_logfile_maxbytes = 20MB
stdoiut_logfile_backups = 20
stdout_logfile = /var/log/groupworker.log
3、最后第三个配置文件是nginx的反向代理配置。
nginx 1.4.4
/etc/nginx/conf.d/tornado.conf upstream tornado {
server 127.0.0.1:8887;
server 127.0.0.1:8888;
server 127.0.0.1:8889;
}
server {
listen 8090;
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://tornado;
}
}
tornado zbar 二维码识别 ,配合nginx 反向代理,supervisord 监控的更多相关文章
- Opencv+Zbar二维码识别(二维码校正)
二维码和车牌识别基本都会涉及到图像的校正,主要是形变和倾斜角度的校正,一种二维码的畸变如下图: 这个码用微信扫了一下,识别不出来,但是用Zbar还是可以准确识别的~~. 这里介绍一种二维码校正方法,通 ...
- Opencv+Zbar二维码识别(标准条形码/二维码识别)
使用Opencv+Zbar组合可以很容易的识别图片中的二维码,特别是标准的二维码,这里标准指的是二维码成像清晰,图片中二维码的空间占比在40%~100%之间,这样标准的图片,Zbar识别起来很容易,不 ...
- Opencv+Zbar二维码识别(一维码校正)
一维码由一组规则排列的黑色线条.白色线条以及对应的字符组成.对倾斜的(没有严重形变)一维码的角度校正,可以根据其黑白相间.排列规则的特点,计算傅里叶频谱,通过傅里叶频谱中直线的倾斜角度计算空间域图像一 ...
- 有关python下二维码识别用法及识别率对比分析
最近项目中用到二维码图片识别,在python下二维码识别,目前主要有三个模块:zbar .zbarlight.zxing. 1.三个模块的用法: #-*-coding=utf-8-*- import ...
- Python zxing 库解析(条形码二维码识别)
各种扫码软件 最近要做个二维码识别的项目,查到二维码识别有好多开源的不开源的软件 http://www.oschina.net/project/tag/238/ Zbar 首先试了一下Zbar,pyt ...
- 基于opencv3.0和下的条形码与二维码识别
其中对条码与二维码的识别分为以下4个步骤 1. 利用opencv和Zbar(或者Zxing)对标准的条形码图片(即没有多余背景干扰,且图片没有倾斜)进行解码,将解码信息显示出来,并与原始信息对比. 2 ...
- android 图片二维码识别和保存(一)
最新业务开发二维码识别的功能,这个功能,在很多应用上都有,比如微信长按图片识别二维码,如果图片中存在可以识别的二维码时,可以增加一个选项 识别二维码.那么如何去实现这个功能呢.这里其实也非常简单,首先 ...
- 第47章 QR-Decoder-OV5640二维码识别—零死角玩转STM32-F429系列
第47章 QR-Decoder-OV5640二维码识别 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.y ...
- 基于opencv+python的二维码识别
花了2天时间终于把二维码识别做出来了,不过效果一般,后面会应用在ROS辅助定位上,废话少说先上图: 具体过程参考了这位大神的博客:http://blog.csdn.net/qq_25491201/ar ...
随机推荐
- CodeForces 733D Kostya the Sculptor
排序.把每一个长方体拆成$6$个做,然后排序做即可. #pragma comment(linker, "/STACK:1024000000,1024000000") #includ ...
- (寒假开黑gym)2018 ACM-ICPC, Syrian Collegiate Programming Contest(爽题)
layout: post title: (寒假开黑gym)2018 ACM-ICPC, Syrian Collegiate Programming Contest(爽题) author: " ...
- HDU 6039 Gear Up(线段树+并查集)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6039 [题目大意] 给出一些齿轮,有些齿轮是边相连,也就是拥有相同的线速度, 有的齿轮是轴相连,也 ...
- BZOJ 3997 [TJOI2015]组合数学(单调DP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3997 [题目大意] 给出一个网格图,其中某些格子有财宝,每次从左上角出发,只能向下或右 ...
- CodeForces 380C Sereja and Brackets(扫描线+树状数组)
[题目链接] http://codeforces.com/problemset/problem/380/C [题目大意] 给出一个括号序列,求区间内左右括号匹配的个数. [题解] 我们发现对于每个右括 ...
- BZOJ 3391 [Usaco2004 Dec]Tree Cutting网络破坏(树形DP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3391 [题目大意] 给定一棵树,求分支size均不大于一半点数的点 [题解] 递归的同 ...
- [LOJ2553]暴力写挂
锟题x2 以下用$a\rightarrow b$表示端点为$a,b$的链 把式子写成$(h_1(x)+h_1(y)-h_1(lca))-h_2(lca')$,第一部分就是$x\rightarrow r ...
- JDK | JDK安装与环境变量配置
文章目录 写在前面 官网下载安装jdk jdk系统环境变量的配置 检验jdk是否配置成功 写在前面 JDK的全称是Java SE Development Kit,也就是Java 开发工具箱.SE表示标 ...
- PHP与Web页面的交互
1.form表单默认情况下提交数据的方式为get方式. 2.PHP脚本用来处理表单数据的预定义变量是$_GET,$_POST(区分大小写) 代码示例:(特别注意复选框属性name的时候加数组) sim ...
- 2014DNIOS视频教程(5-9)
2014DNIOS视频教程(5-9) 联系2g32@sina.com