예제 #1
0
        /// <summary>
        /// 檔案讀取
        /// </summary>
        /// <param name="file">檔案路徑</param>
        /// <param name="list">臉部辨識資料</param>
        /// <param name="mapping">名稱對應資料</param>
        public static void Load(string file, ref List <RecognitionFaceData> list, ref List <NameMapping> mapping)
        {
            using (ZipFile zip = ZipFile.Read(file)) {
                var nameMappingReader = zip["NameMapping.bin"].OpenReader();
                mapping = NameMapping.FromBinary(StreamToBytes(nameMappingReader)).ToList();

                var faceDataReader = zip["FaceData.bin"].OpenReader();

                list = RecognitionFaceDataFile.FromBinary(StreamToBytes(faceDataReader)).ToList();
            }
            FormatData(list, mapping);
        }
예제 #2
0
        /// <summary>
        /// 檔案儲存
        /// </summary>
        /// <param name="file">檔案路徑</param>
        /// <param name="list">臉部辨識資料</param>
        /// <param name="mapping">名稱對應資料</param>
        public static void Save(string file, List <RecognitionFaceData> list, List <NameMapping> mapping)
        {
            FormatData(list, mapping);
            using (FileStream outputStream = new FileStream(file, FileMode.Create))
                using (ZipFile zip = new ZipFile()) {
                    zip.Comment =
                        "RealSenseFaceRecognition Database Files\r\n" +
                        "UTC Time: " + DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss") + "\r\n" +
                        "Guid: " + Guid.NewGuid();

                    zip.AddEntry("NameMapping.bin", NameMapping.ToBinary(mapping.ToArray()));
                    zip.AddEntry("FaceData.bin", list.ToArray().ToBinary());
                    zip.Save(outputStream);
                }
        }
예제 #3
0
        private void RegisterUser(PXCMFaceData faceOutput)
        {
            m_form.Register = false;
            if (faceOutput.QueryNumberOfDetectedFaces() <= 0)
            {
                return;
            }

            PXCMFaceData.Face qface = faceOutput.QueryFaceByIndex(0);
            if (qface == null)
            {
                throw new Exception("PXCMFaceData.Face null");
            }
            PXCMFaceData.RecognitionData rdata = qface.QueryRecognition();
            if (rdata == null)
            {
                throw new Exception(" PXCMFaceData.RecognitionData null");
            }
            #region 註冊視窗
            bool isRegistered = rdata.IsRegistered();//已註冊?
            int  realSenseId  = rdata.RegisterUser();
            var  collection   = faceOutput.QueryRecognitionModule()
                                .GetDatabase()
                                .Where(x => x.ForeignKey == realSenseId);
            var dbItem = collection.LastOrDefault();
            if (realSenseId == -1)
            {
                return;
            }
            if (isRegistered)
            {
                //已註冊的畫面卻又重新註冊,可能是辨識錯誤的更正
                List <RecognitionFaceData> faceData =
                    faceOutput.QueryRecognitionModule()
                    .GetDatabase().ToList();

                dbItem                       = faceData.Last();
                dbItem.ForeignKey            = dbItem.PrimaryKey + 100;//校正Id
                faceData[faceData.Count - 1] = dbItem;

                //整理資料庫的錯誤
                FaceDatabaseFile.FormatData(faceData, NameMapping);
                qrecognition.SetDatabase(faceData.ToArray());
            }

            var registerForm = new RegisterForm()
            {
                Picture = dbItem.Image
            };

            if (registerForm.ShowDialog() == DialogResult.OK)
            {
                var mapping = NameMapping.Where(x => x.Id == registerForm.Id).FirstOrDefault();
                if (mapping == null)
                {
                    mapping = new NameMapping()
                    {
                        Id   = registerForm.Id,
                        Name = registerForm.Name
                    };
                    NameMapping.Add(mapping);
                }
                if (registerForm.Name.Length > 0)
                {
                    mapping.Name = registerForm.Name;
                }
                mapping.DataIds.Add(dbItem.ForeignKey);
            }
            #endregion
        }