Ejemplo n.º 1
0
    def picscoket(self,a,q):
        APP_ID = ·····
        API_KEY = ····
        SECRET_KEY = ·····
        client = AipBodyAnalysis(APP_ID, API_KEY, SECRET_KEY)

        while True:
            if q.qsize() >= 1:

                pic = q.get()
                image = self.get_file_content(pic)
                client.bodyNum(image)
                options = {}
                options["area"] = "0,0,100,100,200,200"
                options["show"] = "false"
                client.bodyNum(image, options)
                num = client.bodyNum(image, options)
                testnum = json.dumps(num)
                testnum2 = json.loads(testnum)
                testnum3 = testnum2['person_num']

                db = pymysql.connect('localhost', 'root', 'root', 'camera')
                cursor = db.cursor()
                ye = now = datetime.datetime.now()
                ye = ye.strftime('%y')
                mo = now = datetime.datetime.now()
                mo = mo.strftime('%m')
                da = now = datetime.datetime.now()
                da = da.strftime('%d')
                sql = "INSERT INTO num(year ,person_num,month,day) VALUES ( '%s', '%s','%s','%s')" % (ye,  testnum3, mo, da)
                try:
                    # 执行sql语句
                    cursor.execute(sql)
                    # 提交到数据库执行
                    db.commit()
                except:
                    # 如果发生错误则回滚
                    db.rollback()

                # 关闭数据库连接
                db.close()
                print(testnum3)


            else:
                print('为空')
                time.sleep(5)
Ejemplo n.º 2
0
            """decode(’utf-8’)表示将utf-8编码的字符串转换成unicode编码。
            encode(‘gb2312’),表示将unicode编码的字符串转换成gb2312编码。"""
            print(json.dumps(j,sort_keys=True,indent=4,separators=(',',':')))
            print_div(a,j)

        if(i==2):
            """ 调用人体属性识别
            client.bodyAttr(image);"""
            """ 如果有可选参数 """
            options = {}
            options["type"] = "gender,age"
            """ 带参数调用人体属性识别 """
            j=client.bodyAttr(image, options)
            d=json.dumps(j,sort_keys=True,indent=4,separators=(',',':'),ensure_ascii=False)
            print(d)

        if(i==3):
            """ 调用人流量统计 
            client.bodyNum(image);"""
            """ 如果有可选参数 """
            options = {}
            options["area"] = "" #x1,y1,x2,y2,x3,y3...xn,yn
            options["show"] = "false"

            """ 带参数调用人流量统计 """
            j=client.bodyNum(image)
            print(json.dumps(j,sort_keys=True,indent=4,separators=(',',':'),ensure_ascii=False))



Ejemplo n.º 3
0
# -*- coding:utf-8 -*-
# 对于输入的一张图片(可正常解码,且长宽比适宜),识别和统计图像中的人体个数,以俯拍角度为主要识别视角
from aip import AipBodyAnalysis

# APPID
APP_ID = '11828915'
API_KEY = 'TxGkNH961xrF41oxeP86pdKr'
SECRET_KEY = 'IKAacd4z9CoPp06RaWlwgYqe3g5TfelN'

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('example9.jpg')

# 调用人流量统计
print("人数有:"+str(client.bodyNum(image)['person_num']))