コード例 #1
0
ファイル: FrmFaceDetection.cs プロジェクト: tang5188/coding
        /// <summary>
        /// 人脸识别特征码提取
        /// </summary>
        /// <param name="image"></param>
        /// <param name="rect"></param>
        /// <param name="orient"></param>
        private byte[] RecognizeFace(Bitmap image, MRECT rect, int orient)
        {
            IntPtr offInputPtr = ArcFaceDetection.MakeImageInput_ASVLOFFSCREEN(image);

            AFR_FSDK_FACEINPUT faceInput = new AFR_FSDK_FACEINPUT();

            faceInput.lOrient = orient;
            faceInput.rcFace  = rect;
            //入参
            IntPtr faceInputPtr = Marshal.AllocHGlobal(Marshal.SizeOf(faceInput));

            Marshal.StructureToPtr(faceInput, faceInputPtr, false);

            AFR_FSDK_FACEMODEL faceModel    = new AFR_FSDK_FACEMODEL();
            IntPtr             faceModelPtr = Marshal.AllocHGlobal(Marshal.SizeOf(faceModel));

            int ret = AFRFunction.AFR_FSDK_ExtractFRFeature(this.faceRecognition.rEngine, offInputPtr, faceInputPtr, faceModelPtr);

            if (ret == 0)
            {
                faceModel = (AFR_FSDK_FACEMODEL)Marshal.PtrToStructure(faceModelPtr, typeof(AFR_FSDK_FACEMODEL));
                Marshal.FreeHGlobal(faceModelPtr);

                byte[] featureContent = new byte[faceModel.lFeatureSize];
                Marshal.Copy(faceModel.pbFeature, featureContent, 0, faceModel.lFeatureSize);

                return(featureContent);
            }
            return(null);
        }
コード例 #2
0
ファイル: FrmFaceDetection.cs プロジェクト: tang5188/coding
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);

            string appID  = ConfigurationManager.AppSettings["appid"];
            string afdKey = ConfigurationManager.AppSettings["fdKey"];
            string afrKey = ConfigurationManager.AppSettings["frKey"];

            //人脸检测初始化
            faceDetection    = new ArcFaceDetection(appID, afdKey);
            this.detectState = faceDetection.InitFaceEngine() == 0;

            //人脸识别初始化
            faceRecognition     = new ArcFaceRecognition(appID, afrKey);
            this.recognizeState = faceRecognition.InitFaceEngine() == 0;
            this.OnEngineStateChanged?.Invoke(this.detectState, this.recognizeState);
        }