public void ProcessFrame(GameTime gameTime, Double elapsedTime) { Image <Bgr, Byte> image = _capture.QueryFrame().Flip(Emgu.CV.CvEnum.FLIP.HORIZONTAL); Image <Gray, Byte> gray = image.Convert <Gray, Byte>(); //Convert it to Grayscale //normalizes brightness and increases contrast of the image gray._EqualizeHist(); //If find faces is set and the Correct amount of time has passed if (this.FindFaces && (ReadFaceTime < elapsedTime + UpdateFaceFrameInterval)) { fd.ProcessFrame(ref image, ref gray, this.SetBitmap); ReadFaceTime = elapsedTime + UpdateFaceFrameInterval; } //If find motion is set and the correct amount of time has passed if (this.FindMotion && (ReadMotionTime < elapsedTime + UpdateMotionDetectorFrameInterval)) { md.ProcessFrame(ref image, this.SetBitmap, gameTime); ReadMotionTime = elapsedTime + UpdateMotionDetectorFrameInterval; } if (SetBitmap) { bimage = image.Bitmap; } }
private void videoSourcePlayer1_NewFrame(object sender, ref Bitmap image) { detectionLevel = detector.ProcessFrame(image); }
private async Task <MotionDetectionResult> DetectMotionAsync(Bitmap previousFrame, Bitmap currentFrame) { var stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); var result = _motionDetector.ProcessFrame(currentFrame); stopwatch.Stop(); MovementDirection xDirection = MovementDirection.None; MovementDirection yDirection = MovementDirection.None; if (result > DetectorConfiguration.Sensitivity) { var motionZonesList = new List <System.Drawing.Rectangle>(); for (int x = 0, i = 0; x < _processor.MotionGrid.GetLength(0); x++) { for (int y = 0; y < _processor.MotionGrid.GetLength(1); y++, i++) { if (_processor.MotionGrid[x, y] <= _processor.MotionAmountToHighlight) { continue; } motionZonesList.Add(new System.Drawing.Rectangle(new System.Drawing.Point(x, y), new System.Drawing.Size(new System.Drawing.Point(0)))); } } _motionDetector.MotionZones = motionZonesList.ToArray(); if (_motionDetector.MotionZones != null && _motionDetector.MotionZones.Length > 0) { var currentAverage = new System.Drawing.Point((int)_motionDetector.MotionZones.Average(x => x.Y), (int)_motionDetector.MotionZones.Average(x => x.X)); { if (currentAverage.X < _lastDetectionAveragePosition.X) { xDirection = MovementDirection.Left; } else { xDirection = MovementDirection.Right; } } if (currentAverage.Y < _lastDetectionAveragePosition.Y) { yDirection = MovementDirection.Up; } else { yDirection = MovementDirection.Down; } if (directionStopwatch.Elapsed.TotalMilliseconds > _directionDetectionTime) { _line.X1 = _lastDetectionAveragePosition.X * DetectionGrid.ActualWidth / DetectorConfiguration.Size; _line.Y1 = _lastDetectionAveragePosition.Y * DetectionGrid.ActualHeight / DetectorConfiguration.Size; directionStopwatch.Restart(); ResetDetector(); } _lastDetectionAveragePosition = currentAverage; _lastDirection = xDirection; _line.X2 = _lastDetectionAveragePosition.X * DetectionGrid.ActualWidth / DetectorConfiguration.Size; _line.Y2 = _lastDetectionAveragePosition.Y * DetectionGrid.ActualHeight / DetectorConfiguration.Size; ; XDirectionTextBlock.Text = xDirection.ToString(); YDirectionTextBlock.Text = yDirection.ToString(); } ResetDetector(); } return(new MotionDetectionResult() { Direction = (xDirection, yDirection), DetectionTimeMilliseconds = stopwatch.Elapsed.TotalMilliseconds });