public List <BoundBox> GetAndBoxes() { var result = new List <BoundBox>(); foreach (var obj in Objects) { var box = new BoundBox( obj.Box.Xmin, obj.Box.Ymin, obj.Box.Ymax - obj.Box.Ymin, obj.Box.Xmax - obj.Box.Xmin ); result.Add(box); } return(result); }
public async Task <List <BoundBox> > Predict(Frame frame) { var list = new List <BoundBox>(); // Instantiate Machine Learning C# - Python class object IMlSharpPython mlSharpPython = new MlSharpPython("python3"); // Test image string imagePathName = ""; var appPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); var modelPatch = $"{appPath}/python/snapshots/resnet50_liza_alert_v1_interface.h5"; // Define Python script file and input parameter name string fileNameParameter = $"{appPath}/python/inference.py --model {modelPatch} --image {frame.Patch}"; // Execute the python script file var outputText = await Task.Run(() => mlSharpPython.ExecutePythonScript(fileNameParameter)); 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); }
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); }
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); }