Exemplo n.º 1
0
        public override void OnGet(HttpRequest request, HttpResponse response)
        {
            if (request.RestConvention != null)
            {
                Log.Debug(string.Format("返回ID:{0}人员库", request.RestConvention));

                int id = -1;
                try
                {
                    id = Convert.ToInt32(request.RestConvention);
                }
                catch
                {
                }
                PersonDataSet da = PersonDataSet.CreateInstanceFromDataAngineModel(bll.GetModel(id));
                if (null != da)
                {
                    response.SetContent(da.ToJson());
                }
            }
            else if (request.Domain != string.Empty)
            {
                Log.Debug(string.Format("返回所有库信息"));
                List <DataAngineSet.Model.person_dataset> datasets = bll.DataTableToList(bll.GetAllList().Tables[0]);
                response.SetContent(JsonConvert.SerializeObject(PersonDataSet.CreateInstanceFromDataAngineModel(datasets.ToArray())));
            }
            response.Send();
        }
Exemplo n.º 2
0
        public override void OnPost(HttpRequest request, HttpResponse response)
        {
            if (request.RestConvention != null)//根据ID获得数据库
            {
                Log.Debug(string.Format("返回数据库{0}的信息", request.RestConvention));
                int id = -1;
                try
                {
                    id = Convert.ToInt32(request.RestConvention);
                }
                catch
                {
                }

                SearchInfo searchinfo = SearchInfo.CreateInstanceFromJSON(request.PostParams);
                if (searchinfo != null)
                {
                    DataAngineSet.Model.person_dataset ds = new DataAngineSet.Model.person_dataset();
                    ds = person_datasetbll.GetModel(id);
                    //int num = bll.GetListByTime(searchinfo.StartTime, searchinfo.EndTime, ds.id.ToString()).Tables[0].Rows.Count;
                    HitAlertData[] ha = HitAlertData.CreateInstanceFromDataAngineDataSet(bll.GetListByTime(searchinfo.StartTime, searchinfo.EndTime, searchinfo.StartIndex, searchinfo.PageSize, ds.id.ToString()));

                    HitAlertData[] haALL = HitAlertData.CreateInstanceFromDataAngineDataSet(bll.GetListByTime_TaskId(searchinfo.StartTime, searchinfo.EndTime, ds.id.ToString()));
                    JObject        jo    = new JObject(new JProperty("num", haALL.Length), new JProperty("pageData", JsonConvert.DeserializeObject(JsonConvert.SerializeObject(ha))));

                    response.SetContent(JsonConvert.SerializeObject(jo));
                }
                //if(request.GetParams!=null)
                //{
                //    DateTime starttime=new DateTime();
                //    DateTime endtime=new DateTime();
                //    int startindex = 0;
                //    int pagesize = 30;
                //    starttime = Convert.ToDateTime(request.GetParams["starttime"]);
                //    endtime = Convert.ToDateTime(request.GetParams["endtime"]);
                //    startindex = Convert.ToInt32(request.GetParams["startindex"]);
                //    pagesize = Convert.ToInt32(request.GetParams["pagesize"]);
                //    HitAlertData[] ha = HitAlertData.CreateInstanceFromDataAngineDataSet(bll.GetListByTime(starttime, endtime, startindex, pagesize, library));
                //     response.SetContent(JsonConvert.SerializeObject(ha));

                //}
            }
            else
            {
                Log.Debug("轨迹查询");

                Trajectory_Search trajectory_search = Trajectory_Search.CreateInstanceFromJSON(request.PostParams);
                if (trajectory_search != null)
                {
                    HitAlertData_Trajectory_Search[] ha    = HitAlertData_Trajectory_Search.CreateInstanceFromDataAngineDataSet(bll.GetListById(trajectory_search.UserId, trajectory_search.StartTime, trajectory_search.EndTime, trajectory_search.StartIndex, trajectory_search.PageSize));
                    HitAlertData_Trajectory_Search[] haALL = HitAlertData_Trajectory_Search.CreateInstanceFromDataAngineDataSet(bll.GetListById(trajectory_search.UserId, trajectory_search.StartTime, trajectory_search.EndTime));
                    JObject jo = new JObject(new JProperty("num", haALL.Length), new JProperty("pageData", JsonConvert.DeserializeObject(JsonConvert.SerializeObject(ha))));

                    response.SetContent(JsonConvert.SerializeObject(jo));
                }
            }
            response.Send();
        }
