示例#1
0
文件: Face.cs 项目: peapodss/DaySign
        public byte[] GetFaceData(AFD_FSDK_FACERES faceRes, IntPtr offInputPtr)
        {
            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));

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

            Marshal.FreeHGlobal(faceModelPtr);
            Marshal.FreeHGlobal(faceInputPtr);

            return(byteData);
        }
示例#2
0
文件: Face.cs 项目: peapodss/DaySign
        //检查是否存在人脸,imageDataPtr必须在offInputPtr用完后释放掉
        public bool CheckFace(Bitmap bitmap, out AFD_FSDK_FACERES faceRes, out IntPtr offInputPtr, out IntPtr imageDataPtr)
        {
            byte[] imageData = BitmapToBmp(bitmap, out int width, out int height, out int pitch);

            imageDataPtr = Marshal.AllocHGlobal(imageData.Length);
            Marshal.Copy(imageData, 0, imageDataPtr, imageData.Length);

            ASVLOFFSCREEN offInput = new ASVLOFFSCREEN();

            offInput.u32PixelArrayFormat = 513;
            offInput.ppu8Plane           = new IntPtr[4];
            offInput.ppu8Plane[0]        = imageDataPtr;
            offInput.i32Width            = width;
            offInput.i32Height           = height;
            offInput.pi32Pitch           = new int[4];
            offInput.pi32Pitch[0]        = pitch;
            offInputPtr = Marshal.AllocHGlobal(Marshal.SizeOf(offInput));
            Marshal.StructureToPtr(offInput, offInputPtr, false);

            faceRes = new AFD_FSDK_FACERES();
            IntPtr faceResPtr   = Marshal.AllocHGlobal(Marshal.SizeOf(faceRes));
            int    detectResult = FaceAPI.AFD_FSDK_StillImageFaceDetection(detectEngine, offInputPtr, ref faceResPtr);

            faceRes = (AFD_FSDK_FACERES)Marshal.PtrToStructure(faceResPtr, typeof(AFD_FSDK_FACERES));
            MRECT rect = (MRECT)Marshal.PtrToStructure(faceRes.rcFace, typeof(MRECT));

            bool ret = faceRes.nFace > 0;

            imageData = null;

            //Marshal.FreeHGlobal(imageDataPtr); //这个指针内存泄漏了

            //Marshal.FreeHGlobal(faceResPtr);
            //GC.Collect();
            return(ret);
        }
示例#3
0
 public byte[] GetFaceData(AFD_FSDK_FACERES faceRes, IntPtr offInputPtr)
 {
     byte[] byteData = faceFR.GetFaceData(faceRes, offInputPtr);
     return(byteData);
 }