/// <summary> /// 人脸对齐,返回识别到的人脸数量。 /// </summary> /// <param name="bitmap">图片</param> /// <param name="faces">人脸对齐的结果</param> /// <returns></returns> public static int Alignment(Bitmap bitmap, ref AlignmentResult[] faces) { Bitmap bmp = BitmapTo24Rgb(bitmap); //将图像转换为24位rgb图像 bmp.SetResolution(96, 96); //设置dpi=96 byte[] imageByte = BitmapToByteBuffer(bmp, out int width, out int height, out int stride); StringBuilder json = new StringBuilder(1500); int faceCount = SDK.AlignmentByte(imageByte, width, height, stride, json); if (faceCount > 0) { JsonSerializer serializer = new JsonSerializer(); faces = serializer.Deserialize <AlignmentResult[]>(new JsonTextReader(new StringReader(json.ToString()))); return(faceCount); } else { faces = new AlignmentResult[0]; return(faceCount); } }
/// <summary> /// 检测图片中的人脸,返回识别到的人脸的数量。 /// </summary> /// <param name="path">图片的路径</param> /// <param name="faceInfo">识别到的第一张人脸</param> /// <returns></returns> public static int DetectFace(string path, ref FaceInfo faceInfo) { return(SDK.DetectFace(path, ref faceInfo)); }
/// <summary> /// 设置日志回调函数 /// </summary> /// <param name="logCallBack"></param> public static void SetDisplayLog(LogCallBack logCallBack) => SDK.SetDisplayLog(logCallBack);
/// <summary> /// 初始化人脸识别 /// </summary> /// <returns></returns> public static bool Init() => SDK.Init();
//公共方法 /// <summary> /// 设置人脸模型的目录 /// </summary> /// <param name="modelPath"></param> public static void SetModelDirectory(string modelPath) => SDK.SetModelDirectory(Encoding.Default.GetBytes(modelPath));
/// <summary> /// 计算人脸特征码相似度。 /// </summary> /// <param name="feat1">人脸特征码1</param> /// <param name="feat2">人脸特征码2</param> /// <returns></returns> public static double CalcSimilarity(float[] feat1, float[] feat2) => SDK.CalcSimilarity(feat1, feat2);
/// <summary> /// 提取人脸特征码。 /// </summary> /// <param name="path">图片路径</param> /// <param name="alignmentResult">要提取特征码的人脸的对齐结果</param> /// <param name="feat">特征码</param> /// <returns></returns> public static bool ExtractFeature(string path, ref AlignmentResult alignmentResult, float[] feat) { return(SDK.ExtractFeature(path, ref alignmentResult, feat)); }