Exemplo n.º 1
0
        public static String UserInfo(string uid)
        {
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var result = client.User.GetInfo(uid);

            return(result.ToString());
        }
Exemplo n.º 2
0
        protected static void Search()
        {
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);

            client.Timeout = 60000;  // 修改超时时间
            var image = "";

            using (var s = new FileStream("C:/Users/admin/Desktop/微信图片_20190107152711.jpg", FileMode.Open))
            {
                image = ComFunc.StreamToBase64String(s);
            }


            var imageType = "BASE64";

            var groupIdList = "F001";

            // 调用人脸搜索,可能会抛出网络等异常,请使用try/catch捕获
            var result = client.Search(image, imageType, groupIdList);

            Console.WriteLine(result);
            // 如果有可选参数
            //        var options = new Dictionary<string, object>{
            //    {"quality_control", "NORMAL"},
            //    {"liveness_control", "LOW"},
            //    {"user_id", "233451"},
            //    {"max_user_num", 3}
            //};
            //        // 带参数调用人脸搜索
            //        result = client.Search(image, imageType, groupIdList, options);
            //        Console.WriteLine(result);
        }
Exemplo n.º 3
0
        protected static void UserAdd()
        {
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);

            client.Timeout = 60000;  // 修改超时时间
            var image = ComFunc.StreamToBase64String(new FileStream("C:/Users/admin/Desktop/2.jpg", FileMode.Open));

            var imageType = "BASE64";

            var groupId = "F001";

            var userId = "F0001";

            // 调用人脸注册,可能会抛出网络等异常,请使用try/catch捕获
            var result = client.UserAdd(image, imageType, groupId, userId);

            Console.WriteLine(result);
            //        // 如果有可选参数
            //        var options = new Dictionary<string, object>{
            //    {"user_info", "user's info"},
            //    {"quality_control", "NORMAL"},
            //    {"liveness_control", "LOW"}
            //};
            //        // 带参数调用人脸注册
            //        result = client.UserAdd(image, imageType, groupId, userId, options);
            //        Console.WriteLine(result);
        }
Exemplo n.º 4
0
        protected static void Detect()
        {
            // 设置APPID/AK/SK
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);

            client.Timeout = 60000;  // 修改超时时间


            var image = ComFunc.StreamToBase64String(new FileStream("C:/Users/admin/Desktop/微信图片_20190104172518.jpg", FileMode.Open));

            var imageType = "BASE64";

            // 调用人脸检测,可能会抛出网络等异常,请使用try/catch捕获
            //var result = client.Detect(image, imageType);
            //Console.WriteLine(result);
            // 如果有可选参数
            var options = new Dictionary <string, object> {
                { "face_field", "age,beauty,expression,faceshape,gender,glasses,landmark,race,quality,facetype" },
                { "max_face_num", 2 },
                { "face_type", "LIVE" }
            };
            // 带参数调用人脸检测
            var result = client.Detect(image, imageType, options);

            Console.WriteLine(result);
        }
Exemplo n.º 5
0
        public static void PersonVerify()
        {
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);

            client.Timeout = 60000;  // 修改超时时间
            var image = ComFunc.StreamToBase64String(new FileStream("C:/Users/admin/Desktop/2.jpg", FileMode.Open));

            var imageType = "BASE64";

            var idCardNumber = "420104198108172011";

            var name = "张三";

            // 调用身份验证,可能会抛出网络等异常,请使用try/catch捕获
            var result = client.PersonVerify(image, imageType, idCardNumber, name);

            Console.WriteLine(result);
            // 如果有可选参数
            //        var options = new Dictionary<string, object>{
            //    {"quality_control", "NORMAL"},
            //    {"liveness_control", "LOW"}
            //};
            //        // 带参数调用身份验证
            //        result = client.PersonVerify(image, imageType, idCardNumber, name, options);
            //        Console.WriteLine(result);
        }
Exemplo n.º 6
0
Arquivo: FaceDemo.cs Projeto: ly2018/t
        public static void FaceVerify()
        {
            var client = new Baidu.Aip.Face.Face(AiKeySecret.ApiKey, AiKeySecret.SecretKey);
            var image1 = File.ReadAllBytes("图片文件路径");

            var result = client.User.Verify(image1, "uid", new [] { "groupId" }, 1);
        }
        public static void FaceRegister()
        {
            var client = new Baidu.Aip.Face.Face("Api Key", "Secret Key");
            var image1 = File.ReadAllBytes("图片文件路径");

            var result = client.User.Register(image1, "uid", "user info here", new [] { "groupId" });
        }
        public static void FaceUpdate()
        {
            var client = new Baidu.Aip.Face.Face("Api Key", "Secret Key");
            var image1 = File.ReadAllBytes("图片文件路径");

            var result = client.User.Update(image1, "uid", "groupId", "new user info");
        }
