//step 2. detect faces public YNFaces[] Detect(Bitmap src) { Int32 w = src.Width; Int32 h = src.Height; IntPtr faces = IntPtr.Zero; Int32 faceCount = 0; BitmapData srcData = src.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); YNRESULT r = YNFaceDetector_Align(mHandle, srcData.Scan0, w, h, srcData.Stride, 4, 0, ref faces, ref faceCount); src.UnlockBits(srcData); YNFaces[] results = new YNFaces[faceCount]; int size = Marshal.SizeOf(typeof(YNFaces)); for (int i = 0; i < faceCount; i++) { results[i] = new YNFaces(); Marshal.PtrToStructure(faces, results[i]); faces = new IntPtr(faces.ToInt64() + size); } return(results); }
//step 1. load models public YNRESULT loadModels(String detectModel) { YNRESULT r = YNFaceDetector_loadModels(mHandle, detectModel); return(r); }