NO IMAGE

百度開放了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)