Exemplo n.º 9
0
        /// <summary>
        /// 人脸匹配
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public JObject NetFaceMatch(Image image)
        {
            try
            {
                var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY)
                {
                    Timeout = 60000  // 修改超时时间
                };

                //图片转为Base64
                string base64 = ImageToBase64(image);

                string        imageType = "BASE64";
                List <string> groupList = new List <string>();

                groupList.Add("UsualUser");
                groupList.Add("StarUser");

                string  group  = string.Join(",", groupList.ToArray());
                JObject result = client.Search(base64, imageType, group);
                return(result);
            }
            catch (Exception ex)
            {
                MessageBox.Show("连接人脸识别API出错:" + ex);
                return(new JObject());
            }
        }
        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);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 人脸注册
        /// </summary>
        /// <param name="image"></param>
        /// <param name="groupId"></param>
        /// <param name="userId"></param>
        /// <param name="info"></param>
        /// <returns></returns>
        public JObject NetFaceRegister(Image image, string groupId, string userId, string info)
        {
            try
            {
                var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY)
                {
                    Timeout = 60000  // 修改超时时间
                };

                //图片转为Base64
                string base64    = ImageToBase64(image);
                string imageType = "BASE64";

                var options = new Dictionary <string, object>
                {
                    { "user_info", info },
                    { "quality_control", "NORMAL" },
                    { "liveness_control", "NONE" }
                };
                JObject result = client.UserAdd(base64, imageType, groupId, userId, options);
                return(result);
            }
            catch (Exception ex)
            {
                MessageBox.Show("人脸录入出错:" + ex);
                return(new JObject());
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// 人脸识别
        /// </summary>
        /// <param name="image">人脸图片</param>
        /// <returns></returns>
        public JObject NetRecognition(Image image)
        {
            try
            {
                var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY)
                {
                    Timeout = 60000  // 修改超时时间
                };

                //图片转为Base64
                Bitmap       bmp = new Bitmap(image);
                MemoryStream ms  = new MemoryStream();
                bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                byte[] arr = new byte[ms.Length]; ms.Position = 0;
                ms.Read(arr, 0, (int)ms.Length); ms.Close();
                var base64 = Convert.ToBase64String(arr);

                string imageType = "BASE64";
                //可选参数
                var options = new Dictionary <string, object> {
                    { "face_field", "age,beauty,gender" },
                    { "max_face_num", 1 },
                    { "face_type", "LIVE" }
                };
                JObject result = client.Detect(base64, imageType, options);
                return(result);
            }
            catch (Exception ex)
            {
                MessageBox.Show("连接人脸识别API出错:" + ex);
                return(new JObject());
            }
        }
Exemplo n.º 13
0
        public static void GroupList()
        {
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var result = client.Group.GetAllGroups(0, 100);

            MessageBox.Show(result.ToString());
        }
Exemplo n.º 14
0
 /// <summary>
 /// 构造
 /// </summary>
 /// <param name="_Req"></param>
 public BusinessBIDU(XAIReqBase _Req)
 {
     if (BIDUClientCache.Where(w => w.Key == _Req.AppCode).Count() == 0)
     {
         lock (BIDUClientCache)
         {
             using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.FACEDb)._DataAccess)
             {
                 var dbApp = dbContext.DbApp(_Req.AppCode);
                 if (dbApp != null)
                 {
                     client = new Baidu.Aip.Face.Face(dbApp.AppKey.ToString(), dbApp.AppSecret.ToString())
                     {
                         Timeout = 60000  // 修改超时时间
                     };
                     BIDUClientCache.AddOrUpdate(_Req.AppCode, client, (key, value) => value);
                 }
                 else
                 {
                     throw new Exception("Missing app config or not activated!");
                 }
             }
         }
     }
     else
     {
         client = BIDUClientCache.Where(w => w.Key == _Req.AppCode).FirstOrDefault().Value;
     }
 }
