怎么通过图片的url识别其中的文字?
斐尘瞳子 发布于2018-12 浏览:1877 回复:4
0
收藏
import base64
import urllib3,base64
import json
from urllib.parse import urlencode

access_token='your'
http=urllib3.PoolManager()
url='https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token='+access_token
f = open('image.png','rb')
#参数image:图像base64编码
img = base64.b64encode(f.read())
params={'image':img}
#对base64数据进行urlencode处理
params=urlencode(params)
request=http.request('POST', 
                      url,
                      body=params,
                      headers={'Content-Type':'application/x-www-form-urlencoded'})
#对返回的byte字节进行处理。Python3输出位串,而不是可读的字符串,需要进行转换
result = str(request.data,'utf-8')
#返回参数json序列化处理
res = json.loads(result)
print(res)

有图片可以打开图片识别,那只有图片的url代码应该怎么改才可用呢?

 

 

 

收藏
点赞
0
个赞
共4条回复 最后由用户已被禁言回复于2022-04
#5斐尘瞳子回复于2018-12
#3 173******90回复
import requests  from aip import AipOcr  image = requests.get('https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1545297615249&di=417de420f364ff1d5191a24599f08783&imgtype=0&src=http%3A%2F%2Fimg238.ph.126.net%2Fqd0R2smfhpib4ag_VhyIhQ%3D%3D%2F1421730107367067801.jpg').content  APP_ID =  API_KEY =  SECRET_KEY= client = AipOcr(APP_ID, API_KEY, SECRET_KEY)  res = client.basicAccurate(image)  if 'words_result' in res.keys():           for item in res['words_result']:                   print(item['words'])  
展开

谢谢,我试试

0
#4斐尘瞳子回复于2018-12
#2 liguanghui2588回复
这个涉及到文字识别,调用python的SDK?

没用过,不太清楚

0
#3173******90回复于2018-12

import requests 

from aip import AipOcr 

image = requests.get('https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1545297615249&di=417de420f364ff1d5191a24599f08783&imgtype=0&src=http%3A%2F%2Fimg238.ph.126.net%2Fqd0R2smfhpib4ag_VhyIhQ%3D%3D%2F1421730107367067801.jpg').content 

APP_ID = 

API_KEY = 

SECRET_KEY=

client = AipOcr(APP_ID, API_KEY, SECRET_KEY) 

res = client.basicAccurate(image) 

if 'words_result' in res.keys():

     

    for item in res['words_result']:

         

        print(item['words'])

 

0
#2liguanghui2588回复于2018-12

这个涉及到文字识别,调用python的SDK?

0
TOP
切换版块