python调用百度AI接口实现人流量统计
2021-02-04 本文已影响0人
Cache_wood
百度AI接口的调用方法不必多介绍。
@[toc]
官网地址
新建AipBodyAnalysis
from aip import AipBodyAnalysis
""" 你的 APPID AK SK """
APP_ID = '你的 App ID'
API_KEY = '你的 Api Key'
SECRET_KEY = '你的 Secret Key'
client = AipBodyAnalysis(APP_ID, API_KEY, SECRET_KEY)
读取和调用
""" 读取图片 """
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
image = get_file_content('example.jpg')
""" 调用人流量统计 """
client.bodyNum(image);
""" 如果有可选参数 """
options = {}
options["area"] = "x1,y1,x2,y2,x3,y3...xn,yn"
options["show"] = "false"
""" 带参数调用人流量统计 """
client.bodyNum(image, options)
显示图片
img = Image.open('ren.jpg')
plt.imshow(img)
plt.show()
完整代码
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 1 22:22:40 2021
@author: lenovo
"""
from aip import AipBodyAnalysis
from PIL import Image
import matplotlib.pyplot as plt
APP_ID = '23619478'
API_KEY = 'x2M6XTQ4oNIlhS2f2GQBElHa'
SECRET_KEY = 'xxxxxxxxxxxxxxx'
client = AipBodyAnalysis(APP_ID, API_KEY, SECRET_KEY)
""" 读取图片 """
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
image = get_file_content('ren.jpg')
img = Image.open('ren.jpg')
plt.imshow(img)
plt.show()
""" 调用人流量统计 """
print(client.bodyNum(image))
最终效果
{'person_num': 45, 'log_id': 4050401326612145858}