willsonlincake 发表于 2022-4-13 21:16:16

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

########### 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(" {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(" {1}".format(e.errno, e.strerror))

willsonlincake 发表于 2022-4-13 21:17:44

还有这个库
https://pypi.org/project/luis/
页: [1]
查看完整版本: 不晓得微软的Project Oxford API还能不能用