Exemple #1
0
        //组列表查询
        public static void GroupList()
        {
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var result = client.Group.GetAllGroups(0, 100);

            group_list = result.ToString();
        }
Exemple #2
0
        public static void FaceVerify()
        {
            var client = new Face.Face(API_KEY, SECRET_KEY);
            var image1 = File.ReadAllBytes("图片文件路径");

            var result = client.User.Verify(image1, "uid", new[] { "groupId" }, 1);
        }
Exemple #3
0
        public static void FaceUpdate()
        {
            var client = new Face.Face(API_KEY, SECRET_KEY);
            var image1 = File.ReadAllBytes("图片文件路径");

            var result = client.User.Update(image1, "uid", "groupId", "new user info");
        }
Exemple #4
0
        /// <summary>
        /// 进行人脸库的搜索,根据人脸检测的结果中的face
        /// </summary>
        /// <returns></returns>
        private string FaceSearch(FaceCheckResult faceResult)
        {
            var client = new Baidu.Aip.Face.Face(appKey, sKey);
            //这里根据face_token搜索,其实没必要使用 m:n 方式,因为token只对应一个人脸
            var result = client.Search(faceResult.face_token, "FACE_TOKEN", "group1");

            if (result != null && JsonConvert.DeserializeObject <int>(result["error_code"].ToString()) == 0)
            {
                var    userList   = JsonConvert.DeserializeObject <List <SearchResult> >(result["result"]["user_list"].ToString());
                int    index      = 1;
                string strAllUser = "";
                foreach (var item in userList)
                {
                    if (item.Score > 80.0)
                    {
                        this.listView1.Items.Add(new ListViewItem(new string[]
                        {
                            index++.ToString(),
                            item.Group_id,
                            item.User_id,
                            item.User_info
                        }));
                        strAllUser += item.User_info + ",";
                        InsertSignTime(item.Group_id, item.User_id, item.User_info, DateTime.Now);
                    }
                }
                return(strAllUser);
            }
            else
            {
                return("");
            }
        }
Exemple #5
0
        public static JObject FaceDelete(string uid, string groupId = "group1")
        {
            var client = new Face.Face(API_KEY, SECRET_KEY);
            var result = client.User.Delete(uid);

            result = client.User.Delete(uid, new[] { groupId });
            return(result);
        }
Exemple #6
0
        //用户信息查询
        public static void UserInfo()
        {
            user_ifo_uid = Form3.str;
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var result = client.User.GetInfo(user_ifo_uid);

            user_ifo = result.ToString();
        }
Exemple #7
0
        //组内用户列表查询
        public static void GroupUsers()
        {
            group_users_gid = Form3.str;
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var result = client.Group.GetUsers(group_users_gid, 0, 100);

            group_users = result.ToString();
        }
Exemple #8
0
        public static JObject FaceIdentify(string imagePath, string groupId = "groupId")
        {
            var client = new Face.Face(API_KEY, SECRET_KEY);
            var image1 = File.ReadAllBytes(imagePath);

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

            return(result);
        }
Exemple #9
0
        public static JObject FaceRegister(string imagePath, string uid, string userInfo, string groupId = "groupId")
        {
            var client = new Face.Face(API_KEY, SECRET_KEY);
            var image1 = File.ReadAllBytes(imagePath);

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

            return(result);
        }
Exemple #10
0
        //人脸检测
        public static void FaceMatch()
        {
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var image1 = File.ReadAllBytes(Form1.filename1);
            var image2 = File.ReadAllBytes(Form1.filename2);
            var images = new byte[][] { image1, image2 };
            var result = client.FaceMatch(images);

            face_match = result.ToString();
        }
Exemple #11
0
        //人脸识别
        public static void FaceIdentify()
        {
            face_identify_gid = Form3.str;
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var image1 = File.ReadAllBytes(Form1.filename1);
            //,1,1什么作用?
            var result = client.User.Identify(image1, new[] { face_identify_gid }, 1, 1);

            FaceIdentify_scores = result.ToString();
        }
