/// <summary> /// Main Image Processing Unit Flow /// </summary> public override void Job() { _publisher.Dettach(this); Image <Gray, byte> image = _publisher.Data.Image; DateTime timestamp = _publisher.Data.Timestamp; if (timestamp != _lastFrameTimeStamp) { _lastFrameTimeStamp = timestamp; if (_isCallibrated) { //Start statisctics and stopwatch _detectionAnalyzer.Next(); //Call Tracker & Set new data to be taken by observers _ballTracker.InvokeTracking(image.Clone(), timestamp); //Stop statics and stopwatch _detectionAnalyzer.Finalize(_ballTracker.IsBallLocationFound); //Notify Observers BallLocationPublisher.UpdateAndNotify(); } else { //Call Callibrator _isCallibrated = _calibrator.InvokeCallibration(image); } } else { Log.Image.Error("We received same image twice. Good to check timestamp."); } _publisher.Attach(this); }
/// <summary> /// Image Processing Unit Constructor /// </summary> /// <param name="streamer">Video streamer to get frames from</param> /// <param name="onUpdateMarkup">Update markup function delegate</param> /// <param name="onUpdateStatistics">Update statistics delegate</param> public ImageProcessingUnit(Publisher <Frame> streamer, Helpers.UpdateMarkupCircleDelegate onUpdateMarkup, Helpers.UpdateStatisticsDelegate onUpdateStatistics) : base(streamer, onUpdateMarkup, onUpdateStatistics) { _calibrator = new CalibrationUnit(UpdateMarkup, UpdateStatistics); _ballTracker = new Tracker(_calibrator, _publisher, UpdateMarkup, UpdateStatistics); BallLocationPublisher = new BallLocationPublisher(_ballTracker); _lastFrameTimeStamp = DateTime.Now; _detectionAnalyzer = new DetectionStatisticAnalyzer(onUpdateStatistics); }