Esempio n. 1
0
        public async Task <List <BoundBox> > Predict(Frame frame)
        {
            var list   = new List <BoundBox>();
            var status = await _client.GetStatusAsync();

            if (status == null || !status.Contains("server is running"))
            {
                Console.WriteLine("server is not active");
                return(list);
            }

            var jsonImg = new JsonImage();

            jsonImg.Load(frame.Patch);
            var json       = JsonConvert.SerializeObject(jsonImg);
            var outputText = await _client.PostAsync(json, "image");

            if (!string.IsNullOrEmpty(outputText))
            {
                foreach (var line in outputText.Split(Environment.NewLine))
                {
                    if (!line.StartsWith("output="))
                    {
                        continue;
                    }
                    var output = line.Split(' ');
                    var x1     = int.Parse(output[1]);
                    var y1     = int.Parse(output[2]);
                    var x2     = int.Parse(output[3]);
                    var y2     = int.Parse(output[4]);
                    var score  = output[6];
                    var label  = output[5];
                    var rect   = new BoundBox(
                        x1,
                        y1,
                        y2 - y1,
                        x2 - x1);
                    list.Add(rect);
                    Console.WriteLine($">{label}: {score}");
                }
            }
            return(list);
        }
Esempio n. 2
0
        public async Task <List <BoundBox> > Predict(Frame frame)
        {
            var list   = new List <BoundBox>();
            var status = await _client.GetStatusAsync();

            if (status == null || !status.Contains("server is running"))
            {
                Console.WriteLine("server is not active");
                return(list);
            }

            var jsonImg = new JsonImage();

            jsonImg.Load(frame.Patch);
            var json       = JsonConvert.SerializeObject(jsonImg);
            var outputText = await _client.PostAsync(json, "image");

            var objects = JsonConvert.DeserializeObject <JsonAnnotation>(outputText);

            if (objects != null || objects.Objects.Count > 0)
            {
                Console.WriteLine("File {0} contains:", Path.GetFileName(frame.Patch));
                foreach (var ooj in objects.Objects)
                {
                    var x1    = ooj.Xmin;
                    var y1    = ooj.Ymin;
                    var x2    = ooj.Xmax;
                    var y2    = ooj.Ymax;
                    var score = ooj.Score;
                    var label = ooj.Name;
                    var rect  = new BoundBox(
                        x1,
                        y1,
                        y2 - y1,
                        x2 - x1);
                    list.Add(rect);
                    Console.WriteLine("\t{0}: {1:P1}", label, double.Parse(score.Replace('.', ',')));
                }
            }
            return(list);
        }