太累了,,有时间再补解释

import pytesseract
import requests
from PIL import Image
from PIL import ImageFilter
from StringIO import StringIO
from werkzeug.utils import secure_filename
from gevent import monkey
from gevent.pywsgi import WSGIServer
monkey.patch_all()
from flask import Flask,render_template,jsonify,request,send_from_directory
import time
import os
import base64
import random app = Flask(__name__)
UPLOAD_FOLDER='upload'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
basedir = os.path.abspath(os.path.dirname(__file__))
ALLOWED_EXTENSIONS = set(['png','jpg','JPG','PNG']) def allowed_file(filename):
return '.' in filename and filename.rsplit('.',)[] in ALLOWED_EXTENSIONS @app.route('/',methods=['GET'],strict_slashes=False)
def indexpage():
return render_template('index.html') @app.route('/',methods=['POST'],strict_slashes=False)
def api_upload():
log = open("error.log","w+")
file_dir = os.path.join(basedir, app.config['UPLOAD_FOLDER'])
if not os.path.exists(file_dir):
os.makedirs(file_dir)
print request.headers
print >> log, request.headers
f = request.files['file']
postLang = request.form.get("lang", type=str) log.close() if f and allowed_file(f.filename):
fname = secure_filename(f.filename)
ext = fname.rsplit('.',)[]
unix_time = int(time.time())
new_filename = str( random.randrange(, , ))+str(unix_time)+'.'+ext
f.save(os.path.join(file_dir,new_filename))
if cmp(postLang, "chi_sim"):
strboxs = pytesseract.image_to_boxes(Image.open("/var/OCRhtml/upload/" + new_filename), lang="chi_sim")
strdata = pytesseract.image_to_string(Image.open("/var/OCRhtml/upload/" + new_filename), lang="chi_sim")
print "Chinese"
else:
strboxs = pytesseract.image_to_boxes(Image.open("/var/OCRhtml/upload/"+new_filename))
strdata = pytesseract.image_to_string(Image.open("/var/OCRhtml/upload/"+new_filename))
return jsonify({"errno":, "msg":"succeed ","data":strdata,"info":strboxs})
else:
return jsonify({"errno":, "errmsg":u"failed"}) if __name__ == '__main__':
http_server = WSGIServer(('', ), app)
http_server.serve_forever()

python实现的ocr接口的更多相关文章

  1. 什么是 WSGI -- Python 中的 “CGI” 接口简介

    今天在 git.oschina 的首页上看到他们推出演示平台,其中,Python 的演示平台支持 WSGI 接口的应用.虽然,这个演示平台连它自己提供的示例都跑不起来,但是,它还是成功的勾起了我对 W ...

  2. python面向对象进阶 反射 单例模式 以及python实现类似java接口功能

    本篇将详细介绍Python 类的成员.成员修饰符.类的特殊成员. 类的成员 类的成员可以分为三大类:字段.方法和特性. 注:所有成员中,只有普通字段的内容保存对象中,即:根据此类创建了多少对象,在内存 ...

  3. 戏说WSGI(Python Web服务网关接口)--[转载]

    戏说WSGI(Python Web服务网关接口) 当你在Python的世界中冒险,突然遭遇一只Web怪兽,你会选择什么武器对付它?在兵器谱上,下列兵器可谓名列前茅: Zope,厚重的长枪.较早出现的武 ...

  4. 转载:python + requests实现的接口自动化框架详细教程

    转自https://my.oschina.net/u/3041656/blog/820023 摘要: python + requests实现的接口自动化框架详细教程 前段时间由于公司测试方向的转型,由 ...

  5. Python 基于python实现的http接口自动化测试框架(含源码)

    基于python实现的http+json协议接口自动化测试框架(含源码) by:授客 QQ:1033553122      欢迎加入软件性能测试交流 QQ群:7156436  由于篇幅问题,采用百度网 ...

  6. 关于python调用zabbix api接口

    因公司业务需要,引进了自动化运维,所用到的监控平台为zbbix3.2,最近正在学习python,计划使用python调用zabbix api接口去做些事情,如生成报表,我想最基本的是要取得zabbix ...

  7. 使用python requests库写接口自动化测试--记录学习过程中遇到的坑(1)

    一直听说python requests库对于接口自动化测试特别合适,但由于自身代码基础薄弱,一直没有实践: 这次赶上公司项目需要,同事小伙伴们一起学习写接口自动化脚本,听起来特别给力,赶紧实践一把: ...

  8. python + requests实现的接口自动化框架详细教程

    前段时间由于公司测试方向的转型,由原来的web页面功能测试转变成接口测试,之前大多都是手工进行,利用postman和jmeter进行的接口测试,后来,组内有人讲原先web自动化的测试框架移驾成接口的自 ...

  9. python调用支付宝支付接口

    python调用支付宝支付接口详细示例—附带Django demo代码   项目演示: 一.输入金额 二.跳转到支付宝付款 三.支付成功 四.跳转回自己网站 在使用支付宝接口的前期准备: 1.支付宝公 ...

随机推荐

  1. python 有参数的装饰器

    怎么样为装饰器加参数 import time current_user = {'user':None} def auth(engine = "file") def deco(fun ...

  2. 第八周总结and实验

    1.实验目的 理解异常的基本概念:掌握异常处理方法及熟悉常见异常的捕获方法. 2.实验要求 练习捕获异常.声明异常.抛出异常的方法.熟悉try和catch子句的使用.掌握自定义异常类的方法. 3.实验 ...

  3. ansible-playbook 案例

    nginx的安装 编写nginx的自动部署文件nginx.yml      hosts主机更改为自己定义的 访问目标主机组的IP地址,查看测试页面 测试页面:显示的是本机ip 1 <h1> ...

  4. Linux 下文件句柄数的查询学习

    1. 查看 所有进程的 打开的句柄数 lsof -n|awk '{print $2}'|sort|uniq -c |sort -nr|more 效果为: 2. 查看某一个进程内的 文件信息 lsof ...

  5. 插入数据库失败([Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version)

    报错信息如下: , ) 原因,read是数据库的关键字, 牢记,如果一个词是数据库的关键字,那么在写数据库语句的时候,这个词一定是蓝色的(关键字颜色)!!

  6. PHP控制session时效(转)

    1.php session 有效期php的session有效期默认是1440秒(24分钟),如果客户端超过24分钟没有刷新,当前session会被回收,失效. 当用户关闭浏览器,会话结束,sessio ...

  7. pgsql物理复制(pgsql 备库的搭建以及角色互换,提升)

    结构图如下: Postgresql早在9.0版本开始支持物理复制,也称为流复制,通过从实例级复制出一个与主库一模一样的备库.流复制同步方式有同步,异步两种,如果主节点和备节点不是很忙,通常异步模式下备 ...

  8. python接口、抽象类与抽象方法

    接口: -url -数据类型,python不存在 class 类名 1.类中的方法可以写任意多个 2.如果想要对类中的方法做约束,就需要写接口 接口中定义一个方法f1,可以约束继承他的子类 class ...

  9. node(koa2)跨域与获取cookie

    欲做一个node 的网关服务,通过 cookie 做信息传递,选择框架 koa2,这里简单记录跨域处理以及 cookie 获取. 首先:解决跨域问题,使用 koa2-cros 来处理,跨域问题后端处理 ...

  10. PhpStorm 2017.3-2018.2 汉化包

    JetBrains 系列软件汉化包 关键字: Android Studio 3.0-3.1.3 汉化包 CLion 2018.1-2018.2 汉化包 GoLand 2017.3.2-2018.2 汉 ...