private void DisplayVideo(object sender, ResultReadyEventArgs<Image<Bgr, byte>> e) { try { ImageBox imgBox = imgDebug; if (sender == invPerp) { Image<Bgr, byte> cam = new Image<Bgr, byte>(imgVideoSource.Image.Bitmap); imgOutput.Image = (Image<Bgr, byte>)e.Result + cam; return; } else if (sender == colorVideoSource) { imgBox = imgVideoSource; } if (imgBox == null) { System.Console.Out.WriteLine("No receiver registered!!"); return; } imgBox.Image = (Image<Bgr, byte>)e.Result; } catch (Exception ex) { System.Console.WriteLine("Bad thing happened in display video :( -" + ex.Message); } }
/// <summary> /// Process the worker result by extracting the coordinates and checking if a person has moved. /// </summary> /// <param name="sender">Worker thread.</param> /// <param name="e">Event arguments.</param> private void ResultReady(object sender, ResultReadyEventArgs e) { if (e.Result.GetCoordinates().HasValue) { Point currentCoordinates = e.Result.GetCoordinates().Value; // check if the person did move since the last result if (DidMove(currentCoordinates)) { // reset the countdown if it already started if (lastMove > 0) { lastMove = 0; manager.SetInstructions("Go to the position and stand still"); // if the configuration is currently in a different step, completely cancel the active step and start again if (!isActiveStep) { manager.Cancel(); manager.SetError("You moved during configuration. Restarting position."); Task.Delay(3000).ContinueWith(_ => { if (manager.IsTerminated()) { return; } System.Windows.Application.Current.Dispatcher.Invoke(() => manager.Start()); }); } } } else { if (lastMove == 0) { // if the person did not move and no countdown is set, start one lastMove = DateTimeOffset.Now.ToUnixTimeMilliseconds(); manager.SetInstructions("Calculating coordinates"); coordinates.Clear(); } else if (isActiveStep && DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastMove >= StandStillTime * 1000) { // proceed to the next step if the person stood still long enough manager.NextStep(); isActiveStep = false; } else if (isActiveStep) { coordinates.Add(currentCoordinates); } } lastCoordinates = currentCoordinates; } }
/// <summary> /// Update the current position when it changes. /// </summary> /// <param name="sender">Worker thread.</param> /// <param name="e">Event arguments.</param> private void ResultReady(object sender, ResultReadyEventArgs e) { if (e.Result.GetCoordinates().HasValue) { VolumeInterpolation volumeInterpolation = workerThread.GetVolumeInterpolation(); int scale = volumeInterpolation.GetScale(); Canvas.SetLeft(currentPosition, volumeInterpolation.MapCoordinate(e.Result.GetCoordinates().Value.X) * scale); Canvas.SetTop(currentPosition, (volumeInterpolation.Values.GetLength(1) - volumeInterpolation.MapCoordinate(e.Result.GetCoordinates().Value.Y)) * scale); } }
private void DisplayVideo(object sender, ResultReadyEventArgs<Image<Gray, Byte>> e) { try { ImageBox imgBox = imgDebug; imgBox.Image = (Image<Gray, Byte>)e.Result; } catch (Exception ex) { System.Console.WriteLine("Bad thing happened in display video :( -" + ex.Message); } }
private void DisplayVideo(object sender, ResultReadyEventArgs<Image<Bgr, byte>> e) { try { ImageBox big = imgVideoSource, small = imgDebug; if (swapImages) { ImageBox tmp = big; big = small; small = tmp; } if (sender == visRoad) big = imgOutput; if (sender == invPerp) { Image<Bgr, byte> cam = new Image<Bgr, byte>(big.Image.Bitmap); Image<Bgr, byte> res = (Image<Bgr, byte>)e.Result + cam; foreach (var p in probe) res.Draw(new CircleF(p, 10), new Bgr(0, 0, 255), -1); small.Image = res; return; } if (sender == kalmanFilteredRoadCenter) { //Image<Bgr, byte> cam = new Image<Bgr, byte>(big.Image.Bitmap); imgDebug3.Image = (Image<Bgr, byte>)e.Result;// +cam; return; } // colorVideoSource big.Image = (Image<Bgr, byte>)e.Result; if (videoWriter != null && sender == colorVideoSource) { videoWriter.WriteFrame(((Image<Bgr, byte>)e.Result).Convert<Bgr, byte>()); } } catch (Exception ex) { System.Console.WriteLine("Bad thing happened in display video :( -" + ex.Message); } }
/// <summary> /// Update the main window when the next result of the worker thread is ready. /// </summary> /// <param name="sender">Worker thread.</param> /// <param name="e">Event arguments.</param> private void ResultReady(object sender, ResultReadyEventArgs e) { // update coordinates text if (e.Result.GetCoordinates().HasValue) { coordinatesTextBlock.Text = "Point(" + e.Result.GetCoordinates().Value.X + ", " + e.Result.GetCoordinates().Value.Y + ")"; } // update the two camera frames if (e.Result.GetFrames() != null) { for (int i = 0; i < e.Result.GetFrames().Length; i++) { cameras.Keys.ElementAt(i).Source = e.Result.GetFrames()[i]; } } }
private void PassRoadModel(object sender, ResultReadyEventArgs<SimpleRoadModel> e) { SimpleRoadModel model = e.Result as SimpleRoadModel; if (model.center != null) ActualRoadModel.Invoke(this, new RoadModelEvent(model)); }