Beispiel #1
0
        public static ParseObject TFSRequestRestful(Bitmap bImage)
        {
            ParseObject pObj      = null;
            int         im_width  = bImage.Width;
            int         im_height = bImage.Height;

            var httpWebRequest =
                (HttpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings["ServerHost2"]);

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                /*NDArray bitmapBytes = GetBitmapBytes2NDArray(bImage);*/
                string bitmapBytes = GetBitmapBytes2String(bImage);

                string json = "{\"instances\": " + bitmapBytes + "}";
                streamWriter.Write(json);
                streamWriter.Flush();
                streamWriter.Close();
            }

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                //Console.WriteLine(result.ToString());

                JObject jobj = JObject.Parse(result);

                var dtNumDetect = jobj["predictions"][0]["num_detections"].ToObject <int>();
                var dtClassList = jobj["predictions"][0]["detection_classes"].Select(x => (int)x).ToArray();
                var dtScoreList = jobj["predictions"][0]["detection_scores"].Select(x => (float)x).ToArray();

                // if only obj is human, it will send data
                float threshold = float.Parse(ConfigurationManager.AppSettings["Threshold"]);
                pObj = new ParseObject();
                //int ppc = 0;
                for (int pid = 0; pid < dtNumDetect; pid++)
                {
                    if ((dtClassList[pid] == 1) && (threshold <= dtScoreList[pid]))
                    {
                        pObj.NumOfDetect += 1;
                        //pObj.ScoreList.SetValue(dtScoreList[pid], ppc);
                        Boxes boxes       = new Boxes();
                        var   dtBoxesList = jobj["predictions"][0]["detection_boxes"][pid].Select(x => (float)x).ToArray();
                        boxes.BoxX1 = dtBoxesList[0] * im_height; //p1_height
                        boxes.BoxX2 = dtBoxesList[1] * im_width;  //p1_width
                        boxes.BoxY1 = dtBoxesList[2] * im_height; //p2_height
                        boxes.BoxY2 = dtBoxesList[3] * im_width;  //p2_width
                        pObj.BoxList.Add(boxes);
                        //ppc++;
                    }
                }
            }

            return(pObj);
        }
Beispiel #2
0
        public static ParseObject TestTFSRequestRestful(Bitmap bImage)
        {
            ParseObject pObj      = null;
            int         im_width  = bImage.Width;
            int         im_height = bImage.Height;

            pObj = new ParseObject();
            string res = "{\"predictions\": [{\"detection_scores\": [0.992537796, 0.0], " +
                         "\"detection_classes\": [1.0, 1.0], " +
                         "\"num_detections\": 1.0, " +
                         "\"detection_boxes\": [[0.0457661822, 0.0729743466, 0.957826436, 0.988076806], [0.0, 0.0, 0.0, 0.0]]}]}";
            JObject jobj = JObject.Parse(res);

            var   dtNumDetect = jobj["predictions"][0]["num_detections"].ToObject <int>();
            var   dtClassList = jobj["predictions"][0]["detection_classes"].Select(x => (int)x).ToArray();
            var   dtScoreList = jobj["predictions"][0]["detection_scores"].Select(x => (float)x).ToArray();
            float threshold   = float.Parse(ConfigurationManager.AppSettings["Threshold"]);

            for (int pid = 0; pid < dtNumDetect; pid++)
            {
                if ((dtClassList[pid] == 1) && (threshold <= dtScoreList[pid]))
                {
                    pObj.NumOfDetect += 1;
                    //pObj.ScoreList.SetValue(dtScoreList[pid], ppc);
                    Boxes boxes       = new Boxes();
                    var   dtBoxesList = jobj["predictions"][0]["detection_boxes"][pid].Select(x => (float)x).ToArray();
                    boxes.BoxX1 = dtBoxesList[0] * im_height; //p1_height
                    boxes.BoxX2 = dtBoxesList[1] * im_width;  //p1_width
                    boxes.BoxY1 = dtBoxesList[2] * im_height; //p2_height
                    boxes.BoxY2 = dtBoxesList[3] * im_width;  //p2_width
                    pObj.BoxList.Add(boxes);
                    //ppc++;
                }
            }
            return(pObj);
        }