Exemple #1
0
        public void OnSaved(WpfConfiguration configurationControl)
        {
            WebcamSnapshotConfig config = configurationControl as WebcamSnapshotConfig;

            config.Cleanup();
            folderLocation     = config.SaveLocation;
            fileNamePrefix     = config.FilenamePrefix;
            captureWidth       = 640;
            captureHeight      = 480;
            selectedCameraPath = config.SelectedCameraPath;
            selectedCameraName = config.SelectedCameraName;
            showPreview        = config.ShowPreview;
            playShutterSound   = config.PlayShutterSound;
            if (WebcamManager.IsServiceRestartRequired())
            {
                WebcamManager.RestartService();
            }
            //look for the selected camera
            selectedCameraIndex = LookforSelectedCamera(true);
            if (selectedCameraIndex != -1 && selectedCameraConnected)
            {
                if (!callbacksRegistered)
                {
                    WebcamManager.RegisterWebcamConnectionEvent(OnCameraConnected);
                    WebcamManager.RegisterWebcamRemovalEvent(OnCameraDisconnected);
                    callbacksRegistered = true;
                }
                InitializeSnapshot(selectedCameraIndex);
            }
        }
Exemple #2
0
        public void OnSaved(WpfConfiguration configurationControl)
        {
            WebCamFaceDetectionConfig config = configurationControl as WebCamFaceDetectionConfig;

            config.Cleanup();
            captureWidth        = 640;
            captureHeight       = 480;
            selectedCameraPath  = config.SelectedCameraPath;
            selectedCameraName  = config.SelectedCameraName;
            selectedCameraIndex = config.SelectedCameraIndex;
            roiX        = config.RoiX;
            roiY        = config.RoiY;
            roiWidth    = config.RoiWidth;
            roiHeight   = config.RoiHeight;
            camerafocus = config.CameraFocus;
            camerazoom  = config.CameraZoom;

            if (WebcamManager.IsServiceRestartRequired())
            {
                WebcamManager.RestartService();
            }
            selectedCameraIndex = LookforSelectedCamera(true);

            if (selectedCameraIndex != -1 && selectedCameraConnected)
            {
                if (!callbacksRegistered)
                {
                    WebcamManager.RegisterWebcamConnectionEvent(OnCameraConnected);
                    WebcamManager.RegisterWebcamRemovalEvent(OnCameraDisconnected);
                    callbacksRegistered = true;
                }
                InitializeFaceDetection(selectedCameraIndex);
            }
        }
 protected override void OnAfterLoad()
 {
     selectedCameraIndex = LookforSelectedCamera();
     if (selectedCameraIndex != -1 && selectedCameraConnected)
     {
         if (WebcamManager.IsServiceRestartRequired())
         {
             WebcamManager.RestartService();
         }
         if (!callbacksRegistered)
         {
             WebcamManager.RegisterWebcamConnectionEvent(OnCameraConnected);
             WebcamManager.RegisterWebcamRemovalEvent(OnCameraDisconnected);
             callbacksRegistered = true;
         }
         InitializeMotionDetection(selectedCameraIndex);
     }
 }
Exemple #4
0
 //[MethodImpl(MethodImplOptions.Synchronized)]
 protected override void OnEnabling(EnablingEventArgs e)
 {
     if (!e.WasConfiguring)
     {
         if (WebcamManager.IsServiceRestartRequired())
         {
             WebcamManager.RestartService();
         }
         //look for the selected camera
         selectedCameraIndex = LookforSelectedCamera(true);
         if (selectedCameraIndex != -1 && selectedCameraConnected)
         {
             if (!callbacksRegistered)
             {
                 WebcamManager.RegisterWebcamConnectionEvent(OnCameraConnected);
                 WebcamManager.RegisterWebcamRemovalEvent(OnCameraDisconnected);
                 callbacksRegistered = true;
             }
             InitializeSnapshot(selectedCameraIndex);
         }
     }
 }
        private void UpdatePanel()
        {
            if (WebcamManager.IsServiceRestartRequired())
            {
                WebcamManager.RestartService();
            }

            if (!callbacksRegistered)
            {
                WebcamManager.RegisterWebcamConnectionEvent(OnCameraConnected);
                WebcamManager.RegisterWebcamRemovalEvent(OnCameraDisconnected);
                callbacksRegistered = true;
            }

            numberConnectedCameras = WebcamManager.NumberConnectedCameras();

            cameraList          = new List <int>();
            selectedCameraIndex = -1;
            int numAvailableCameras = 0;

            cameraPreviews.Clear(); //remove previous viewers
            //populate the camera list and find the one that is available and set it as current selection...
            if (numberConnectedCameras == 0)
            {
                ShowNoCamerasFoundPanel();
                return;
            }
            for (int i = 0; i < numberConnectedCameras; i++)
            {
                //if (WebcamManager.StartCamera(i, captureWidth, captureHeight))
                {
                    ImageViewer viewer = new ImageViewer();
                    viewer.ViewerWidth  = previewWidth;
                    viewer.ViewerHeight = previewHeight;
                    viewer.TopTitle     = WebcamManager.GetCamera(i).WebCamName;
                    if (WebcamManager.StartCamera(i, captureWidth, captureHeight))
                    {
                        if (viewer.TopTitle == selectedCameraName || selectedCameraIndex == -1)
                        {
                            selectedCameraIndex = i;
                        }
                        viewer.SetImageSource(WebcamManager.GetCamera(i));
                        viewer.MouseEnter += Viewer_MouseEnter;
                        viewer.MouseLeave += Viewer_MouseLeave;
                        viewer.PreviewMouseLeftButtonUp += Viewer_MouseLeftButtonUp;
                        ++numAvailableCameras;
                    }
                    else
                    {
                        viewer.ImageSource.Source = loadBitmap(Properties.Resources.CamBusyIcon);
                        viewer.BottomTitle        = "This webcam is already busy";
                    }
                    cameraList.Add(i);
                    cameraPreviews.Add(viewer);
                }
            }

            if (selectedCameraIndex != -1)
            {
                cameraPreviews[cameraList.IndexOf(selectedCameraIndex)].ViewerBorderColor = "LightGreen";
                cameraPreviews[cameraList.IndexOf(selectedCameraIndex)].ViewerWidth       = previewHeight + 16;
                cameraPreviews[cameraList.IndexOf(selectedCameraIndex)].ViewerHeight      = cameraPreviews[cameraList.IndexOf(selectedCameraIndex)].ViewerWidth * 3 / 4;
            }

            //release inactive cameras so that they can be made available to other processes...
            WebcamManager.ReleaseInactiveCameras();
            CameraReadiness = true;
        }