Exemple #12
0
        //人脸更新
        public static void FaceUpdate()
        {
            face_update_uid  = Form4.str1;
            face_update_gid  = Form4.str3;
            face_update_uifo = Form4.str2;
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var image1 = File.ReadAllBytes(Form1.filename1);
            var result = client.User.Update(image1, face_update_uid, face_update_gid, face_update_uifo);

            face_update = result.ToString();
        }
Exemple #13
0
        //人脸删除 如果没有指定group_id则会删除该用户的所有图像和身份信息
        public static void FaceDelete()
        {
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);

            face_delete_uid = Form5.str1;
            face_delete_gid = Form5.str2;
            var result = client.User.Delete(face_delete_uid);

            result      = client.User.Delete(face_delete_uid, new[] { face_delete_gid });
            face_delete = result.ToString();
        }
Exemple #14
0
        //人脸认证
        public static void FaceVerify()
        {
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            //MessageBox.Show(Form1.filename1);
            var image1 = File.ReadAllBytes(Form1.filename1);

            face_verify_uid = Form5.str1;
            face_verify_gid = Form5.str2;
            var result = client.User.Verify(image1, face_verify_uid, new[] { face_verify_gid }, 1)["result"][0];

            face_verify = result.ToString();
        }
Exemple #15
0
        //人脸注册
        public static void FaceRegister()
        {
            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var image1 = File.ReadAllBytes(Form1.filename1);

            face_register_uid  = Form4.str1;
            face_register_uifo = Form4.str2;
            face_register_gid  = Form4.str3;
            var result = client.User.Register(image1, face_register_uid, face_register_uifo, new[] { face_register_gid })["log_id"];

            log_id = result.ToString();
        }
Exemple #16
0
        public static void FaceMatch()
        {
            var client = new Face.Face(API_KEY, SECRET_KEY);
            var image1 = File.ReadAllBytes("图片文件路径");
            var image2 = File.ReadAllBytes("图片文件路径");
            var image3 = File.ReadAllBytes("图片文件路径");

            var images = new[] { image1, image2, image3 };

            // 人脸对比
            var result = client.FaceMatch(images);
        }
Exemple #17
0
        public static JObject FaceDetect(string imagePath)
        {
            var client  = new Face.Face(API_KEY, SECRET_KEY);
            var image   = File.ReadAllBytes(imagePath);
            var options = new Dictionary <string, object>
            {
                { "face_fields", "age,beauty,expression,faceshape,gender,glasses,landmark,race,qualities" }
            };
            var result = client.FaceDetect(image, options);

            return(result);
        }
Exemple #18
0
        public static void FaceDetect()
        {
            var client  = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
            var image   = File.ReadAllBytes(Form1.filename1);
            var options = new Dictionary <string, object>()
            {
                { "face_fields", "beauty,age" }
            };
            var result = client.FaceDetect(image, options)["result"];

            text = result.ToString();
            MessageBox.Show(text);
        }
Exemple #19
0
 public static void UserInfo()
 {
     var client = new Face.Face(API_KEY, SECRET_KEY);
     var result = client.User.GetInfo("uid");
 }
Exemple #20
0
 public BaiduFace()
 {
     client         = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
     client.Timeout = 60000;
 }
Exemple #21
0
 public void renew()
 {
     client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);
 }
Exemple #22
0
 public static void GroupDeleteUser()
 {
     var client = new Face.Face(API_KEY, SECRET_KEY);
     var result = client.Group.DeleteUser(new[] { "groupId" }, "uid");
 }
