示例#1
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
示例#2
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
示例#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 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))))
示例#5
0
# 激活设备
res = faceUtil.asfActivation(APP_ID, SDK_KEY)
if res == 0 or res == 90114:
    print("激活成功!", res)
else:
    print("激活失败!", res)

# 0xFFFFFFFF, 0x1, 16, 50, 5, byref(Handle))
res, faceEngine = faceUtil.asfInitEngine(0xFFFFFFFF, 0x5, 16, 50, 61)
if res == 0:
    print("初始化成功!", res)
else:
    print("初始化失败!", res)

image1 = faceUtil.loadImage(img1)
image2 = faceUtil.loadImage(img2)

print('image1: ', image1)
print('image2: ', image2)


# 分开检测以及获取属性
def test():
    res1, faces1 = faceUtil.asfDetectFaces(image1, 0x201)
    if res1 == 0:
        print('image1:', res1, faces1.faceNum, faces1.faceRect)
    else:
        print('image1:', res1)
    res1 = faceUtil.asfFaceFeatureExtract(
        image1, 0x201, faceUtil.getSingleFaceInfo(faces1, 0))