不晓得微软的Project Oxford API还能不能用

电脑技术 电脑技术 1267 人阅读 | 1 人回复 | 2022-04-13

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
########### Python 2.7 #############
import httplib, urllib, base64

headers = {
   # Basic Authorization Sample
   # 'Authorization': 'Basic %s' % base64.encodestring('{username}:{password}'),
   'Content-type': 'application/json',
}

params = urllib.urlencode({
   # Specify your subscription key
   'subscription-key': 'xxxxxxxxxxxxxxxxxxxxxxxxx',
   # Specify values for optional parameters, as needed
   'language': 'unk',
   'detectOrientation ': 'true',
})

try:
   conn = httplib.HTTPSConnection('api.projectoxford.ai')
   conn.request("POST", "/vision/v1/ocr?%s" % params, "{'Url':'http://images.takungpao.com/2012/1115/20121115073901672.jpg'}", headers)
   response = conn.getresponse()
   data = response.read()
   print(data)
   conn.close()
except Exception as e:
   print("[Errno {0}] {1}".format(e.errno, e.strerror))

####################################

########### Python 3.2 #############
import http.client, urllib.request, urllib.parse, urllib.error, base64

headers = {
   # Basic Authorization Sample
   # 'Authorization': 'Basic %s' % base64.encodestring('{username}:{password}'),
   'Content-type': 'application/json',
}

params = urllib.parse.urlencode({
   # Specify your subscription key
   'subscription-key': 'XXXXXXXXXXXXXXXXXXXXXXXXXXX',
   # Specify values for optional parameters, as needed
   'language': 'unk',
   'detectOrientation ': 'true',
})

try:
   conn = http.client.HTTPSConnection('api.projectoxford.ai')
   conn.request("POST", "/vision/v1/ocr?%s" % params, "{'Url':'http://images.takungpao.com/2012/1115/20121115073901672.jpg'}", headers)
   response = conn.getresponse()
   data = response.read()
   print(data)
   conn.close()
except Exception as e:
   print("[Errno {0}] {1}".format(e.errno, e.strerror))

回答|共 1 个

willsonlincake 发表于 2022-4-13 21:17:44| 字数 35 来自手机 | 显示全部楼层

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

热门推荐