Exemple #1
0
        private void CompleteImageComarision(string actualImageContainer, string actualImage, string referenceImage, string referenceImageContainer)
        {
            var df             = new BlobStorageService();
            var motionDetector = new MotionDetector();

            motionDetector.ProcessFrame(df.ReadImageContent(referenceImage, referenceImageContainer));
            var result = new ImageComparisionResult();

            result.UploadImageAfterProcess(motionDetector.ProcessFrame(df.ReadImageContent(actualImage, actualImageContainer)), actualImageContainer, actualImage);
        }
        protected override void DoWork()
        {
            FireRequestMainStream();
            Thread.Sleep(100);

            if (!_mainStream)
            {
                return;
            }

            BlobCountingObjectsProcessing motionProcessing = new BlobCountingObjectsProcessing(5, 2);
            MotionDetector detector = new MotionDetector(new TwoFramesDifferenceDetector(), motionProcessing);

            int i = 0;

            while (i < 5 && _mainStream)
            {
                using (Bitmap backgroundFrame = (Bitmap)ScreenCapture.CaptureWindow(_hWnd))
                {
                    detector.MotionZones = new Rectangle[] { ImageProcessing.GetRectangleAreaFromCenter(backgroundFrame, 35) };

                    detector.ProcessFrame(backgroundFrame.FilterForBlackTags());

                    AutoClickHandlers.SendKeyDown(_hWnd, Keys.A);

                    Thread.Sleep(200);
                    using (Bitmap currentFrame = (Bitmap)ScreenCapture.CaptureWindow(_hWnd))
                    {
                        if (detector.ProcessFrame(currentFrame.FilterForBlackTags()) > 0.0002 && motionProcessing.ObjectsCount >= 1)
                        {
                            RECT rect = motionProcessing.ObjectRectangles.FirstOrDefault();
                            AutoClickHandlers.LeftClickOnPoint(_hWnd, rect.Center.ScaleDownToClientPoint(_hWnd));
                            Thread.Sleep(250);
                        }
                        else
                        {
                            AutoClickHandlers.SendKeyUp(_hWnd, Keys.A);
                            FireReleaseMainStream();
                            break;
                        }
                    }

                    AutoClickHandlers.SendKeyUp(_hWnd, Keys.A);
                    Thread.Sleep(200);
                }

                i++;
            }

            FireReleaseMainStream();
        }
        private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            lock (_lock)
            {
                Thread.Sleep(40);

                try
                {
                    if (_isCameraStart)
                    {
                        using (var bitmap = (Bitmap)eventArgs.Frame.Clone())
                        {
                            _bitmap = bitmap;

                            if (_recording)
                            {
                                _detector.ProcessFrame(bitmap);

                                if (_firstFrameTime != null)
                                {
                                    _writer.WriteVideoFrame(bitmap, DateTime.Now - _firstFrameTime.Value);
                                }
                                else
                                {
                                    _writer.WriteVideoFrame(bitmap);
                                    _firstFrameTime = DateTime.Now;
                                }
                            }
                            else
                            {
                                if (_detector.ProcessFrame(bitmap) > 0.02) // нарушитель замечен
                                {
                                    _logger.Info($"Start recording process | {DateTime.Now}");
                                    _recording = true;
                                    var filename = Guid.NewGuid().ToString();

                                    CreateSnapShot(filename);
                                    CreateVideoShot(filename);
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    _logger.Error("Error on _videoSource_NewFrame:\n" + e);
                    StopCamera();
                }
            }
        }
Exemple #4
0
 private void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs)
 {
     if (Detector.ProcessFrame((Bitmap)eventArgs.Frame.Clone()) > DetectionThreshold)
     {
         MotionDetected?.Invoke();
     }
 }
Exemple #5
0
        private static void VideoSourcePlayer_NewFrame(object sender, ref System.Drawing.Bitmap image)
        {
            var motionLevel = _motionDetector.ProcessFrame(image);

            if (motionLevel > _motionAlarmLevel)
            {
                if (_hasMotion)
                {
                    return;
                }
                Console.WriteLine(DateTime.Now + ": Motion started. Motion level: " + motionLevel);
                var file = _path + @"\picture_" + _volgnr + ".jpg";
                Console.WriteLine(DateTime.Now + "Image saved as " + file);
                image.Save(file, ImageFormat.Jpeg);
                _volgnr++;
                _hasMotion = true;
            }
            else
            {
                if (_hasMotion)
                {
                    Console.WriteLine(DateTime.Now + ": Motion stopped. Motion level: " + motionLevel);
                }
                _hasMotion = false;
            }
        }
Exemple #6
0
 private void videoSourcePlayer_NewFrame(object sender, ref Bitmap image)
 {
     if (Detector2.ProcessFrame(image) > motionLevel)
     {
         try
         {
             Invoke(new Action(() => backgroundBorder.Visible = true));
         }
         catch (Exception ex)
         {
             System.Environment.Exit(1);
             //MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         try
         {
             Invoke(new Action(() => backgroundBorder.Visible = false));
         }
         catch (Exception ex)
         {
             System.Environment.Exit(1);
             //MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Exemple #7
0
        private void Alert(object sender, NewFrameEventArgs e)
        {
            this.BackgroundImage = e.Frame.Clone() as Image;
            float Result = LunchDetector.ProcessFrame(e.Frame.Clone() as Bitmap);

            if (Result > 0.0001)
            {
                if (IgnoreAlert)
                {
                    return;
                }
                IgnoreAlert = true;
                AppendLog("发现移动对象 " + Result.ToString());

                //TODO:触发监视警报
                Debug.Print(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " : " + Result.ToString());
                SendAlert(Result, new Bitmap(e.Frame, 640, 360));

                //解除警报事件,防止瞬间重复触发
                new Thread(new ThreadStart(delegate {
                    Thread.Sleep(3000);
                    IgnoreAlert = false;
                })).Start();
            }
            MotionPictureBox.BackgroundImage = (motionDetector as TwoFramesDifferenceDetector).MotionFrame.ToManagedImage();
            //GC.Collect();
        }
Exemple #8
0
        private void VideoSourcePlayer_NewFrame(object sender, ref System.Drawing.Bitmap image)
        {
            var motionLevel = _motionDetector.ProcessFrame(image);

            if (motionLevel > _motionAlarmLevel)
            {
                if (_hasMotion)
                {
                    return;
                }

                this.Invoke(new UpdateStatusDelegate(this.UpdateLabel));



                _volgnr++;
                _hasMotion = true;

                PowerHelper.ForceSystemAwake();
                PowerHelper.ResetSystemDefault();
            }
            else
            {
                if (_hasMotion)
                {
                    Console.WriteLine(DateTime.Now + ": Motion stopped. Motion level: " + motionLevel);
                }
                _hasMotion = false;
            }
        }
        private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            try
            {
                if (_recording)
                {
                    using (var bitmap = (Bitmap)eventArgs.Frame.Clone())
                    {
                        if (_firstFrameTime != null)
                        {
                            _writer.WriteVideoFrame(bitmap, DateTime.Now - _firstFrameTime.Value);
                        }
                        else
                        {
                            _writer.WriteVideoFrame(bitmap);
                            _firstFrameTime = DateTime.Now;
                        }
                    }
                }
                using (var bitmap = (Bitmap)eventArgs.Frame.Clone())
                {
                    _detector.ProcessFrame(bitmap);

                    var bi = bitmap.ToBitmapImage();
                    bi.Freeze();
                    Dispatcher.CurrentDispatcher.Invoke(() => Image = bi);
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("Error on _videoSource_NewFrame:\n" + exc.Message, "Error", MessageBoxButton.OK,
                                MessageBoxImage.Error);
                StopCamera();
            }
        }
Exemple #10
0
        /// <summary>
        /// A chaque frame capturée, mets à jour l'image si un mouvement a été détecté
        /// </summary>
        private void OnNewFrameReceived(object sender, NewFrameEventArgs eventArgs)
        {
            var img         = (Bitmap)eventArgs.Frame.Clone();
            var motionLevel = _motionDetector.ProcessFrame(img);

            if (CurrentImage == null)
            {
                _synchronizationContext.Post(
                    o =>
                {
                    CurrentImage = BitmapConverter.ToBitmapImage(img);
                }, null);
            }
            // vous pouvez jouer sur ce chiffre pour éviter de détecter des petits mouvements
            if (motionLevel < .005f)
            {
                return;
            }

            _bitmapToUpload = true;
            _synchronizationContext.Post(o =>
            {
                Information  = "Mouvement détecté !";
                CurrentImage = BitmapConverter.ToBitmapImage(img);
            }, null);
        }
        void JpegStreamNewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            if (!_resized)
            {
                if (_displayControl != null)
                {
                    _displayControl.Invalidate();
                }
                this.LiveViewResized(null);
                _resized = true;
            }

            LastImage = eventArgs.Frame;

            if (_motionFramesQueue.Count > MotionQueueSize)
            {
                return;
            }

            var bmp = AForge.Imaging.Image.Clone(eventArgs.Frame);

            OpenCvSharp.IplImage ipl = null;

            try
            {
                ipl = OpenCvSharp.IplImage.FromBitmap(bmp);
            }
            catch (Exception)
            {
                return;
            }
            finally
            {
                if (bmp != null)
                {
                    bmp.Dispose();
                }
            }


            var frame   = new Frame(ipl);
            var grouped = _motionDetector.ProcessFrame(frame);

            if (grouped)
            {
                var motionFrames = _motionDetector.GetMotionFrames();
                if (motionFrames != null)
                {
                    foreach (var motionFrame in motionFrames)
                    {
                        motionFrame.DeviceId = _cameraInfo.Id;
                    }

                    SaveMotionFrames(motionFrames);

                    _motionFramesQueue.Enqueue(motionFrames);
                    _signal.Set();
                }
            }
        }
Exemple #12
0
        private void videoSourcePlayerInput_NewFrame(object sender, ref Bitmap image)//it enables the processing in the video that is in the video box
        // it breaks the video into images
        {
            var   motionlevel = _detector.ProcessFrame(image);//motion level is threshold
            var   dateTime    = DateTime.Now;
            float i           = image.Width;
            float j           = image.Height;

            if (motionlevel > 0.05)
            {
                var historyString = "There was a motion at" + dateTime.ToString() + count.ToString();
                _historyList.Add(historyString);
            }

            var g     = Graphics.FromImage(image);
            var font  = new Font(FontFamily.GenericSerif, 30);
            var brush = new SolidBrush(Color.Red);
            var pen   = new SolidBrush(Color.Beige);

            g.DrawString(dateTime.ToString(), font, brush, new PointF(5, 5));
            g.DrawString(count.ToString(), font, brush, new PointF(40, 40));
            brush.Dispose();
            g.Dispose();
            count++;
        }
        private void video_NuevoFrame(object sender, NewFrameEventArgs eventArgs)
        {
            //entra aqui mientras no se haya detectado movimiento

            Bitmap Imagen = (Bitmap)eventArgs.Frame.Clone();

            video = (Bitmap)eventArgs.Frame.Clone();
            if (detector != null)
            {
                Single motionLevel = detector.ProcessFrame(Imagen);

                if (motionLevel > motionAlarmLevel)
                {
                    //"Si hay Movimiento";
                    if (!IsRecording && timeLeft <= 0)
                    {
                        //txtMensajes.Text += "Inicio de grabación...! " + "\r\n";
                        time_stop     = DateTime.Now.AddSeconds(10);
                        IsRecording   = true;
                        VideoFileName = "C:/Users/Alex/Desktop/DEMO/video_" + DateTime.Now.ToShortDateString().Replace("/", "-") + DateTime.Now.ToShortTimeString().Replace(":", "_") + ".avi";
                        writer.Open(VideoFileName, video.Width, video.Height);
                        //FileWriter.Open("D:/video.avi", 320, 240, 25, VideoCodec.MPEG4, 5000000);
                    }
                }
                else
                {
                    //"No hay Movimiento";
                    foto = (Bitmap)eventArgs.Frame.Clone();
                }

                pcb_video.Image = Imagen;
            }
        }
Exemple #14
0
 private void video_NewFrame(object sender, Accord.Video.NewFrameEventArgs eventArgs)
 {
     if (Detector1.ProcessFrame(eventArgs.Frame) > motionLevel)
     {
         try
         {
             Invoke(new Action(() => backgroundBorder.Visible = true));
         }
         catch (Exception ex)
         {
             System.Environment.Exit(1);
             //MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         try
         {
             Invoke(new Action(() => backgroundBorder.Visible = false));
         }
         catch (Exception ex)
         {
             System.Environment.Exit(1);
             //MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     pictureBox1.Image = (Image)eventArgs.Frame.Clone();
 }
        private void FinalVideoSource_NewFrame2(object sender, AForge.Video.NewFrameEventArgs eventArgs)
        {
            Bitmap image = (Bitmap)eventArgs.Frame.Clone();

            if (detector.ProcessFrame(image) > 1)
            {
                pictureBox1.Image = image;
            }
            pictureBox1.Image = image;

            int X = 0;
            int Y = 0;

            try
            {
                BlobCountingObjectsProcessing countingDetector = (BlobCountingObjectsProcessing)detector.MotionProcessingAlgorithm;

                foreach (Rectangle rect in countingDetector.ObjectRectangles)
                {
                    X += rect.X;
                    Y += rect.Y;
                }

                SumX = X / countingDetector.ObjectRectangles.Length;
                SumY = Y / countingDetector.ObjectRectangles.Length;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemple #16
0
        void captureDevice_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
        {
            lock (this)
            {
                Dispatcher.Invoke(delegate()
                {
                    var image = eventArgs.Frame;
                    _detector.ProcessFrame(image);

                    if (_processor.ObjectsCount > 0)
                    {
                        var largestMovementArea   = int.MinValue;
                        var largestMovementCenter = default(Point);

                        foreach (var zone in _processor.ObjectRectangles)
                        {
                            var movementArea = zone.Width * zone.Height;
                            if (movementArea > largestMovementArea)
                            {
                                largestMovementArea   = movementArea;
                                largestMovementCenter = new Point(zone.X + zone.Width / 2, zone.Y + zone.Height / 2);
                            }
                        }

                        //now determine where the center movement is, and in which grid.
                        var imageWidth  = (double)image.Width;
                        var imageHeight = (double)image.Height;

                        var gridRowCount    = MotionGrid.RowDefinitions.Count;
                        var gridColumnCount = MotionGrid.ColumnDefinitions.Count;

                        var cellWidth  = imageWidth / gridColumnCount;
                        var cellHeight = imageHeight / gridRowCount;

                        var targetColumn = (int)Math.Min(Math.Max((largestMovementCenter.X) / cellWidth, 0), gridColumnCount - 1);
                        var targetRow    = (int)Math.Min(Math.Max((largestMovementCenter.Y) / cellHeight, 0), gridRowCount - 1);

                        var currentProgressBarRow    = Grid.GetRow(ProgressBar);
                        var currentProgressBarColumn = Grid.GetColumn(ProgressBar);

                        //reposition the progress bar if the cell with activity in it has changed.
                        if (currentProgressBarColumn != targetColumn || currentProgressBarRow != targetRow)
                        {
                            Grid.SetColumn(ProgressBar, targetColumn);
                            Grid.SetRow(ProgressBar, targetRow);

                            this.currentColumn = targetColumn;
                            this.currentRow    = targetRow;

                            ProgressBar.Value = 0;
                        }
                    }

                    var source        = ConvertBitmap(image);
                    CameraFeed.Source = source;

                    image.Dispose();
                });
            }
        }
Exemple #17
0
        // New frame received by the player
        private void videoSourcePlayer_NewFrame(object sender, ref Bitmap image)
        {
            lock (this)
            {
                //for test
                if (detectorTL != null)
                {
                    float motionLevel = detectorTL.ProcessFrame(image);

                    if (motionLevel > motionAlarmLevel)
                    {
                        // flash for 2 seconds
                        flash = (int)(2 * (1000 / alarmTimer.Interval));
                    }

                    // accumulate history
                    motionHistoryTL.Add(motionLevel);
                    if (motionHistoryTL.Count > 300)
                    {
                        motionHistoryTL.RemoveAt(0);
                    }

                    //if (showMotionHistoryToolStripMenuItem.Checked)
                    DrawMotionHistory(image, "tl");
                }

                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, "");
                }
            }
        }
Exemple #18
0
        private void DetectMotion(Bitmap bitmap)
        {
            _detector.ProcessFrame(bitmap);
            MotionFrameEvent?.Invoke(this, new NewFrameEventArgs(bitmap));
            bitmap.Dispose();

            //processingAlgorithm.ObjectRectangles
        }
Exemple #19
0
        private void CameraZm_NewFrame(object sender, ref System.Drawing.Bitmap oBitmap)
        {
            if (this.IsIdentify)
            {
                FPSCount++;

                #region 跟踪变化项
                lock (this)
                {
                    if (detector != null)
                    {
                        detector.ProcessFrame(oBitmap);
                    }
                }
                #endregion

                if (FPSCount < 10)
                {
                    return;
                }
                else
                {
                    FPSCount = -1;
                }

                try
                {
                    string sResult = "";

                    // ****************** Failed *************************
                    // 采用ThoughtWorks.QRCode.dll时识别不出,  原始二维码制作成素材可识别。  但是摄像头扫描模式进行识别时识别结果为乱码
                    //QRCodeImage oCodeImage = new QRCodeBitmapImage(oBitmap);
                    //string sResult = QRImageDecoder.decode(oCodeImage);

                    //var result = ZXingDecoder.Decode((BitmapSource)imageBarcode.Source);
                    BitmapSource oBitmapSource = this.ConvertBitmapToBiamapSource(oBitmap);
                    sResult = ZXingDecoder.Decode(oBitmapSource).ToString();

                    this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate()
                    {
                        if (this.QrCodeIdentified != null && !String.IsNullOrEmpty(sResult))
                        {
                            this.QrCodeIdentified(sResult);
                        }
                    });
                }
                catch (Exception ex)
                {
                    this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate()
                    {
                        if (this.QrCodeIdentified != null)
                        {
                            this.QrCodeIdentified(ex.Message);
                        }
                    });
                }
            }
        }
    private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
    {
        Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone();

        detector.ProcessFrame(bitmap);

        bitmap.Dispose();
        bitmap = null;
    }
Exemple #21
0
 void FinalVideo_Kuyruk(object sender, NewFrameEventArgs eventArgs)//event func
 {
     frame_al  = (Bitmap)eventArgs.Frame.Clone();
     frame_al1 = (Bitmap)frame_al.Clone();
     i++;
     if ((detector.ProcessFrame(frame_al) > 0.001) && i % 10 == 0)////
     {
         ImageQueue.Enqueue(frame_al1);
     }
 }
Exemple #22
0
 private void ProcessImageMotionDetection(ref Bitmap frame)
 {
     if (IsMotionDetection && MotionDetector != null)
     {
         float motionLevel = MotionDetector.ProcessFrame(frame);
         if (motionLevel >= 0.0005)
         {
             RaiseCameraAlarmEvent("Motion detected.");
         }
     }
 }
Exemple #23
0
        //detect if there is motion in frames
        private Bitmap DetectMotion(MotionDetector motionDetector, Bitmap videoFrame)
        {
            Bitmap frames = null;

            // process new video frame and check motion level
            if (motionDetector.ProcessFrame(videoFrame) > 0.02)
            {
                frames = videoFrame;
            }
            return(frames);
        }
Exemple #24
0
        // Motion Detection Function

        private void videoSourcePlayer1_NewFrame(object sender, ref Bitmap image)
        {
            motdet.ProcessFrame(image);
            while (true)
            {
                if (alrm == true)
                {
                    MessageBox.Show("we made it");
                }
            }
        }
Exemple #25
0
        private void videoSource_MotionFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap frame = (Bitmap)eventArgs.Frame.Clone();



            if (detector.ProcessFrame(frame) > 0.04)
            {
            }

            pictureBox2.Image = frame;
        }
 private void vspCamara_NewFrame(object sender, ref Bitmap image)
 {
     // Procesa el movimiento en tiempo real.
     if (rbDetector1.Checked)
     {
         NivelDetenccion = Detector01.ProcessFrame(image);
     }
     else if (rbDetector2.Checked)
     {
         NivelDetenccion = Detector02.ProcessFrame(image);
     }
     else if (rbDetector3.Checked)
     {
         NivelDetenccion = Detector03.ProcessFrame(image);
     }
     else if (rbDetector4.Checked)
     {
         NivelDetenccion = Detector04.ProcessFrame(image);
     }
     else if (rbDetector5.Checked)
     {
         NivelDetenccion = Detector05.ProcessFrame(image);
     }
     else if (rbDetector6.Checked)
     {
         NivelDetenccion = Detector06.ProcessFrame(image);
     }
     else if (rbDetector7.Checked)
     {
         NivelDetenccion = Detector07.ProcessFrame(image);
     }
     else if (rbDetector8.Checked)
     {
         NivelDetenccion = Detector08.ProcessFrame(image);
     }
     else if (rbDetector9.Checked)
     {
         NivelDetenccion = Detector09.ProcessFrame(image);
     }
     else if (rbDetector10.Checked)
     {
         NivelDetenccion = Detector10.ProcessFrame(image);
     }
     else if (rbDetector11.Checked)
     {
         NivelDetenccion = Detector11.ProcessFrame(image);
     }
     else
     {
         NivelDetenccion = Detector12.ProcessFrame(image);
     }
 }
Exemple #27
0
 /// <summary>
 /// Funkcja przygotowująca nową klatkę do wyświetlenia.
 /// </summary>
 /// <param name="currentFrame">Klatka do przetworzenia.</param>
 /// <returns>Klatka zmodyfikowana o zastosowane efekty.</returns>
 public Bitmap PrepareFrame(Bitmap currentFrame)
 {
     lastFrame = (Bitmap)currentFrame.Clone();
     if (startProcess)
     {
         motionlevel = detector.ProcessFrame(lastFrame);
         count       = process.getPersonCount();
         LR          = process.getLR();
         RL          = process.getRL();
     }
     //lastFrame.RotateFlip(RotateFlipType.RotateNoneFlipX);
     return(lastFrame);
 }
Exemple #28
0
        ///------自定义函数
        private void Cam_NewFrame(object obj, NewFrameEventArgs eventArgs)
        {
            pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone();
            float motionLevel = detector.ProcessFrame(eventArgs.Frame);

            if (motionLevel > motionAlarmLevel)
            {
                detected = true;
            }
            else
            {
                detected = false;
            }
        }
        /// <summary>
        ///     image must be a clone of the original image (un-proccessed by motion proccessor)
        /// </summary>
        /// <param name="image"></param>
        public void ProcessFrame(Bitmap image)
        {
            if (++processedFrames % skipFrame == 0)
            {
                processedFrames = 0;
                Bitmap  img           = image.Clone(new Rectangle(0, 0, image.Width, image.Height), image.PixelFormat);
                Boolean disposedImage = false;
                var     motionLevel   = motionDetector.ProcessFrame(image);
                //Console.WriteLine(motionLevel);
                switch (detectionMethod)
                {
                case MOTION.MOTION_GRID_AREA_HIGHLIGHTING:
                {
                    // ReSharper disable once PossibleNullReferenceException
                    if (motionLevel >= sensitivityFactor)
                    {
                        LPR.analyze(img);
                        disposedImage = true;
                    }
                    break;
                }

                case MOTION.MOTION_AREA_HIGHLIGHTING:
                {
                    if (motionLevel >= sensitivityFactor)
                    {
                        LPR.analyze(img);
                        disposedImage = true;
                    }
                    break;
                }

                case MOTION.MOTION_BORDER_HIGHLIGHTING:
                {
                    if (motionLevel >= sensitivityFactor)
                    {
                        LPR.analyze(img);
                        disposedImage = true;
                    }
                    break;
                }
                }

                if (!disposedImage)
                {
                    img.Dispose();
                }
            }
        }
        private void videoSourcePlayer_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));
                        //Save Photo
                        string fileName = DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() +
                                          DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString();
                        //Check if there is an Alarm
                        _deviceData[0] = "0000012345";
                        _deviceData[1] = "Video";
                        _deviceData[2] = "1";
                        if (_bwfc.IsThereAlarm(_deviceData) == "Warning")
                        {
                            image.Save("D:\\Caelum 2012\\Warda Daily Work\\" + fileName + ".jpg",
                                       System.Drawing.Imaging.ImageFormat.Jpeg);
                        }
                    }

                    // 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);
                }
            }
        }