Exemple #23
0
        /// <summary>
        /// 点击注册
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btRegist_Click(object sender, EventArgs e)
        {
            // 设置APPID/AK/SK
            var APP_ID     = "14976181";
            var API_KEY    = "v6gNCmUGTHzdkUVP0XI7ksaG";
            var SECRET_KEY = "YPqgbFV9T0qmEGbnvMKYGPHeGw5exW5F";

            var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY);

            client.Timeout = 60000;  // 修改超时时间
                                     //输入值检测返回值
            bool res = true;

            label9.Text       = "带*为必填项";
            label9.ForeColor  = Color.Black;
            label10.ForeColor = Color.Black;
            label11.ForeColor = Color.Black;
            label12.ForeColor = Color.Black;
            label13.ForeColor = Color.Black;
            label14.ForeColor = Color.Black;
            res = CheckInput();
            if (res == false)
            {
                MySqlConnection myconn = new MySqlConnection("Host=" + host +
                                                             ";Database=" + database +
                                                             ";Username="******";Password="******";");
                FileStream fs         = File.OpenRead(tbPhotoPath.Text); //OpenRead
                int        filelength = 0;
                filelength = (int)fs.Length;                             //获得文件长度 
                Byte[] imgData64 = new Byte[filelength];                 //建立一个字节数组 
                fs.Read(imgData64, 0, filelength);                       //按字节流读取 
                                                                         //System.Drawing.Image result = System.Drawing.Image.FromStream(fs);
                fs.Close();
                //图片转BASE64码
                var image = Convert.ToBase64String(imgData64);
                //文件格式
                var imageType = "BASE64";
                //注册人脸用户组
                var groupId = "User";
                //注册人脸用户号
                var userId = tbTel.Text;
                //人脸注册返回结果
                bool userAddCheck = false;

                try
                {
                    // 如果有可选参数
                    var options = new Dictionary <string, object> {
                        { "quality_control", "NORMAL" },
                        { "liveness_control", "LOW" }
                    };
                    // 调用人脸注册,可能会抛出网络等异常,请使用try/catch捕获
                    var    get_result   = client.UserAdd(image, imageType, groupId, userId, options);
                    string index_resilt = get_result.ToString();
                    MessageBox.Show(index_resilt);
                    //判断注册情况
                    int index_add   = index_resilt.IndexOf("SUCCESS");
                    int index_exist = index_resilt.IndexOf("exist");
                    //注册成功,添加人脸图片
                    if (index_add != -1 || index_exist != -1)
                    {
                        //添加人脸图片
                        get_result = client.UserUpdate(image, imageType, groupId, userId, options);
                        MessageBox.Show(get_result.ToString());
                        index_resilt = get_result.ToString();
                        int index_update = index_resilt.IndexOf("SUCCESS");
                        if (index_update != -1)
                        {
                            userAddCheck = true;    //人脸图片添加成功
                        }
                    }
                }
                catch (FieldAccessException face_ex)
                {
                    MessageBox.Show(face_ex.ToString());
                }

                string sex = null;
                if (rbMan.Checked == Enabled)
                {
                    sex = rbMan.Text;
                }
                else if (rbWoman.Checked == Enabled)
                {
                    sex = rbWoman.Text;
                }

                if (userAddCheck == true)
                {
                    myconn.Open();
                    MySqlTransaction transaction = myconn.BeginTransaction();//事务必须在try外面赋值不然catch里的
                    try
                    {
                        string sql = "SELECT count(*) FROM userInfo";

                        //开启连接
                        MySqlCommand cmd = new MySqlCommand(sql, myconn);

                        Object get_count = cmd.ExecuteScalar();
                        int    count     = int.Parse(get_count.ToString()) + 1;
                        cmd.CommandText = "insert into userInfo values(@userID,@userName,@authority,@passwd,@sex,@tel,@qq,@email,@birthday,@recodeDate);";
                        cmd.Parameters.AddRange(new[] {
                            new MySqlParameter("@userID", count),                                   //用户序号
                            new MySqlParameter("@userName", tbUserName.Text),                       //用户名
                            new MySqlParameter("@authority", tbTel.Text),                           //用户识别号
                            new MySqlParameter("@passwd", tbPasswd.Text),                           //用户密码
                            new MySqlParameter("@sex", sex),                                        //性别
                            new MySqlParameter("@tel", tbTel.Text),                                 //电话(识别码)
                            new MySqlParameter("@qq", tbQQ.Text),                                   //QQ
                            new MySqlParameter("@email", tbMail.Text),                              //邮箱
                            new MySqlParameter("@birthday", dtBirthday.Value.ToString("yyyy年MM月dd日")),
                            new MySqlParameter("recodeDate", DateTime.Now.ToString("yyyy年MM月dd日 HH时mm分"))
                        });
                        //MessageBox.Show(cmd.CommandText.ToString());
                        cmd.ExecuteNonQuery();
                        //事务要么回滚要么提交,即Rollback()与Commit()只能执行一个
                        transaction.Commit();

                        label9.Text      = "信息正确,注册成功!";
                        label9.ForeColor = Color.Black;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                        transaction.Rollback(); //事务ExecuteNonQuery()执行失败报错,username被设置unique
                                                //关闭连接,以免数据库被锁
                        myconn.Dispose();
                        myconn.Close();
                        label9.Text      = "注册失败!";
                        label9.ForeColor = Color.Red;
                    }
                    finally
                    {
                        //关闭连接,以免数据库被锁
                        myconn.Dispose();
                        myconn.Close();
                    }
                }
            }
        }
