Exemplo n.º 1
0
        public static int FaceDetect(byte[] image, HIWITFaceRegion[] faceRect, ref int faceNumber, int minFaceSize, int maxFaceSize, HIWITFaceRect? detectROI = null)
        {
            if (image == null || faceRect == null) return HIWIT_ERR_ILLEGAL;
            IntPtr roiPtr = IntPtr.Zero;
            IntPtr faceRectPtr = IntPtr.Zero;
            try {
                if (detectROI != null) {
                    roiPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HIWITFaceRect)));
                    Marshal.StructureToPtr(detectROI, roiPtr, false);
                }
                faceRectPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HIWITFaceRegion)) * faceRect.Length);

                int r = HIWITFaceDetect(APPIP, APPKEY, image, image.Length, faceRectPtr, faceRect.Length, ref faceNumber, minFaceSize, maxFaceSize, roiPtr);
                if (r == HIWIT_ERR_NONE && faceNumber != 0) {
                    for (int i = 0; i < faceNumber; i++) {
                        IntPtr tmPtr = new IntPtr(faceRectPtr.ToInt64() + Marshal.SizeOf(typeof(HiwitLib.HIWITFaceRegion)) * i);
                        faceRect[i] = (HiwitLib.HIWITFaceRegion)Marshal.PtrToStructure(tmPtr, typeof(HiwitLib.HIWITFaceRegion));
                    }
                }
                return r;
            }
            finally {
                Marshal.FreeHGlobal(roiPtr);
                Marshal.FreeHGlobal(faceRectPtr);
            }
        }
Exemplo n.º 2
0
 public static int FaceAlignmentFromFaceRegion(byte[] image, HIWITFaceRegion faceRegion, ref HIWITFaceInfo faceInfo)
 {
     if (image == null) return HIWIT_ERR_ILLEGAL;
     IntPtr regionPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HIWITFaceRegion)));
     Marshal.StructureToPtr(faceRegion, regionPtr, false);
     IntPtr infoPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HIWITFaceInfo)));
     try {
         int r = HIWITFaceAlignmentFromFaceRegion(APPIP, APPKEY, image, image.Length, regionPtr, infoPtr);
         if (r == HIWIT_ERR_NONE) faceInfo = (HIWITFaceInfo)Marshal.PtrToStructure(infoPtr, typeof(HIWITFaceInfo));
         return r;
     }
     finally {
         Marshal.FreeHGlobal(regionPtr);
         Marshal.FreeHGlobal(infoPtr);
     }
 }