コード例 #1
0
        private void Camera_NewFrameEvent(object sender, NewCameraFrameEventArgs e)
        {
            CameraConnection camera = sender as CameraConnection;

            if (camera == null)
            {
                return;
            }

            var status = boundCameras[camera.Name];

            lock (status.ReadWriteLock)
            {
                var oldImage = status.LatestImage;

                status.LatestImage = new Bitmap(e.Frame);

                if (oldImage != null)
                {
                    oldImage.Dispose();
                }

                status.ImageTimestamp = DateTime.Now;
            }
        }
コード例 #2
0
        private void Video_NewFrame(object source, NewCameraFrameEventArgs e)
        {
            try
            {
                if (IsLoadingCameraStream)
                {
                    this.IsLoadingCameraStream = false;
                }

                BitmapImage bi;

                using (var bitmap = e.GetBitmap())
                {
                    bi = BitmapHelper.Bitmap2BitmapImage(bitmap);
                }

                bi.Freeze(); // avoid cross thread operations and prevents leaks

                this.DisplayStream = bi;
            }
            catch (VideoException exc)
            {
                this.videoManager.StopCamera();
                this.DisplayStream = null;
            }
        }
コード例 #3
0
ファイル: MotionHandler.cs プロジェクト: trembon/OpenONVIF
        private void Camera_NewFrameEvent(object sender, NewCameraFrameEventArgs e)
        {
            // create a clone of the current image to save if any motion is detected
            using (Bitmap clone = new Bitmap(e.Frame))
            {
                // process the current frame
                var   result           = motionDetector.ProcessFrame(clone);
                float calculatedResult = float.Parse(result.ToString("N4"));

                // check if there was any motion detected, by both motion and object found count
                if (calculatedResult >= camera.Settings.Properties.MotionSense && processor.ObjectsCount > 0)
                {
                    if (currentMotion == null)
                    {
                        currentMotion = new CurrentMotion(camera);
                    }

                    DateTime now = DateTime.Now;

                    string processedFile = Path.Combine(camera.BasePath, "motion", String.Format("{0}_framed_{1}.jpg", currentMotion.MotionID, now.Ticks));
                    Directory.CreateDirectory(Path.GetDirectoryName(processedFile));

                    clone.Save(processedFile, ImageFormat.Jpeg);
                    e.Frame.Save(Path.Combine(camera.BasePath, "motion", String.Format("{0}_raw_{1}.jpg", currentMotion.MotionID, now.Ticks)), ImageFormat.Jpeg);

                    currentMotion.AddMotion(processedFile, calculatedResult, processor.ObjectsCount, now);

                    camera.Log.Info("Motion detected (sense: {0}, count: {1})", calculatedResult, processor.ObjectsCount);
                }
                else
                {
                    if (currentMotion != null)
                    {
                        // TODO: verifiera att detta fungerar bra, eller om man ska nollställa sensorn, eller ha två sensorer för natt och dag.
                        if (lastTimeOfDay == e.TimeOfDay)
                        {
                            currentMotion.Process();
                        }
                        currentMotion = null;
                    }

                    lastTimeOfDay = e.TimeOfDay;
                }
            }
        }
コード例 #4
0
ファイル: SnapshotHandler.cs プロジェクト: trembon/OpenONVIF
        private void Camera_NewFrameEvent(object sender, NewCameraFrameEventArgs e)
        {
            DateTime now = DateTime.Now;

            TimeSpan timeSinceLastSnapshot = now - lastSnapshot;

            if (timeSinceLastSnapshot.TotalSeconds >= camera.Settings.Properties.SnapshotInternal)
            {
                string snapshotFile = Path.Combine(camera.BasePath, "snapshots", String.Format("snap_{0}.jpg", now.Ticks));

                Directory.CreateDirectory(Path.GetDirectoryName(snapshotFile));
                e.Frame.Save(snapshotFile, ImageFormat.Jpeg);

                lastSnapshot = now;

                camera.Log.Info("Snapshot taken");
            }
        }
コード例 #5
0
        private void Video_NewFrame(object source, NewCameraFrameEventArgs e)
        {
            try
            {
                if (IsLoadingCameraStream)
                {
                    this.IsLoadingCameraStream = false;
                }

                BitmapImage bi;

                using (var bitmap = e.GetBitmap())
                {
                    Bitmap trackBitmap = this.faceDetectionManager.FaceTracking(bitmap);

                    List <Point> first = new List <Point>();
                    List <Point> last  = new List <Point>();

                    Rectangle rect = this.faceDetectionManager.FaceTracked;
                    first.Add(new Point(rect.X, rect.Y));
                    last.Add(new Point(rect.X + rect.Width, rect.Y + rect.Height));


                    Bitmap encryptedImage = CryptingLib.Algorithm.EncryptingAlgorithm.EncryptImage(trackBitmap, first, last);

                    bi = BitmapHelper.Bitmap2BitmapImage(encryptedImage);
                    //bi = BitmapHelper.Bitmap2BitmapImage(this.faceDetectionManager.FaceTracking(bitmap));
                }

                bi.Freeze(); // avoid cross thread operations and prevents leaks

                this.DisplayStream = bi;
            }
            catch (AForge.Video.VideoException exc)
            {
                this.videoManager.StopCamera();
                this.DisplayStream = null;
            }
        }