import qqai
import base64
import types
your_app_id = '2******4' ###自己的appid
your_app_key = 'Bf********fa'
from qqai.vision.ocr import GeneralOCR ###也可以调用其余的例如身份证等OCR识别API,我这里选择的是通用的
it = GeneralOCR(your_app_id, your_app_key)
with open('E:\\2.jpg', 'rb') as image: #选择自己的要识别的图片,因为API限制只能使用BufferedReader/url
print(type(image))
result = it.run(image)####这里的image也可以直接是个图片的url
print(result)
tmp_list = []
def get_target_value(key, dic):
if not isinstance(dic, dict) or not isinstance(tmp_list, list): # 对传入数据进行格式校验
return 'argv[1] not an dict or argv[-1] not an list '
if key in dic.keys():
tmp_list.append(dic[key]) # 传入数据存在则存入tmp_list
else:
for value in dic.values(): # 传入数据不符合则对其value值进行遍历
if isinstance(value, dict):
get_target_value(key, value) # 传入数据的value值是字典,则直接调用自身
elif isinstance(value, (list, tuple)):
_get_value(key, value) # 传入数据的value值是列表或者元组,则调用_get_value
return tmp_list
def _get_value(key, val):
for val_ in val:
if isinstance(val_, dict):
get_target_value(key, val_) # 传入数据的value值是字典,则调用get_target_value
elif isinstance(val_, (list, tuple)):
_get_value(key, val_) # 传入数据的value值是列表或者元组,则调用自身
if __name__ == '__main__':
print(get_target_value("itemstring", result))
首先自己先去腾讯AI申请appid和appkey,然后pip install 一个qqai就行,所以这应该算是一个科普文~~~~
原图1
效果图1
原图2
效果图2
版权声明:本文为qq_36279725原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。