代码部分:
识别效果:
代码:
# -*- coding: UTF-8 -*-
import cv2
from aip import AipImageClassify
def get_image():
cap = cv2.VideoCapture(0)
while(1):
# get a frame
ret, frame = cap.read()
# show a frame
cv2.imshow("capture", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
cv2.imwrite("test.jpg", frame)
break
cap.release()
cv2.destroyAllWindows()
def chack_image():
APP_ID = ' '
API_KEY = ' '
SECRET_KEY = ' '
client = AipImageClassify(APP_ID, API_KEY, SECRET_KEY)
"""读取图片"""
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
image = get_file_content('test.jpg')
""" 调用通用物体识别 """
keyword = client.advancedGeneral(image)
""" 如果有可选参数 """
options = {}
options["baike_num"] = 5
""" 带参数调用通用物体识别 """
client.advancedGeneral(image, options)
""" 打印出结果 """
print("num:"),print(keyword['result_num'])
for i in range(keyword['result_num']):
print(keyword['result'][i])
""" 打印识别物体的名字 """
list1 =[]
for i in range(keyword['result_num']):
list1.append(keyword['result'][i]['keyword'])
print(list1)
if __name__ == '__main__':
get_image()
chack_image()