700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 有道自然语言翻译和文字识别OCR(图片文字识别)接口调用

有道自然语言翻译和文字识别OCR(图片文字识别)接口调用

时间:2020-09-21 14:39:54

相关推荐

有道自然语言翻译和文字识别OCR(图片文字识别)接口调用

官网:

文档地址 :/docs/doc-oc…

在Python中调用api.

#/usr/bin/env python#coding=utf8import httplibimport md5import urllibimport urllib2import randomimport jsonimport base64appKey = '应用程序key'secretKey = '应用程序秘钥'httpClient = Nonetry:f=open(r'd:\1.png','rb') #二进制方式打开图文件 需要用户在d:\1.png 放这个图片并且里面得有文字img=base64.b64encode(f.read()) #读取文件内容,转换为base64编码 f.close()detectType = '10011'imageType = '1'langType = 'zh-en'#ensalt = random.randint(1, 65536)sign = appKey+img+str(salt)+secretKeym1 = md5.new()m1.update(sign)sign = m1.hexdigest()data = {'appKey':appKey,'img':img,'detectType':detectType,'imageType':imageType,'langType':langType,'salt':str(salt),'sign':sign}data = urllib.urlencode(data)req = urllib2.Request('/ocrapi',data)#response是HTTPResponse对象response = urllib2.urlopen(req)readJson = response.read()print unicode(readJson, "utf-8")except Exception, e:print efinally:if httpClient:httpClient.close()复制代码

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。