/// <summary> /// 获取人脸的数量 /// </summary> /// <returns></returns> public int FindFaceNum() { MultiFaceInfo faceInfo = DetectFaces(); //如果底层返回的数据并没有相框及角度信息,默认没有检测到人脸 if (faceInfo.faceOrient == IntPtr.Zero || faceInfo.faceRect == IntPtr.Zero) { return(0); } return(faceInfo.faceNum); }
/// <summary> /// 获取人脸检测结果 /// </summary> /// <param name="image"></param> /// <param name="bitmapImage"></param> /// <returns></returns> public MultiFaceInfo DetectFaces(Bitmap image, out BitmapImage bitmapImage) { bitmapImage = new BitmapImage(image); bitmapImage.ParseImage(); MultiFaceInfo faceInfo = new MultiFaceInfo(); try { ResultCode result = (ResultCode)ASFAPI.ASFDetectFaces(hEngine, bitmapImage.Width, bitmapImage.Height, bitmapImage.Format, bitmapImage.ImageData, ref faceInfo); if (result == ResultCode.成功) { return(faceInfo); } else { throw new Exception(result.ToString()); } } catch (Exception ex) { throw ex; } }
public static extern int ASFProcess(IntPtr hEngine, int width, int height, int format, byte[] imgData, MultiFaceInfo detectedFaces, int combinedMask);
public static extern int ASFDetectFaces(IntPtr hEngine, int width, int height, int format, byte[] data, ref MultiFaceInfo detectedFaces);
/// <summary> /// 获取人脸的数量 /// </summary> /// <returns></returns> public int FindFaceNum() { MultiFaceInfo faceInfo = DetectFaces(); return(faceInfo.faceNum); }