コード例 #1
0
ファイル: Face.cs プロジェクト: peapodss/DaySign
        public byte[] GetFaceData(Bitmap bitmap, Face_FD face_FD)
        {
            bool isFace = face_FD.CheckFace(bitmap, out AFD_FSDK_FACERES faceRes, out IntPtr offInputPtr, out IntPtr imageDataPtr);

            if (!isFace)
            {
                Error.Log(ErrorType.inputError);
                return(null);
            }

            AFR_FSDK_FaceInput faceinput = new AFR_FSDK_FaceInput();

            faceinput.lOrient = (int)Marshal.PtrToStructure(faceRes.lfaceOrient, typeof(int));
            MRECT rect = (MRECT)Marshal.PtrToStructure(faceRes.rcFace, typeof(MRECT));

            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 = FaceAPI.AFR_FSDK_ExtractFRFeature(detectEngine, offInputPtr,
                                                        faceInputPtr, faceModelPtr);

            if (ret != 0) //返回值为0代表获取成功
            {
                Log.AddLog("获取不到人脸信息。");
                return(null);
            }

            faceModel = (AFR_FSDK_FaceModel)Marshal.PtrToStructure(faceModelPtr, typeof(AFR_FSDK_FaceModel));
            Marshal.FreeHGlobal(faceModelPtr);

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

            Marshal.FreeHGlobal(faceInputPtr);

            return(byteData);
        }