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
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
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
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))))
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])))
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))))