/// <summary> /// Update the motion history with the specific image and the specific timestamp /// </summary> /// <param name="foregroundMask">The foreground of the image to be added to history</param> /// <param name="timestamp">The time when the image is captured</param> public void Update(Mat foregroundMask, DateTime timestamp) { _lastTime = timestamp; TimeSpan ts = _lastTime.Subtract(_initTime); if (_mhi == null) { _mhi = new Mat(foregroundMask.Rows, foregroundMask.Cols, DepthType.Cv32F, 1); } CvInvoke.UpdateMotionHistory(foregroundMask, _mhi, ts.TotalSeconds, _mhiDuration); double scale = 255.0 / _mhiDuration; _mhi.ConvertTo(_mask, DepthType.Cv8U, scale, (_mhiDuration - ts.TotalSeconds) * scale); CvInvoke.CalcMotionGradient(_mhi, _mask, _orientation, _maxTimeDelta, _minTimeDelta); }