Exemplo n.º 15
0
        void method()
        {
            // 设置APPID/AK/SK
            var APP_ID     = "16604945";
            var API_KEY    = "qTvV0EqG1Mmaavs9wIGzNBPS";                //你的 Api Key
            var SECRET_KEY = "wwckh4CQm2NR5tEZPu0nzNmSzg9Q3KDT";        //你的 Secret Key
            var client     = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);

            client.Timeout = 60000;  // 修改超时时间


            //取决于image_type参数,传入BASE64字符串或URL字符串或FACE_TOKEN字符串
            //你共享的图片路径(点击路径可直接查看图片)
            var image     = "http://b117.photo.store.qq.com/psb?/V10bnVD11OXPw5/QWpK4tAnWQ0G2t*V7d.MYQXiAoniZpYvqqjGn5kPoPA!/c/dHUAAAAAAAAA&bo=nAU4BJ0FOAQRECY!&rf=mood_app";
            var imageType = "URL";


            //注册人脸
            var groupId = "group1";
            var userId  = "user1";
            // 调用人脸注册,可能会抛出网络等异常,请使用try/catch捕获
            var result = client.UserAdd(image, imageType, groupId, userId);

            Console.WriteLine(result);
            // 如果有可选参数
            var options = new Dictionary <string, object> {
                { "user_info", "user's info" },
                { "quality_control", "NORMAL" },
                { "liveness_control", "LOW" }
            };

            // 带参数调用人脸注册
            result = client.UserAdd(image, imageType, groupId, userId, options);
            Console.WriteLine(result);
        }
Exemplo n.º 16
0
        public static void FaceIdentify()
        {
            var client = new Baidu.Aip.Face.Face("Api Key", "Secret Key");
            var image1 = File.ReadAllBytes("图片文件路径");

            var result = client.User.Identify(image1, new [] { "groupId" }, 1, 1);
        }
Exemplo n.º 17
0
        public static void FaceDelete()
        {
            var client = new Baidu.Aip.Face.Face("Api Key", "Secret Key");
            var result = client.User.Delete("uid");

            result = client.User.Delete("uid", new [] { "group1" });
        }
Exemplo n.º 18
0
 public BaiduUser()
 {
     this.APP_ID     = "你的APP_ID";
     this.API_KEY    = "你的API_KEY";
     this.SECRET_KEY = "你的SECRET_KEY";
     this.client     = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
     client.Timeout  = 60000;
 }
Exemplo n.º 19
0
        public static void UserInfo()
        {
            uid = str1;
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var result = client.User.GetInfo(uid);

            MessageBox.Show(result.ToString());
        }
Exemplo n.º 20
0
 public FaceRecognition(IOptions <ApiConfig> apiConfig, ILogger <FaceRecognition> logger)
 {
     _logger = logger;
     _client = new Baidu.Aip.Face.Face(apiConfig.Value.API_KEY, apiConfig.Value.SECRET_KEY)
     {
         Timeout = 60000
     };
 }
Exemplo n.º 21
0
        public static void GroupUsers()
        {
            gid = str1;
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var result = client.Group.GetUsers(gid, 0, 100);

            MessageBox.Show(result.ToString());
        }
Exemplo n.º 22
0
        public static String FaceDelete(string imgpath, string uid, string groupId)
        {
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var result = client.User.Delete(uid);

            result = client.User.Delete(uid, new[] { groupId });
            return(result.ToString());
        }
Exemplo n.º 23
0
        public BaiDuApiHelper()
        {
            if (this.Client == null)
            {
                Client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            }

            //Client.Timeout = 60000;//修改超时时间
        }
Exemplo n.º 24
0
        public static String FaceRegister(string imgpath, string uid, string groupId)
        {
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var image1 = File.ReadAllBytes(imgpath);

            var result = client.User.Register(image1, uid, "user info here", new[] { groupId });

            return(result.ToString());
        }
Exemplo n.º 25
0
        public static String FaceUpdate(string imgpath, string uid, string groupId)
        {
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var image1 = File.ReadAllBytes(imgpath);

            var result = client.User.Update(image1, uid, groupId, "new user info");

            return(result.ToString());
        }
Exemplo n.º 26
0
        public static String GetFaceVerify(string imgpath, string uid, string groupId)
        {
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var image1 = File.ReadAllBytes(imgpath);

            var result = client.User.Verify(image1, uid, new[] { groupId }, 1);

            return(result.ToString());
        }
Exemplo n.º 27
0
        public static void GroupDeleteUser()
        {
            uid = str1;
            gid = str2;
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var result = client.Group.DeleteUser(new[] { gid }, uid);

            MessageBox.Show(result.ToString());
        }
Exemplo n.º 28
0
        public static void FaceDelete()
        {
            uid = str1;
            gid = str2;
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var result = client.User.Delete(uid, new[] { gid });

            MessageBox.Show(result.ToString());
        }
Exemplo n.º 29
0
        public static void GroupAddUser()
        {
            toGroupId   = str1;
            uid         = str2;
            fromGroupId = str3;
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var result = client.Group.AddUser(new[] { toGroupId }, uid, fromGroupId);

            MessageBox.Show(result.ToString());
        }
Exemplo n.º 30
0
        public static void FaceMatch()
        {
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var image1 = File.ReadAllBytes(filename1);
            var image2 = File.ReadAllBytes(filename2);
            var images = new byte[][] { image1, image2 };
            var result = client.FaceMatch(images);

            MessageBox.Show(result.ToString());
        }