Example #1
0
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))
    print('image1:', res1)

    # 获取人脸属性
    # print(1 | 4)
    # print(8 | 16 | 32)
    res = faceUtil.asfProcess(image1, 0x201, faces1, 56)
    print(res)
    print(faceUtil.asfGetAge()[1].ageArray[0])
    print(faceUtil.asfGetGender()[1].genderArray[0])
    print(faceUtil.asfGetFace3DAngle()[1].roll[0])

    res2, faces2 = faceUtil.asfDetectFaces(image2, 0x201)
    if res2 == 0:
        print('image2:', res2, faces2.faceNum, faces2.faceRect)
    else:
        print('image2:', res2)
    res2 = faceUtil.asfFaceFeatureExtract(
        image2, 0x201, faceUtil.getSingleFaceInfo(faces2, 0))
    print('image2:', res2)

    # 人脸比对
    res, score = faceUtil.asfFaceFeatureCompare(res1[1], res2[1])
    print(res, score)
Example #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
Example #3
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
Example #4
0
def test1():
    # 检测人脸
    res1, faces1 = faceUtil.asfDetectFaces(image1, 0x201)
    if res1 == 0:
        print('image1:', res1, faces1.faceNum, faces1.faceRect)
    else:
        print('image1:', res1)

    res2, faces2 = faceUtil.asfDetectFaces(image2, 0x201)
    if res2 == 0:
        print('image2:', res2, faces2.faceNum, faces2.faceRect)
    else:
        print('image2:', res2)

    # 测试多张人脸如何获取值
    # img3 = faceUtil.IM()
    # img3.filePath = 'E:/PycharmProjects/face_recognition_test/arcsoft_all/aaa.jpeg'
    # image3 = faceUtil.loadImage(img3)
    # res3, faces3 = faceUtil.asfDetectFaces(image3, 0x201)
    # print(faces3.faceOrient[1], faces3.faceRect[0])
    # 获取人脸特征, 先单脸
    # res1, detect1 = faceUtil.asfFaceFeatureExtract(image1, 0x201, face_detect_sdk.ASF_SingleFaceInfo(faces1.faceRect.contents, faces1.faceOrient.contents))
    res1 = faceUtil.asfFaceFeatureExtract(
        image1, 0x201, faceUtil.getSingleFaceInfo(faces1, 0))
    print('image1:', res1)
Example #5
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