private async Task PredictBySource(MRCnnResponse lastPrediction, StreamSource streamSource) { try { lastPrediction.Working = true; Timer.Restart(); List <Rect> positions = await controls.AllSelected(streamSource.Id); var currentSourceId = streamSource.Id; var activeUrl = Enviroment.SourceImageRemote(streamSource); if (positions.Count == 0) { lastPrediction.Free = 0; lastPrediction.Total = 0; lastPrediction.Rects = new List <DrawRects>(); return; } var model = await SendRequest(lastPrediction, positions, activeUrl); var carDetections = model.Data .Where(x => x[1] == "car") .ToList(); // Save to history lastPrediction.AddPrediction(model); lastPrediction.Result = positions .Select(x => new DrawRects(x.x1, x.y1, x.x2, x.y2)) .ToList(); lastPrediction.Detected = model.Detected; // Format newest data lastPrediction.Total = positions.Count; lastPrediction.Free = model.Detected .Where(x => x < 0.4) .Count(); lastPrediction.Width = model.Width; lastPrediction.Height = model.Height; lastPrediction.SourceId = currentSourceId; lastPrediction.Miliseconds = (int)Timer.ElapsedMilliseconds; lastPrediction.Online = true; lastPrediction.ParseRects(model.Rects); } catch (Exception e) { lastPrediction.Online = false; } finally { lastPrediction.Working = false; } }
public async Task <ActionResult <List <Rect> > > AllSelected(int source) { return(await controls.AllSelected(source)); }