Exemplo n.º 3
0
        bool Init(int taskID)
        {
            DataAngineSet.Model.surveillance_task task = taskBll.GetModel(taskID);
            if (null == task)
            {
                Log.Debug("检索任务失败"); return(false);
            }
            DataAngineSet.Model.device device = deviceBll.GetModel(task.device_id);
            if (null == device)
            {
                Log.Debug("检索设备失败"); return(false);
            }
            DataAngineSet.Model.person_dataset person_dataset = datasetBll.GetModel(task.person_dataset_id);
            if (null == person_dataset)
            {
                Log.Debug("检索库失败"); return(false);
            }

            InitFRS();
            fa.LoadData(person_dataset.id);
            cap.TaskID = taskID;
            cap.HitAlertReturnEvent += new Capture.HitAlertCallback(OnHit);


            int id = -1;

            try
            {
                Log.Debug(device.video_address);
                id = Convert.ToInt32(device.video_address);
            }
            catch
            {
            }
            if (id == -1)
            {
                if (cap.Start(device.video_address) != ReturnCode.SUCCESS)
                {
                    Log.Debug("打开摄像头失败");
                    return(false);
                }
            }
            else
            {
                if (cap.Start(id) != ReturnCode.SUCCESS)
                {
                    Log.Debug("打开摄像头失败");
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Post时调用
        /// </summary>
        public override void OnPost(HttpRequest request, HttpResponse response)
        {
            bool status = false;

            //OneVsOne
            if (request.RestConvention == "0")
            {
                Log.Debug("比较图片");
                //http://127.0.0.1:8080/v1/verify/0
                //VerifyOneVsOne verify = VerifyOneVsOne.CreateInstanceFromJSON(request.PostParams);
                string         result = Base64Decode(request.PostParams);
                VerifyOneVsOne verify = VerifyOneVsOne.CreateInstanceFromJSON(result);
                if (verify != null)
                {
                    double score = 0;
                    //初始化
                    InitFRS();
                    if (verify.PicSrc != null && verify.PicDst != null)
                    {
                        Bitmap Bitmapsrc = Base64ToImage(verify.PicSrc);
                        Bitmap Bitmapdst = Base64ToImage(verify.PicDst);

                        Bitmap bmpsrc = new Bitmap(Bitmapsrc.Width, Bitmapsrc.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                        Graphics.FromImage(bmpsrc).DrawImage(Bitmapsrc, new Rectangle(0, 0, bmpsrc.Width, bmpsrc.Height));

                        Bitmap bmpdst = new Bitmap(Bitmapdst.Width, Bitmapdst.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                        Graphics.FromImage(bmpdst).DrawImage(Bitmapdst, new Rectangle(0, 0, bmpdst.Width, bmpdst.Height));

                        Bitmapsrc.Save("Bitmapsrc.jpg");
                        Bitmapdst.Save("Bitmapdst.jpg");

                        score = fa.Compare(bmpsrc, bmpdst);
                        bmpsrc.Dispose();
                        bmpdst.Dispose();
                    }
                    else
                    {
                        //Image src = Image.FromFile(verify.PicSrc_Path);
                        Image src = Get_UrlImage(verify.PicSrc_Path);
                        //Image dst = Image.FromFile(verify.PicDst_Path);
                        Image dst = Get_UrlImage(verify.PicDst_Path);
                        score = fa.Compare(src, dst);
                    }


                    Log.Debug(string.Format("相似度:{0}", score));
                    response.SetContent(JsonConvert.SerializeObject(score));
                    //response.SetContent("0.8");
                }
            }
            else
            {
                Log.Debug("查找图片");
                //VerifyOneVsN verify = VerifyOneVsN.CreateInstanceFromJSON(request.PostParams);
                string       result = Base64Decode(request.PostParams);
                VerifyOneVsN verify = VerifyOneVsN.CreateInstanceFromJSON(result);
                if (verify != null)
                {
                    int DatasetId = Convert.ToInt32(request.RestConvention);
                    DataAngineSet.Model.person_dataset ds = new DataAngineSet.Model.person_dataset();
                    ds = bll.GetModel(DatasetId);

                    // 获取Post的阈值和top值
                    double ScoreThresh = Convert.ToDouble(verify.ScoreThresh);
                    int    TopK        = Convert.ToInt32(verify.TopK);

                    if (ScoreThresh == 0)
                    {
                        ScoreThresh = 0.6;
                    }
                    if (TopK == 0)
                    {
                        TopK = 3;
                    }


                    //初始化
                    InitFRS();
                    fa.LoadData(DatasetId);

                    Log.Debug(string.Format("初始阈值:{0}", fa.ScoreThresh));
                    Log.Debug(string.Format("初始top值:{0}", fa.TopK));

                    // 设置阈值和top值
                    fa.ScoreThresh = (float)ScoreThresh;
                    fa.TopK        = TopK;

                    Log.Debug(string.Format("设置阈值:{0}", fa.ScoreThresh));
                    Log.Debug(string.Format("设置top值:{0}", fa.TopK));

                    FRS.HitAlert[] hits;
                    if (verify.PicSrc != null)
                    {
                        Bitmap Bitmapsrc = Base64ToImage(verify.PicSrc);
                        Bitmap bmpsrc    = new Bitmap(Bitmapsrc.Width, Bitmapsrc.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                        Graphics.FromImage(bmpsrc).DrawImage(Bitmapsrc, new Rectangle(0, 0, bmpsrc.Width, bmpsrc.Height));
                        //Bitmapsrc.Save("Bitmapsrc.jpg");


                        hits = fa.Search(bmpsrc);
                        bmpsrc.Dispose();
                    }
                    else
                    {
                        //Image src = Image.FromFile(verify.PicSrc_Path);
                        Image src = Get_UrlImage(verify.PicSrc_Path);
                        hits = fa.Search(src);
                    }
                    string msg = JsonConvert.SerializeObject(Model.HitAlert.CreateInstanceFromFRSHitAlert(hits));
                    if (hits == null)
                    {
                        JObject jo = new JObject(new JProperty("num", 0));
                        response.SetContent(JsonConvert.SerializeObject(jo));
                    }
                    response.SetContent(msg);
                }
            }


            response.Send();
        }