示例#1
0
def loadLocalFaceDatebase(path):
    images = os.listdir(path)
    # 存放特征库
    retzs = {}
    if (len(images) > 0):
        for image in images:
            img = faceUtil.IM()
            img.filePath = os.path.join(path, image)
            print(img.filePath)
            im = faceUtil.loadImage(img)
            res, faces1 = faceUtil.asfDetectFaces(im, 0x201)
            if res == 0:
                print(im.filePath, res, faces1.faceNum, faces1.faceRect)
                res1 = faceUtil.asfFaceFeatureExtract(
                    im, 0x201, faceUtil.getSingleFaceInfo(faces1, 0))
                if res1[0] == 0:
                    print('人脸获取特征成功')
                    retzs[img.filePath] = res1[1]
                else:
                    print(
                        error.BaseException(
                            img.filePath + '人脸获取特征失败:' +
                            configUtil.getValue('error_code', str(res1[0]))))
            else:
                print(
                    error.BaseException(
                        img.filePath + '人脸检测失败:' +
                        configUtil.getValue('error_code', str(res))))
    return retzs
示例#2
0
def loadOnlineFaceDatebase(users):
    # 存放特征库
    retzs = {}
    if (len(users) > 0):
        for user in users:
            img = faceUtil.IM()
            img.filePath = user.imgUrl
            print(img.filePath)
            im = faceUtil.loadImage(img)
            res, faces1 = faceUtil.asfDetectFaces(im, 0x201)
            if res == 0:
                print(im.filePath, res, faces1.faceNum, faces1.faceRect)
                res1 = faceUtil.asfFaceFeatureExtract(
                    im, 0x201, faceUtil.getSingleFaceInfo(faces1, 0))
                if res1[0] == 0:
                    print('人脸获取特征成功')
                    retzs[img.filePath] = res1[1]
                else:
                    print(
                        error.BaseException(
                            img.filePath + '人脸获取特征失败:' +
                            configUtil.getValue('error_code', str(res1[0]))))
            else:
                print(
                    error.BaseException(
                        img.filePath + '人脸检测失败:' +
                        configUtil.getValue('error_code', str(res))))
    return retzs
示例#3
0
def getFacesRET(frame):
    retz = {}
    img = faceUtil.IM()
    img.filePath = ""
    img.data = frame
    im = faceUtil.loadImage(img)
    res, faces1 = faceUtil.asfDetectFaces(im, 0x201)
    if res == 0:
        print(im.filePath, res, faces1.faceNum, faces1.faceRect)
        for i in range(faces1.faceNum):
            res1 = faceUtil.asfFaceFeatureExtract(
                im, 0x201, faceUtil.getSingleFaceInfo(faces1, i))
            if res1[0] == 0:
                print('人脸获取特征成功')
                retz[i] = (faces1.faceRect[i], res1[1])
            else:
                print(
                    error.BaseException(
                        img.filePath + '人脸获取特征失败:' +
                        configUtil.getValue('error_code', str(res1[0]))))
    else:
        print(
            error.BaseException(img.filePath + '人脸检测失败:' +
                                configUtil.getValue('error_code', str(res))))
    return retz
示例#4
0
def activation():
    APP_ID = configUtil.getValue('arcsoft', 'APP_ID').encode()
    SDK_KEY = configUtil.getValue('arcsoft', 'SDK_KEY').encode()
    res = faceUtil.asfActivation(APP_ID, SDK_KEY)
    if res == 0 or res == 90114:
        print('激活成功', res)
    else:
        print(
            error.BaseException('激活失败:' +
                                configUtil.getValue('error_code', str(res))))
示例#5
0
def getAllUsers():
    import pymysql
    db = pymysql.Connect(host=configUtil.getValue('datasource', 'host'),
                         user=configUtil.getValue('datasource', 'username'),
                         password=configUtil.getValue('datasource',
                                                      'password'),
                         database=configUtil.getValue('datasource', 'db_name'))
    cursor = db.cursor()
    print(cursor)
    sql = "select * from faceinfo"
    users = []
    try:
        cursor.execute(sql)
        results = cursor.fetchall()
        for row in results:
            user = User(row[0], row[1], row[2], row[3], "", row[5])
            users.append(user)
    except:
        print('不能获取数据!')
    db.close()
    return users
示例#6
0
def initEngine(detectMode=0xFFFFFFFF,
               detectFaceOrientPriority=0x5,
               detectFaceScaleVal=16,
               detectFaceMaxNum=50,
               combinedMask=1 | 4 | 8 | 16 | 32):
    res = faceUtil.asfInitEngine(detectMode, detectFaceOrientPriority,
                                 detectFaceScaleVal, detectFaceMaxNum,
                                 combinedMask)
    if res[0] == 0:
        print('初始化成功:', res[0])
    else:
        print(
            error.BaseException('初始化失败:' +
                                configUtil.getValue('error_code', res[0])))
示例#7
0
def getFacesProperty(path):
    retz = {}
    img = faceUtil.IM()
    img.filePath = path
    im = faceUtil.loadImage(img)
    res, faces1 = faceUtil.asfDetectFaces(im, 0x201)
    if res == 0:
        print(im.filePath, res, faces1.faceNum, faces1.faceRect)
        res1 = faceUtil.asfProcess(im, 0x201, faces1, 56)
        if res1 == 0:
            for i in range(faces1.faceNum):
                print(faceUtil.asfGetAge()[1].ageArray[i])
                print(faceUtil.asfGetGender()[1].genderArray[i])
                print(faceUtil.asfGetFace3DAngle()[1].roll[i])
        else:
            print(
                error.BaseException(
                    img.filePath + '人脸屬性检测失败:' +
                    configUtil.getValue('error_code', str(res1))))
    else:
        print(
            error.BaseException(img.filePath + '人脸检测失败:' +
                                configUtil.getValue('error_code', str(res))))