Exemple #1
0
 public FaceData(FaceData f)
 {
     faceid       = f.faceid;
     userid       = f.userid;
     featureLenth = f.featureLenth;
     feature      = f.feature;
     angleType    = f.angleType;
     text         = f.text;
 }
Exemple #2
0
 public FaceInfo(FaceData fd)
 {
     this.faceid       = fd.faceid;
     this.userid       = fd.userid;
     this.feature      = fd.feature;
     this.featureLenth = fd.featureLenth;
     this.angleType    = fd.angleType;
     this.text         = fd.text;
 }
Exemple #3
0
        /// <summary>
        /// 更新已登记的人脸图片。
        /// </summary>
        /// <param name="f"></param>
        /// <param name="fd"></param>
        public void UpdateFacePicture(FaceInfo f, FaceData fd)
        {
            if (DataSource == DataSrcType.FileSystem)
            {
                //存储抓拍到的新图片,替换原始图片
                string savepath;
                int    uid = f.userid;
                switch (f.angleType)
                {
                case FaceData.FaceAngleType.Middle:
                    savepath = Path.GetDirectoryName(fd.text) + "\\"
                               + _FaceDic.GetUserName(uid) + "0.jpg";
                    break;

                case FaceData.FaceAngleType.Up:
                    savepath = Path.GetDirectoryName(fd.text) + "\\"
                               + _FaceDic.GetUserName(uid) + "1.jpg";
                    break;

                case FaceData.FaceAngleType.Down:
                    savepath = Path.GetDirectoryName(fd.text) + "\\"
                               + _FaceDic.GetUserName(uid) + "2.jpg";
                    break;

                case FaceData.FaceAngleType.Left:
                    savepath = Path.GetDirectoryName(fd.text) + "\\"
                               + _FaceDic.GetUserName(uid) + "3.jpg";
                    break;

                case FaceData.FaceAngleType.Right:
                    savepath = Path.GetDirectoryName(fd.text) + "\\"
                               + _FaceDic.GetUserName(uid) + "4.jpg";
                    break;

                default:
                    savepath = fd.text;
                    break;
                }
                Console.WriteLine("Save shot face: " + savepath);
                f.text = savepath;
                if (f.FaceShotBmp != null)
                {
                    f.FaceShotBmp.Save(savepath);
                }
            }
            else
            {
                //数据库更新
                //TODO
            }
        }
