public ProcessFrame ( |
||
videoFrame | Video frame to process (detect motion in). | |
return | float |
private void frame(object s, NewFrameEventArgs e) { Bitmap img = (Bitmap)e.Frame.Clone(); Confidence = detector.ProcessFrame(img); pictureBox1.Image = img; }
private void videoSourcePlayer1_NewFrame(object sender, ref Bitmap image) { lock (this) { if (detector != null) { float motionLevel = detector.ProcessFrame(image); if (motionLevel > motionAlarmLevel) { // flash for 2 seconds flash = (int)(2 * (1000 / alarmTimer.Interval)); } // check objects' count if (detector.MotionProcessingAlgorithm is BlobCountingObjectsProcessing) { BlobCountingObjectsProcessing countingDetector = (BlobCountingObjectsProcessing)detector.MotionProcessingAlgorithm; detectedObjectsCount = countingDetector.ObjectsCount; } else { detectedObjectsCount = -1; } // accumulate history motionHistory.Add(motionLevel); if (motionHistory.Count > 300) { motionHistory.RemoveAt(0); } if (showMotionHistoryToolStripMenuItem.Checked) { DrawMotionHistory(image); } } } }
private void detectMovement(Bitmap b) { float motionLevel = 0; motionLevel = motionDetector.ProcessFrame(b); if (inWarmupMode || !running) { if (DateTime.Now.Ticks - warmupTime > warmupStartTime) { inWarmupMode = false; } return; } Rectangle[] i = ((AForge.Vision.Motion.BlobCountingObjectsProcessing)motionDetector.MotionProcessingAlgorithm).ObjectRectangles; if (i.Count() > 0) { Rectangle x1 = i.OrderByDescending(item => item.Height * item.Width).FirstOrDefault(); ClickBobber(x1); } }
//Загрузка формы private void ClientSettingsForm_Load(object sender, EventArgs e) { videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); if (videoDevices.Count == 0) { MessageBox.Show("Камера не найдена!"); isAppExit = true; Application.Exit(); } videoCamera = new VideoCaptureDevice(videoDevices[0].MonikerString); detector = new MotionDetector(new SimpleBackgroundModelingDetector(), new MotionAreaHighlighting()); if (this.videoCamera.IsRunning) this.videoCamera.Stop(); videoCamera.NewFrame += delegate(object send, AForge.Video.NewFrameEventArgs eventArgs) { //Отлавливаем движение if (detector.ProcessFrame(eventArgs.Frame) > 0.02) { if (client == null) return; client.SignalAlarmCmd(); } }; ClientSettingsFormExtracted(); }