public override void OnProcessing(Frame current) { if (buffer == null || !current.SameSizeAs(buffer.First)) { buffer = new FrameBuffer(framesNeeded, current.Width, current.Height); } var result = new MotionProcessorResult(); //Check for duplicate frames, and assume previous result for them if (buffer.Count > 0 && !current.IsDifferentFrom(buffer.First)) { current.ProcessorResult = (MotionProcessorResult)buffer.First.ProcessorResult; current.IsReadyForRender = true; return; } if (buffer.Count == framesNeeded) { buffer.RemoveFirst(); } buffer.Enqueue(current); if (buffer.Count == framesNeeded) { var prev = buffer.First; var roi = new System.Windows.Rect ( new Point(current.Width * LeftBoundPCT, current.Height * TopBoundPCT), new Point(current.Width * RightBoundPCT, current.Height * BottomBoundPCT) ); var changedPixels = current.ChangeExtentPoints(prev, Threshold, roi); result.Threshold = Threshold; result.ChangedPixels = changedPixels; result.ChangedPixelsCount = changedPixels.Count; result.Frame = current; result.FrameIndex = current.FrameIndex; result.FrameTime = current.FrameTime; } current.ProcessorResult = result; current.IsReadyForRender = true; }
private void EnqueueStandardHeadClip() { var isDuplicate = queue.Count > 0 && !currentFrame.IsDifferentFrom(queue.Last); //Don't add duplicates to frame history if (isDuplicate) { return; } //Subclip head subclippedHead.DrawFrame(currentFrame, 0, 0, 1, 0, Space.HeadOffset.X, Space.HeadOffset.Y); //Resize to standard into stdHeadClip subclippedHead.ScaleHQ(Space.StandardWidth, Space.StandardHeight, stdHeadClip.Bitmap); //We're computing T-1 frame's antenna positions //T-2 frame should be the last frame part of the background if (queue.Count >= FastMotionHistLength - 1) { //Because T has not been added yet, T-2 is still T-1 var forBackground = queue.GetNthBeforeLast(1); //BG update takes a while, do it in parallel backgroundUpdater = new Thread(() => { //Add to background queue background.Append(forBackground); }); backgroundUpdater.Start(); } //Enque into the buffer //Remove oldest frame if (queue.Count >= FastMotionHistLength) { queue.RemoveFirst(); } //Add new one queue.Enqueue(stdHeadClip); }