Exemple #4
0
        private void onFaceShotAndFindSame(FaceInfo f, FaceEvent.EventType t)
        {
            try
            {
                if (f == null)
                {
                    return;
                }
                if (f.userid != 0)
                {
                    return;
                }

                int      score = 0, uid = 0;
                FaceData fd = null;
                _LastFaceID = f.faceid;

                //数据库检索
                uid = FaceDic.FindSameFace(f, out score, out fd);

                if (uid != 0)
                {
                    //更新抓拍全景照片
                    updateFullViewBmp(f);
                    //更新抓拍特写照片
                    updateShotFace(f);
                    //显示检索到的照片
                    updateFoundPic(f, fd);
                    //在TracingList中标记相同人脸
                    f.text   = score.ToString();
                    f.userid = uid;

                    FaceEvent e = new FaceEvent
                    {
                        type     = t,
                        faceinfo = f,
                        //userid = uid,
                        //score = score
                    };
                    if (FaceHandler != null)
                    {
                        FaceHandler(e);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("FaceCamera->shotFaceAndFind:" + ex);
            }
        }
Exemple #5
0
 public Bitmap GetFaceOrgPic(FaceData fd)
 {
     if (DataSource == DataSrcType.FileSystem)
     {
         return(new Bitmap(Image.FromFile(fd.text)));
     }
     else if (DataSource == DataSrcType.DataBase)
     {
         return(GetFaceImage(fd.userid));//TODO
     }
     else
     {
         return(null);
     }
 }
Exemple #6
0
        private void updateFoundPic(FaceInfo f, FaceData fd)
        {
            if (f == null || fd == null)
            {
                return;
            }

            if (PicBoxFoundPic != null)
            {
                Action d = () =>
                {
                    PicBoxFoundPic.Image = Data.GetFaceOrgPic(fd);
                };
                PicBoxFoundPic.BeginInvoke(d);
            }
            //自动更新人脸字典数据结构
            if (FaceAutoUpdateOn && f.userid != 0)
            {
                Data.UpdateFacePicture(f, fd);
                FaceDic.AddFace(f.userid, f);
                Console.WriteLine("FaceCamera->AutoFaceDictionaryUpdate: uid=" + f.userid + "FaceAngleType=" + f.angleType);
            }
        }
Exemple #7
0
 public void UpdateFaceOrgPic(FaceData fd)
 {
 }
Exemple #8
0
        public int LoadFaceData(ProgressBar proBar)
        {
            try
            {
                if (!_isDBInitialized)
                {
                    return(ERROR_NOT_INIT);
                }
                int count = 0;
                int total = GetFaceCount();
                if (total == 0)
                {
                    Console.WriteLine("LoadFace no record, exit.");
                    return(0);
                }

                if (proBar != null)
                {
                    if (proBar.InvokeRequired)
                    {
                        Action a = () =>
                        {
                            proBar.Maximum = total;
                            proBar.Value   = 0;
                        };
                        proBar.Invoke(a);
                    }
                    else
                    {
                        proBar.Maximum = total;
                        proBar.Value   = 0;
                    }
                }

                //装载用户信息
                LoadUserInfo();

                //获取所有人脸信息
                MySqlDataReader reader = MySqlHelper.ExecuteReader(conn,
                                                                   "SELECT id,userid,featurelength,feature,angletype FROM " + FACE_TABLE_NAME);

                while (reader.Read())
                {
                    int    fid           = reader.GetInt32(reader.GetOrdinal("id"));
                    int    userid        = reader.GetInt32(reader.GetOrdinal("userid"));
                    int    featurelength = reader.GetInt32(reader.GetOrdinal("featurelength"));
                    byte[] feature       = new byte[featurelength];
                    reader.GetBytes(reader.GetOrdinal("feature"), 0, feature, 0, featurelength);
                    FaceData.FaceAngleType angletype = (FaceData.FaceAngleType)reader.GetInt32(reader.GetOrdinal("angletype"));


                    FaceData fd = new FaceData();
                    fd.faceid       = fid;
                    fd.userid       = userid;
                    fd.featureLenth = (short)featurelength;
                    fd.feature      = feature;
                    fd.angleType    = angletype;

                    _FaceDic.AddFace(userid, fd);

                    count++;
                    if (proBar != null)
                    {
                        if (proBar.InvokeRequired)
                        {
                            Action d = () =>
                            {
                                proBar.Value++;
                            };
                            proBar.Invoke(d);
                        }
                        else
                        {
                            proBar.Value++;
                        }
                    }
                }
                reader.Close();
                Console.WriteLine("LoadFace ok. read count={0}", count);
                return(count);
            }
            catch (Exception ex)
            {
                Console.WriteLine("DataAccess LoadFace Error. " + ex.Message);
                return(ERROR_DB_FAILED);
            }
        }
Exemple #9
0
        private void onFaceShotAndFind(FaceInfo f, FaceEvent.EventType t)
        {
            try
            {
                bool isSame = false;
                if (f != null && f.userid == 0)
                {
                    _LastFaceID = f.faceid;
                    //更新抓拍全景照片
                    updateFullViewBmp(f);
                    //更新抓拍特写照片
                    updateShotFace(f);

                    //数据库检索并显示检索到的照片
                    int      score = 0, uid = 0;
                    FaceData fd = null;
                    uid = FaceDic.FindMostSimilarFace(f, out score, out fd);
                    //在TracingList中标记相同人脸
                    if (score >= Face.SameFaceThreshold)
                    {
                        f.userid = uid;
                        isSame   = true;
                        //合并uid相同的人脸
                        FaceInfo mergeto;
                        if (Face.MergeTracingList(f, out mergeto))
                        {
                            //被合并后,需要删除
                            onRemoveFaceHander(f);
                            return;
                        }
                        else
                        {
                            isSame = true;
                        }
                    }
                    else
                    {
                        f.userid = 0;
                    }
                    f.text = score.ToString();
                    updateFoundPic(f, fd);
                }
                FaceEvent e = new FaceEvent
                {
                    type        = t,
                    faceinfo    = f,
                    isFoundSame = isSame
                                  //userid = uid,
                                  //score = score
                };
                if (SpeechEnable && isSame)
                {
                    //进行语音播报
                    string text = FaceDic.GetUserName(f.userid);
                    if (text.Trim().Length != 0)
                    {
                        text += ",你好。";
                        _Speech.SpeakAsync(text);
                    }
                }
                //回调上层
                if (FaceHandler != null)
                {
                    FaceHandler(e);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("FaceCamera->shotFaceAndFind:" + ex);
            }
        }