700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > python调用腾讯ocr接口实现图片文字识别

python调用腾讯ocr接口实现图片文字识别

时间:2024-04-30 17:19:54

相关推荐

python调用腾讯ocr接口实现图片文字识别

import requestsimport hmacimport hashlibimport base64import timeimport randomimport reappid = " "secret_id = " " #参考官方文档secret_key = " " #同上expired = time.time() + 2592000onceExpired = 0current = time.time()rdm = ''.join(random.choice("0123456789") for i in range(10))userid = "0"fileid = "tencentyunSignTest"info = "a=" + appid + "&b=" + bucket + "&k=" + secret_id + "&e=" + str(expired) + "&t=" + str(current) + "&r=" + str(rdm) + "&u=0&f="signindex = hmac.new(bytes(secret_key,'utf-8'),bytes(info,'utf-8'), hashlib.sha1).digest() # HMAC-SHA1加密sign = base64.b64encode(signindex + bytes(info,'utf-8')) # base64转码,也可以用下面那行转码#sign=base64.b64encode(signindex+info.encode('utf-8'))url = "http://recognition./ocr/general"headers = {'Host': 'recognition.',"Authorization": sign,}files = {'appid': (None,appid),'bucket': (None,bucket),'image': ('00022.jpg',open('00022.jpg','rb'),'image/jpeg')} r = requests.post(url, files=files,headers=headers)responseinfo = r.contentdata = responseinfo.decode('utf-8')r_index = r'itemstring":"(.*?)"' result = re.findall(r_index, data)for i in result:print(i)

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