Exemplo n.º 1
0
        /// <summary>
        /// 加载xml数据
        /// </summary>
        public static FaceCompareInfo FaceCompareTotalInfoLoad(string fileName)
        {
            FaceCompareInfo faceCompareInfo = new FaceCompareInfo();

            try
            {
                string filePathStr = string.Format(@"{0}\FaceCompareXmlFile", Environment.CurrentDirectory);
                string fileNameStr = string.Format(@"{0}\{1}", filePathStr, fileName);

                if (File.Exists(fileNameStr))
                {
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(fileNameStr);
                    XmlNode success = xmlDoc.SelectSingleNode("Total/compareSuccess");
                    XmlNode Fail    = xmlDoc.SelectSingleNode("Total/compareFail");

                    if (success != null && !string.IsNullOrWhiteSpace(success.InnerText))
                    {
                        faceCompareInfo.CompareSuccess = int.Parse(success.InnerText);
                    }

                    if (Fail != null && !string.IsNullOrWhiteSpace(Fail.InnerText))
                    {
                        faceCompareInfo.CompareFail = int.Parse(Fail.InnerText);
                    }
                }
            }
            catch (Exception ex)
            {
                RecordSystemErrorLog(typeof(ToolHelper).FullName, MethodBase.GetCurrentMethod().Name, ex.Message, ex.StackTrace);
            }
            return(faceCompareInfo);
        }
        public void Timer1CallBack(object sender, ElapsedEventArgs e)
        {
            try
            {
                if (faceCompareInfoList != null && faceCompareInfoList.Count > 0)
                {
                    FaceCompareInfo faceCompareInfo = faceCompareInfoList.FirstOrDefault(x => !x.isShow);

                    if (faceCompareInfo != null && !string.IsNullOrWhiteSpace(faceCompareInfo.CompareImage))
                    {
                        if (!string.IsNullOrWhiteSpace(faceCompareInfo.CompareImage))
                        {
                            bool result = onProcessEvent(faceCompareInfo.CompareImage, faceCompareInfo.PersonName,
                                                         faceCompareInfo.Sex == "男" ? "先生" : (faceCompareInfo.Sex == "女" ? "女士" : ""));
                            faceCompareInfo.isShow = result;

                            if (result)
                            {
                                ToolHelper.RecordSystemInfoLog(this.GetType().ToString(), MethodBase.GetCurrentMethod().Name, string.Format("{0}显示成功", faceCompareInfo.PersonName));
                            }
                            else
                            {
                                ToolHelper.RecordSystemErrorLog(this.GetType().ToString(), MethodBase.GetCurrentMethod().Name,
                                                                string.Format("{0}显示失败", faceCompareInfo.PersonName), JsonConvert.SerializeObject(faceCompareInfo));
                            }
                        }
                    }
                    else
                    {
                        if (timer1.Enabled)
                        {
                            timer1.Enabled = false;
                        }
                        ToolHelper.RecordSystemInfoLog(this.GetType().ToString(), MethodBase.GetCurrentMethod().Name, JsonConvert.SerializeObject(faceCompareInfo));
                    }
                }
                else
                {
                    if (timer1.Enabled)
                    {
                        timer1.Enabled = false;
                    }
                    ToolHelper.RecordSystemInfoLog(this.GetType().ToString(), MethodBase.GetCurrentMethod().Name, "faceCompareInfoList.Count为0");
                }
            }
            catch (Exception ex)
            {
                ToolHelper.RecordSystemErrorLog(this.GetType().ToString(), MethodBase.GetCurrentMethod().Name, ex.Message, ex.StackTrace);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 加载xml数据
        /// </summary>
        public static List <FaceCompareInfo> FaceCompareInfoLoad(string fileName)
        {
            List <FaceCompareInfo> faceCompareInfoList = new List <FaceCompareInfo>();

            try
            {
                string filePathStr = string.Format(@"{0}\FaceCompareXmlFile", Environment.CurrentDirectory);
                string fileNameStr = string.Format(@"{0}\{1}", filePathStr, fileName);

                if (File.Exists(fileNameStr))
                {
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(fileNameStr);
                    XmlNodeList userList = xmlDoc.SelectNodes("Users/User");

                    if (userList != null && userList.Count > 0)
                    {
                        FaceCompareInfo faceCompareInfoItem = null;

                        foreach (XmlNode item in userList)
                        {
                            faceCompareInfoItem = new FaceCompareInfo();
                            faceCompareInfoItem.CaputerDeviceIp  = item.SelectSingleNode("caputerDeviceIp").InnerText;
                            faceCompareInfoItem.Channel          = item.SelectSingleNode("channel").InnerText;
                            faceCompareInfoItem.CaptureTime      = item.SelectSingleNode("captureTime").InnerText;
                            faceCompareInfoItem.SimilarityDegree = item.SelectSingleNode("similarityDegree").InnerText;
                            faceCompareInfoItem.PersonName       = item.SelectSingleNode("personName").InnerText;
                            faceCompareInfoItem.AlarmTime        = item.SelectSingleNode("alarmTime").InnerText;
                            faceCompareInfoItem.AlarmDeviceIp    = item.SelectSingleNode("alarmDeviceIp").InnerText;
                            faceCompareInfoItem.Sex          = item.SelectSingleNode("sex").InnerText;
                            faceCompareInfoItem.Glasses      = item.SelectSingleNode("glasses").InnerText;
                            faceCompareInfoItem.FaceScore    = item.SelectSingleNode("faceScore").InnerText;
                            faceCompareInfoItem.BigImage     = item.SelectSingleNode("bigImage").InnerText;
                            faceCompareInfoItem.FaceImage    = item.SelectSingleNode("faceImage").InnerText;
                            faceCompareInfoItem.CompareImage = item.SelectSingleNode("compareImage").InnerText;
                            faceCompareInfoItem.TelePhone    = item.SelectSingleNode("telePhone").InnerText;

                            faceCompareInfoList.Add(faceCompareInfoItem);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                RecordSystemErrorLog(typeof(ToolHelper).FullName, MethodBase.GetCurrentMethod().Name, ex.Message, ex.StackTrace);
            }
            return(faceCompareInfoList);
        }
        private void UpdateXmlFile(CHCNetSDK.NET_DVR_ALARMER pAlarmer, CHCNetSDK.NET_VCA_FACESNAP_MATCH_ALARM struFaceMatchAlarm, string filePath,
                                   string fileName, Dictionary <string, string> imagePath)
        {
            try
            {
                Dictionary <string, string> keyValue = new Dictionary <string, string>();
                string nodeType   = string.Empty;
                string sex        = string.Empty;
                string telephone  = string.Empty;
                string personName = string.Empty;

                //抓拍时间:年月日时分秒
                string strTimeYear   = ((struFaceMatchAlarm.struSnapInfo.dwAbsTime >> 26) + 2000).ToString();
                string strTimeMonth  = ((struFaceMatchAlarm.struSnapInfo.dwAbsTime >> 22) & 15).ToString("d2");
                string strTimeDay    = ((struFaceMatchAlarm.struSnapInfo.dwAbsTime >> 17) & 31).ToString("d2");
                string strTimeHour   = ((struFaceMatchAlarm.struSnapInfo.dwAbsTime >> 12) & 31).ToString("d2");
                string strTimeMinute = ((struFaceMatchAlarm.struSnapInfo.dwAbsTime >> 6) & 63).ToString("d2");
                string strTimeSecond = ((struFaceMatchAlarm.struSnapInfo.dwAbsTime >> 0) & 63).ToString("d2");
                string strTime       = string.Format("{0}-{1}-{2} {3}:{4}:{5}", strTimeYear, strTimeMonth, strTimeDay, strTimeHour, strTimeMinute, strTimeSecond);

                //比对成功
                if ((struFaceMatchAlarm.struBlackListInfo.dwBlackListPicLen != 0) && (struFaceMatchAlarm.struBlackListInfo.pBuffer1 != IntPtr.Zero))
                {
                    nodeType = "compareSuccess";
                    string[] strArray = Encoding.Default.GetString(struFaceMatchAlarm.struBlackListInfo.struBlackListInfo.struAttribute.byName).Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);

                    if (strArray != null && strArray.Length > 2)
                    {
                        personName = strArray[0].Split('\0')[0];
                        sex        = strArray[1].Split('\0')[0];
                        telephone  = strArray[2].Split('\0')[0];
                    }
                    else
                    {
                        personName = Encoding.Default.GetString(struFaceMatchAlarm.struBlackListInfo.struBlackListInfo.struAttribute.byName).Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries)[0];
                    }
                }
                else
                {
                    nodeType = "compareFail";
                }

                if (nodeType == "compareSuccess") //比对成功要去重
                {
                    if (faceCompareInfoList != null && faceCompareInfoList.Count > 0)
                    {
                        List <FaceCompareInfo> selectList = faceCompareInfoList.FindAll(x => x.PersonName == personName);
                        if (selectList != null && selectList.Count > 0)
                        {
                            return;
                        }
                    }
                }

                keyValue.Add("caputerDeviceIp", struFaceMatchAlarm.struSnapInfo.struDevInfo.struDevIP.sIpV4);                                                    //抓拍设备
                keyValue.Add("channel", struFaceMatchAlarm.struSnapInfo.struDevInfo.byChannel.ToString());                                                       //通道号
                keyValue.Add("captureTime", strTime);                                                                                                            //抓拍时间
                keyValue.Add("similarityDegree", Convert.ToString(struFaceMatchAlarm.fSimilarity));                                                              //相似度
                keyValue.Add("personName", personName);                                                                                                          //姓名
                keyValue.Add("alarmTime", DateTime.Now.ToString());                                                                                              //报警时间
                keyValue.Add("alarmDeviceIp", pAlarmer.sDeviceIP);                                                                                               //报警设备
                keyValue.Add("sex", sex);                                                                                                                        //性别
                keyValue.Add("glasses", struFaceMatchAlarm.struSnapInfo.byGlasses == 1 ? "是" : (struFaceMatchAlarm.struSnapInfo.byGlasses == 2 ? "否" : "无法确认")); //眼镜
                keyValue.Add("faceScore", struFaceMatchAlarm.struSnapInfo.byFaceScore.ToString());                                                               //人脸清晰
                keyValue.Add("bigImage", imagePath["bigImage"]);                                                                                                 //抓拍大图
                keyValue.Add("faceImage", imagePath["faceImage"]);                                                                                               //抓拍头像
                keyValue.Add("compareImage", imagePath["compareImage"]);                                                                                         //人脸比对照片
                keyValue.Add("telePhone", telephone);                                                                                                            //电话

                bool isSuccess = ToolHelper.SaveXmlFile(filePath, fileName, keyValue, nodeType);

                if (isSuccess)
                {
                    if (nodeType == "compareSuccess")
                    {
                        FaceCompareInfo faceCompareInfoItem = new FaceCompareInfo();
                        faceCompareInfoItem.CaputerDeviceIp  = struFaceMatchAlarm.struSnapInfo.struDevInfo.struDevIP.sIpV4;
                        faceCompareInfoItem.Channel          = struFaceMatchAlarm.struSnapInfo.struDevInfo.byChannel.ToString();
                        faceCompareInfoItem.CaptureTime      = strTime;
                        faceCompareInfoItem.SimilarityDegree = Convert.ToString(struFaceMatchAlarm.fSimilarity);
                        faceCompareInfoItem.PersonName       = personName;
                        faceCompareInfoItem.AlarmTime        = DateTime.Now.ToString();
                        faceCompareInfoItem.AlarmDeviceIp    = pAlarmer.sDeviceIP;
                        faceCompareInfoItem.Sex          = sex;
                        faceCompareInfoItem.Glasses      = struFaceMatchAlarm.struSnapInfo.byGlasses == 1 ? "是" : (struFaceMatchAlarm.struSnapInfo.byGlasses == 2 ? "否" : "无法确认");
                        faceCompareInfoItem.FaceScore    = struFaceMatchAlarm.struSnapInfo.byFaceScore.ToString();
                        faceCompareInfoItem.BigImage     = imagePath["bigImage"];
                        faceCompareInfoItem.FaceImage    = imagePath["faceImage"];
                        faceCompareInfoItem.CompareImage = imagePath["compareImage"];
                        faceCompareInfoItem.TelePhone    = telephone;

                        faceCompareInfoList.Add(faceCompareInfoItem);

                        if (!timer1.Enabled)
                        {
                            timerCallBackAction(new object(), null);
                            timer1.Enabled = true;
                        }
                    }

                    if (!ToolHelper.SaveXmlFile(filePath, fileName, nodeType))
                    {
                        ToolHelper.RecordSystemErrorLog(this.GetType().ToString(), MethodBase.GetCurrentMethod().Name, "更新汇总XML文件失败", nodeType);
                    }
                }
                else
                {
                    ToolHelper.RecordSystemErrorLog(this.GetType().ToString(), MethodBase.GetCurrentMethod().Name, "更新XML文件失败", JsonConvert.SerializeObject(keyValue));
                }
            }
            catch (Exception ex)
            {
                ToolHelper.RecordSystemErrorLog(this.GetType().ToString(), MethodBase.GetCurrentMethod().Name, ex.Message, ex.StackTrace);
            }
        }