/// <summary>
        /// Post时调用
        /// </summary>
        public override void OnPost(HttpRequest request, HttpResponse response)
        {
            bool status = false;

            if (request.Operation == "verify")//添加一条数据
            {
                Log.Debug("比较图片");

                //OneVsOne
                if (request.RestConvention == "0")
                {
                    VerifyOneVsOne verify = VerifyOneVsOne.CreateInstanceFromJSON(request.PostParams);
                    if (verify != null)
                    {
                        Bitmap Bitmapsrc = BytesToBitmap(verify.PicSrc);
                        Bitmap Bitmapdst = BytesToBitmap(verify.PicDst);
                        double score     = fa.Compare(Bitmapsrc, Bitmapdst);

                        response.SetContent(JsonConvert.SerializeObject(score));
                    }
                }
                else
                {
                    VerifyOneVsN verify = VerifyOneVsN.CreateInstanceFromJSON(request.PostParams);
                    if (verify != null)
                    {
                        int DatasetId = Convert.ToInt32(request.RestConvention);
                        DataAngine_Set.Model.dataset ds = new DataAngine_Set.Model.dataset();
                        ds = bll.GetModel(DatasetId);

                        Bitmap Bitmapsrc = BytesToBitmap(verify.PicSrc);
                        fa.LoadData(ds.datasetname);
                        FRS.HitAlert[] hits = fa.Search(Bitmapsrc);
                        string         msg  = JsonConvert.SerializeObject(Model.HitAlert.CreateInstanceFromFRSHitAlert(hits));
                        response.SetContent(msg);
                    }
                }
            }
            response.Send();
        }
Exemple #2
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();
        }