/// <summary> /// 识别 <paramref name="bitmap"/> 中指定的人脸信息 <paramref name="info"/> 的关键点坐标。 /// <para> /// 当 <see cref="FaceType"/> <see langword="="/> <see cref="FaceType.Normal"/> 时, 需要模型:<see langword="face_landmarker_pts68.csta"/><br/> /// 当 <see cref="FaceType"/> <see langword="="/> <see cref="FaceType.Mask"/> 时, 需要模型:<see langword="face_landmarker_mask_pts5.csta"/><br/> /// 当 <see cref="FaceType"/> <see langword="="/> <see cref="FaceType.Light"/> 时, 需要模型:<see langword="face_landmarker_pts5.csta"/><br/> /// </para> /// </summary> /// <param name="bitmap">包含人脸的图片</param> /// <param name="info">指定的人脸信息</param> /// <returns></returns> public FaceMarkPoint[] FaceMark(Bitmap bitmap, FaceInfo info) { byte[] bgr = ImageSet.Get24BGRFromBitmap(bitmap, out int width, out int height, out int channels); int size; if (Platform64) { size = ViewFacePlus64.FaceMarkSize((int)MarkType); } else { size = ViewFacePlus32.FaceMarkSize((int)MarkType); } double[] _pointX = new double[size]; double[] _pointY = new double[size]; bool val; if (Platform64) { val = ViewFacePlus64.FaceMark(bgr, width, height, channels, info.Location.X, info.Location.Y, info.Location.Width, info.Location.Height, _pointX, _pointY, (int)MarkType); } else { val = ViewFacePlus32.FaceMark(bgr, width, height, channels, info.Location.X, info.Location.Y, info.Location.Width, info.Location.Height, _pointX, _pointY, (int)MarkType); } if (val) { List <FaceMarkPoint> points = new List <FaceMarkPoint>(); for (int i = 0; i < size; i++) { points.Add(new FaceMarkPoint() { X = _pointX[i], Y = _pointY[i] }); } return(points.ToArray()); } else { throw new Exception("人脸关键点获取失败"); } }
// public method /// <summary> /// 识别 <paramref name="bitmap"/> 中的人脸,并返回人脸的信息。 /// <para> /// 当 <c><see cref="FaceType"/> <see langword="="/> <see cref="FaceType.Normal"/> <see langword="||"/> <see cref="FaceType.Light"/></c> 时, 需要模型:<see langword="face_detector.csta"/><br/> /// 当 <c><see cref="FaceType"/> <see langword="="/> <see cref="FaceType.Mask"/></c> 时, 需要模型:<see langword="mask_detector.csta"/><br/> /// </para> /// </summary> /// <param name="bitmap">包含人脸的图片</param> /// <returns></returns> public FaceInfo[] FaceDetector(Bitmap bitmap) { byte[] bgr = ImageSet.Get24BGRFromBitmap(bitmap, out int width, out int height, out int channels); int size; if (Platform64) { size = ViewFacePlus64.DetectorSize(bgr, width, height, channels, DetectorSetting.FaceSize, DetectorSetting.Threshold, DetectorSetting.MaxWidth, DetectorSetting.MaxHeight, (int)FaceType); } else { size = ViewFacePlus32.DetectorSize(bgr, width, height, channels, DetectorSetting.FaceSize, DetectorSetting.Threshold, DetectorSetting.MaxWidth, DetectorSetting.MaxHeight, (int)FaceType); } float[] _socre = new float[size]; int[] _x = new int[size]; int[] _y = new int[size]; int[] _width = new int[size]; int[] _height = new int[size]; if (Platform64) { _ = ViewFacePlus64.Detector(_socre, _x, _y, _width, _height); } else { _ = ViewFacePlus32.Detector(_socre, _x, _y, _width, _height); } List <FaceInfo> infos = new List <FaceInfo>(); for (int i = 0; i < size; i++) { infos.Add(new FaceInfo() { Score = _socre[i], Location = new FaceRect() { X = _x[i], Y = _y[i], Width = _width[i], Height = _height[i] } }); } return(infos.ToArray()); }
/// <summary> /// 提取人脸特征值。 /// <para> /// 当 <see cref="FaceType"/> <see langword="="/> <see cref="FaceType.Normal"/> 时, 需要模型:<see langword="face_recognizer.csta"/><br/> /// 当 <see cref="FaceType"/> <see langword="="/> <see cref="FaceType.Mask"/> 时, 需要模型:<see langword="face_recognizer_mask.csta"/><br/> /// 当 <see cref="FaceType"/> <see langword="="/> <see cref="FaceType.Light"/> 时, 需要模型:<see langword="face_recognizer_light.csta"/><br/> /// </para> /// </summary> /// <param name="bitmap"></param> /// <param name="points"></param> /// <returns></returns> public float[] Extract(Bitmap bitmap, FaceMarkPoint[] points) { byte[] bgr = ImageSet.Get24BGRFromBitmap(bitmap, out int width, out int height, out int channels); float[] features; if (Platform64) { features = new float[ViewFacePlus64.ExtractSize((int)FaceType)]; } else { features = new float[ViewFacePlus32.ExtractSize((int)FaceType)]; } if (Platform64) { ViewFacePlus64.Extract(bgr, width, height, channels, points, features, (int)FaceType); } else { ViewFacePlus32.Extract(bgr, width, height, channels, points, features, (int)FaceType); } return(features); }