Exemple #24
0
 public static void GroupAddUser()
 {
     var client = new Face.Face(API_KEY, SECRET_KEY);
     var result = client.Group.AddUser(new[] { "toGroupId" }, "uid", "fromGroupId");
 }
Exemple #25
0
 public static void GroupUsers()
 {
     var client = new Face.Face(API_KEY, SECRET_KEY);
     var result = client.Group.GetUsers("groupId", 0, 100);
 }
Exemple #26
0
 public static void GroupList()
 {
     var client = new Face.Face(API_KEY, SECRET_KEY);
     var result = client.Group.GetAllGroups(0, 100);
 }
Exemple #27
0
        /// <summary>
        /// 人脸检测,进行红框绘制
        /// </summary>
        /// <returns></returns>
        private void FaceCheck(object objImagePath)
        {
            try
            {
                string strImagePath = (string)objImagePath;
                var    client       = new Baidu.Aip.Face.Face(appKey, sKey);

                var image = Convert.ToBase64String(File.ReadAllBytes(strImagePath));

                var imageType = "BASE64";

                var options = new Dictionary <string, object> {
                    {
                        "max_face_num", 5
                    }
                };
                // 带参数调用人脸检测
                var result = client.Detect(image, imageType, options);
                Console.WriteLine(result);

                //如果有人脸,则将图片加载到识别结果中
                if (int.Parse(result["result"]["face_num"].ToString()) > 0)
                {
                    this.BeginInvoke(new Action(() =>
                    {
                        //清空之前的查询结果
                        this.listView1.Items.Clear();
                        //直接从内存中拿数据,不用再读写磁盘数据,即将base64转为stream
                        byte[] imageBytes = Convert.FromBase64String(image);
                        using (MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
                        {
                            ms.Write(imageBytes, 0, imageBytes.Length);
                            this.pictureBox2.Image = Image.FromStream(ms, true);

                            //根据返回的人脸数据进行红框的绘制
                            Image img = pictureBox2.Image;

                            var faceArr        = JsonConvert.DeserializeObject <List <FaceCheckResult> >(result["result"]["face_list"].ToString());
                            string strAllUsers = "";
                            foreach (var item in faceArr)
                            {
                                Graphics g    = Graphics.FromImage(img);
                                Pen pen       = new Pen(Color.Red, 3);
                                pen.DashStyle = DashStyle.Solid;
                                g.RotateTransform(item.location.rotation);
                                g.TranslateTransform((float)item.location.left, (float)item.location.top, MatrixOrder.Append);
                                g.DrawRectangle(pen, new Rectangle(0, 0, (int)item.location.width, (int)item.location.height));

                                g.Dispose();
                                strAllUsers += FaceSearch(item);
                            }
                            if (!string.IsNullOrEmpty(strAllUsers))
                            {
                                Thread tVoice = new Thread(VoiceBroadcast);
                                tVoice.Start("你好," + strAllUsers);
                            }
                        };
                    }));
                }
            }
            catch (Exception exp)
            {
                return;
            }
        }