コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // 设置APPID/AK/SK
            var APP_ID     = ConfigurationManager.AppSettings["APP_ID"];
            var API_KEY    = ConfigurationManager.AppSettings["API_KEY"];
            var SECRET_KEY = ConfigurationManager.AppSettings["SECRET_KEY"];

            var    client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            string imgsrc = " D:/Project/Git/C#/AI/FaceRecognition/FaceRecognitionTest/FaceRecognition/BaiDu/FaceRecognition/img/ldh.jpg";
            var    image  = File.ReadAllBytes(imgsrc);
            // 调用人脸检测,可能会抛出网络等异常,请使用try/catch捕获
            var result = client.FaceDetect(image);

            //{ "result_num": 1, "result": [ { "location": { "left": 112, "top": 202, "width": 280, "height": 256 }, "face_probability": 1, "rotation_angle": 4, "yaw": -10.597146034241, "pitch": 4.6834144592285, "roll": 4.6553287506104 } ], "log_id": 3473511017011916 }{ "result_num": 1, "result": [ { "location": { "left": 112, "top": 202, "width": 280, "height": 256 }, "face_probability": 1, "rotation_angle": 4, "yaw": -10.597146034241, "pitch": 4.6834144592285, "roll": 4.6553287506104, "age": 26 } ], "log_id": 3474425141011916 }
            Response.Write(result);
            // 如果有可选参数
            var options = new Dictionary <string, object> {
                { "max_face_num", 2 },
                { "face_fields", "age" }
            };

            // 带参数调用人脸检测
            result = client.FaceDetect(image, options);
            Response.Write(result);
        }
コード例 #2
0
 public static void FaceDetect()
 {
     var client  = new Baidu.Aip.Face.Face("Api Key", "Secret Key");
     var image   = File.ReadAllBytes("图片文件路径");
     var options = new Dictionary <string, object>()
     {
         { "face_fields", "beauty,age" }
     };
     var result = client.FaceDetect(image, options);
 }
コード例 #3
0
        public static void FaceDetect()
        {
            var client  = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var image   = File.ReadAllBytes(filename);
            var options = new Dictionary <string, object>()
            {
                { "face_fields", "beauty,age" }
            };
            var result = client.FaceDetect(image, options)["result"];

            MessageBox.Show(result.ToString());
        }
コード例 #4
0
        public static String GetFaceDetectResult(string imgPath)
        {
            var client  = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var image   = File.ReadAllBytes(imgPath);
            var options = new Dictionary <string, object>()
            {
                { "face_fields", "beauty,age" }
            };
            // 调用图像主体检测
            var result = client.FaceDetect(image, options);

            return(result.ToString());
        }