Exemplo n.º 1
0
    // Open video source
    private void OpenVideoSource(AForge.Video.IVideoSource source)
    {
      // set busy cursor
      this.Cursor = Cursors.WaitCursor;

      // close previous video source
      CloseVideoSource();

      // create camera
      Camera camera = new Camera(source, detector);
      camera.NewFrame += new EventHandler(camera_NewFrame);
      // start camera
      camera.Start();

      // attach camera to camera window
      cameraWindow1.Camera = camera;

      // reset statistics
      statIndex = statReady = 0;

      // start timer        
      timer.Start();

      this.Cursor = Cursors.Default;
    }
Exemplo n.º 2
0
 public void Start()
 {
     if (false == this.CameraClass.ValidCheck(true))
     {
         return;
     }
     this.Cursor = Cursors.WaitCursor;
     try
     {
         CameraViewBeforeStartEventArgs e = new CameraViewBeforeStartEventArgs(this.Status, this);
         OnCameraViewBeforeStartEvent(e);
         if (e.Cancel == false)
         {
             OnCameraViewLog(new CameraViewLogEventArgs(ZForge.Controls.Logs.LogLevel.LOG_INFO, string.Format(Translator.Instance.T("启动摄像头[{0}]."), this.CameraClass.Name), this));
             AForge.Video.IVideoSource source = this.CameraClass.VideoSource;
             if (source == null)
             {
                 throw new System.NullReferenceException();
             }
             OpenVideoSource(source);
             this.SetStatus(Motion.Core.CameraStatus.STOPPED, false);
             this.SetStatus(Motion.Core.CameraStatus.STARTED, true);
         }
         e = null;
     }
     catch (Exception)
     {
         MessageBox.Show(string.Format(Translator.Instance.T("启动摄像头[{0}]失败!"), this.CameraClass.Name), MotionPreference.Instance.MessageBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
         OnCameraViewLog(new CameraViewLogEventArgs(ZForge.Controls.Logs.LogLevel.LOG_ERROR, string.Format(Translator.Instance.T("启动摄像头[{0}]失败!"), this.CameraClass.Name), this));
     }
     finally
     {
         this.Cursor = Cursors.Default;
     }
 }
Exemplo n.º 3
0
        // Open video source
        private void OpenVideoSource(AForge.Video.IVideoSource source)
        {
            // set busy cursor
            this.Cursor = Cursors.WaitCursor;

            // close previous video source
            CloseVideoSource();

            // create camera
            Camera camera = new Camera(source, null);

            //camera.NewFrame += new EventHandler(camera_NewFrame);
            // start camera
            camera.Start();

            // attach camera to camera window
            gridBox.Camera = camera;

            this.Cursor = Cursors.Default;
        }
Exemplo n.º 4
0
        public void StartWith(CameraInfo cameraInfo, System.Windows.Forms.Control displayControl)
        {
            _displayControl = displayControl;

            if (_jpegStream == null)
            {
                switch (cameraInfo.Provider)
                {
                    case CameraProvider.LocalDirectory:
                        var dir = new Damany.Cameras.DirectoryFilesCamera(cameraInfo.Location.LocalPath, "*.*");
                        dir.Repeat = false;
                        dir.FrameIntervalMs = cameraInfo.Interval;

                        _jpegStream = dir;
                        break;

                    case CameraProvider.Sanyo:
                        var sanyo = new JPEGExtendStream(cameraInfo.Location.ToString());
                        sanyo.Login = cameraInfo.LoginUserName ?? "guest";
                        sanyo.Password = cameraInfo.LoginPassword ?? "guest";
                        sanyo.FrameInterval = cameraInfo.Interval;

                        sanyo.RequireCookie = cameraInfo.Provider == CameraProvider.Sanyo;
                        _portraitFinder.PostFilters = _facePostFilters;

                        _jpegStream = sanyo;
                        break;
                    case CameraProvider.AipStar:

                        var hwnd = displayControl != null ? displayControl.Handle : IntPtr.Zero;
                        var aip = CreateAipCamera(cameraInfo, hwnd);
                        aip.Camera.StreamId = 0;

                        Mediator.Instance.RegisterHandler(
                            "liveViewResize", new Action<object>(LiveViewResized));
                        _jpegStream = aip;

                        if (displayControl != null)
                        {
                            //aip.Camera.DisplayPos = displayControl.ClientRectangle;
                        }

                        var videoRecorder = CreateAipCamera(cameraInfo, IntPtr.Zero);
                        videoRecorder.Camera.PathFunc = d =>
                                                            {
                                                                var utc = d.ToUniversalTime();
                                                                var rp = string.Format(
                                                                    "{0:d2}\\NORMAL\\{1:d4}{2:d2}{3:d2}\\{4:d2}\\{5:d2}.m4v",
                                                                    cameraInfo.Id,
                                                                    utc.Year, utc.Month, utc.Day, utc.Hour, utc.Minute);

                                                                var ap = Path.Combine(Util.GetVideoOutputPath(), rp);
                                                                var directory = Path.GetDirectoryName(ap);
                                                                if (!Directory.Exists(directory))
                                                                {
                                                                    Directory.CreateDirectory(directory);
                                                                }

                                                                return ap;
                                                            };
                        videoRecorder.Camera.StreamId = 1;
                        videoRecorder.Start();
                        videoRecorder.Camera.StartRecord();

                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                }

                _cameraInfo = cameraInfo;

                _jpegStream.NewFrame += JpegStreamNewFrame;
                _jpegStream.Start();

                if (_faceSearchTask == null)
                {
                    _faceSearchTask =
                        Task.Factory.StartNew(
                            FaceSearchWorkerThread,
                            _tokenSource.Token,
                            TaskCreationOptions.LongRunning,
                            TaskScheduler.Default
                            );
                }

                _faceComparer.InitializeAsync();
                _faceComparer.Start();

                _faceComparer.Threshold = Properties.Settings.Default.RealTimeFaceCompareSensitivity;
                _faceComparer.Sensitivity = Properties.Settings.Default.LbpThreshold;

            }
        }
        public void StartWith(CameraInfo cameraInfo, System.Windows.Forms.Control displayControl)
        {
            _displayControl = displayControl;

            if (_jpegStream == null)
            {
                switch (cameraInfo.Provider)
                {
                case CameraProvider.LocalDirectory:
                    var dir = new Damany.Cameras.DirectoryFilesCamera(cameraInfo.Location.LocalPath, "*.*");
                    dir.Repeat          = false;
                    dir.FrameIntervalMs = cameraInfo.Interval;

                    _jpegStream = dir;
                    break;

                case CameraProvider.Sanyo:
                    var sanyo = new JPEGExtendStream(cameraInfo.Location.ToString());
                    sanyo.Login         = cameraInfo.LoginUserName ?? "guest";
                    sanyo.Password      = cameraInfo.LoginPassword ?? "guest";
                    sanyo.FrameInterval = cameraInfo.Interval;

                    sanyo.RequireCookie         = cameraInfo.Provider == CameraProvider.Sanyo;
                    _portraitFinder.PostFilters = _facePostFilters;

                    _jpegStream = sanyo;
                    break;

                case CameraProvider.AipStar:

                    var hwnd = displayControl != null ? displayControl.Handle : IntPtr.Zero;
                    var aip  = CreateAipCamera(cameraInfo, hwnd);
                    aip.Camera.StreamId = 0;


                    Mediator.Instance.RegisterHandler(
                        "liveViewResize", new Action <object>(LiveViewResized));
                    _jpegStream = aip;

                    if (displayControl != null)
                    {
                        //aip.Camera.DisplayPos = displayControl.ClientRectangle;
                    }

                    var videoRecorder = CreateAipCamera(cameraInfo, IntPtr.Zero);
                    videoRecorder.Camera.PathFunc = d =>
                    {
                        var utc = d.ToUniversalTime();
                        var rp  = string.Format(
                            "{0:d2}\\NORMAL\\{1:d4}{2:d2}{3:d2}\\{4:d2}\\{5:d2}.m4v",
                            cameraInfo.Id,
                            utc.Year, utc.Month, utc.Day, utc.Hour, utc.Minute);

                        var ap        = Path.Combine(Util.GetVideoOutputPath(), rp);
                        var directory = Path.GetDirectoryName(ap);
                        if (!Directory.Exists(directory))
                        {
                            Directory.CreateDirectory(directory);
                        }

                        return(ap);
                    };
                    videoRecorder.Camera.StreamId = 1;
                    videoRecorder.Start();
                    videoRecorder.Camera.StartRecord();

                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                _cameraInfo = cameraInfo;

                _jpegStream.NewFrame += JpegStreamNewFrame;
                _jpegStream.Start();



                if (_faceSearchTask == null)
                {
                    _faceSearchTask =
                        Task.Factory.StartNew(
                            FaceSearchWorkerThread,
                            _tokenSource.Token,
                            TaskCreationOptions.LongRunning,
                            TaskScheduler.Default
                            );
                }



                _faceComparer.InitializeAsync();
                _faceComparer.Start();

                _faceComparer.Threshold   = Properties.Settings.Default.RealTimeFaceCompareSensitivity;
                _faceComparer.Sensitivity = Properties.Settings.Default.LbpThreshold;
            }
        }