/// <summary>
        /// 检测图片中的人脸,返回识别到的人脸数量。
        /// </summary>
        /// <param name="bitmap">图片</param>
        /// <param name="faceInfos">识别到的所有人脸的信息</param>
        /// <returns></returns>
        public static int DetectFaces(Bitmap bitmap, ref FaceInfo[] faceInfos)
        {
            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(500);
            int            faceCount  = SDK.DetectFacesByte(imageByte, width, height, stride, json);
            JsonSerializer serializer = new JsonSerializer();

            if (faceCount > 0)
            {
                faceInfos = serializer.Deserialize <FaceInfo[]>(new JsonTextReader(new StringReader(json.ToString())));
                return(faceCount);
            }
            else
            {
                faceInfos = new FaceInfo[0];
                return(faceCount);
            }
        }
Exemple #2
0
 public extern static int DetectFaceByte(byte[] imageByte, int width, int height, int stride, ref FaceInfo faceInfo);
Exemple #3
0
 public extern static int DetectFace(string path, ref FaceInfo faceInfo);
 /// <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));
 }