百度ocr开放api调用python代码

百度开放了ocr的api,改改调用评测了一把准确率和召回率,基本上属于可用的范围,对于一般的图片识别效果还可以。


import sys, urllib, urllib2, json
import base64
import StringIO

url = 'http://apis.baidu.com/apistore/idlocr/ocr'

data = {}
data['fromdevice'] = "pc"
data['clientip'] = "10.10.10.0"
data['detecttype'] = "LocateRecognize"
data['languagetype'] = "CHN_ENG"
data['imagetype'] = "1"


#读取图片
file=open('9.jpg','rb')
image= file.read()
file.close()

data['image'] = base64.b64encode(image)
decoded_data = urllib.urlencode(data)


req = urllib2.Request(url, data = decoded_data)

req.add_header("Content-Type", "application/x-www-form-urlencoded")
req.add_header("apikey", "你的key")

resp = urllib2.urlopen(req)
content = resp.read()
if(content):
        print(content)


猜你喜欢

转载自blog.csdn.net/cxf7394373/article/details/48138133