Esempio n. 1
0
        /// <summary>
        /// 检测人脸信息。
        /// <para>注:该接口与 DetectFaces 功能一致,但采用结构体的形式传入图像数据,对更高精度的图像兼容性更好。</para>
        /// </summary>
        /// <param name="image"></param>
        /// <param name="process">执行Process方法提取特性</param>
        /// <param name="detectonly">如果只检测人脸信息,不做特征值提取,可以设置为true则不会调用Process方法</param>
        /// <returns></returns>
        public MultiFaceInfo DetectFacesEx(ImageInfo image, bool process = false, bool detectonly = false)
        {
            if (_version == 2)
            {
                return(DetectFaces(image));
            }
            var result =
                ASFFunctions.ASFDetectFacesEx(EngineHandler, image.ASFImageData, out ASF_MultiFaceInfo multiFaceInfo);

            if (result == MResult.MOK)
            {
                var entity = new MultiFaceInfo(multiFaceInfo);
                if (_version >= 4 || process)//4.x需要用到是否带口罩特性
                {
                    if (!detectonly)
                    {
                        var processcombinMask = CombinedMask & ~ASF_Mask.ASF_FACE_DETECT & ~ASF_Mask.ASF_FACERECOGNITION & ~ASF_Mask.ASF_IMAGEQUALITY & ~ASF_Mask.ASF_IR_LIVENESS & ~ASF_Mask.ASF_FACESHELTER & ~ASF_Mask.ASF_UPDATE_FACEDATA;
                        result = ASFFunctions.ASFProcessEx(EngineHandler, image.ASFImageData, multiFaceInfo, (int)processcombinMask);
                        if (result == MResult.MOK)
                        {
                            if (processcombinMask.HasFlag(ASF_Mask.ASF_AGE) && ASFFunctions.ASFGetAge(EngineHandler, out ASF_AgeInfo ageInfo) == MResult.MOK)
                            {
                                entity.SetAgeInfo(ageInfo);
                            }
                            if (processcombinMask.HasFlag(ASF_Mask.ASF_GENDER) && ASFFunctions.ASFGetGender(EngineHandler, out ASF_GenderInfo genderInfo) == MResult.MOK)
                            {
                                entity.SetGenderInfo(genderInfo);
                            }
                            if (processcombinMask.HasFlag(ASF_Mask.ASF_FACE3DANGLE) && ASFFunctions.ASFGetFace3DAngle(EngineHandler, out ASF_Face3DAngle face3DAngle) == MResult.MOK)
                            {
                                entity.SetFace3DAngle(face3DAngle);
                            }
                            if (processcombinMask.HasFlag(ASF_Mask.ASF_LIVENESS) && ASFFunctions.ASFGetLivenessScore(EngineHandler, out ASF_LivenessInfo livenessInfo) == MResult.MOK)
                            {
                                entity.SetLivenessInfo(livenessInfo);
                            }
                            if (processcombinMask.HasFlag(ASF_Mask.ASF_MASKDETECT) && ASFFunctions.ASFGetMask(EngineHandler, out ASF_MaskInfo maskInfo) == MResult.MOK)
                            {
                                entity.SetMaskInfo(maskInfo);
                            }
                            if (processcombinMask.HasFlag(ASF_Mask.ASF_FACELANDMARK) && ASFFunctions.ASFGetFaceLandMark(EngineHandler, out ASF_LandMarkInfo faceLandmark) == MResult.MOK)
                            {
                                entity.SetFaceLandmark(faceLandmark);
                            }
                        }
                    }
                }
                return(entity);
            }
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// 该接口仅支持单人脸 IR 活体检测,超出返回未知。
        /// </summary>
        /// <param name="image"></param>
        /// <param name="multiFaceInfo"></param>
        /// <returns></returns>
        public bool ProcessEx_IR(ImageInfo image, ref MultiFaceInfo multiFaceInfo)
        {
            var asfinfo = multiFaceInfo.ASFMultiFaceInfo;
            var result  = ASFFunctions.ASFProcessEx_IR(EngineHandler, image.ASFImageData, asfinfo);

            if (result == MResult.MOK)
            {
                multiFaceInfo.UpdateMultiFaceInfo(asfinfo);
                var liveness = GetLivenessScore_IR();
                multiFaceInfo.SetLivenessInfo(liveness);
                return(true);
            }
            return(false);
        }