Esempio n. 1
0
        void InitializeMotionDetection(int cameraindex)
        {
            Thread thread = new Thread(() =>
            {
                try
                {
                    ReleasePreviousDetectors();
                    WebcamManager.SetPropertyValueManual(cameraindex, WebcamManager.CAMERA_PROPERTY.CAMERA_FOCUS, camerafocus);
                    WebcamManager.SetPropertyValueManual(cameraindex, WebcamManager.CAMERA_PROPERTY.CAMERA_ZOOM, camerazoom);

                    personDetector = new WebCamPersonDetector();
                    personDetector.ToggleVisualization();
                    personDetector.RegisterForImages(WebcamManager.GetCamera(cameraindex));
                    personDetector.SelectedCameraIndex = cameraindex;
                    personDetector.RoiX            = roiX;
                    personDetector.RoiY            = roiY;
                    personDetector.RoiWidth        = roiWidth;
                    personDetector.RoiHeight       = roiHeight;
                    personDetector.PersonDetected += WebCamPersonDetected;
                }
                catch (Exception err)
                {
                    MessageBox.Show(err.ToString());
                }
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }
Esempio n. 2
0
 public void OnCameraConnected(object sender, USBEvent e)
 {
     if (!selectedCameraConnected)
     {
         Thread.Sleep(50);
         WebcamManager.RestartService();
         selectedCameraIndex = LookforSelectedCamera();
         if (selectedCameraIndex != -1)
         {
             Logger.WriteLine("Selected camera reconnected");
             ErrorLog.AddError(ErrorType.Message, "Selected camera has been reconnected");
             personDetector.RegisterForImages(WebcamManager.GetCamera(selectedCameraIndex));
             WebcamManager.ReleaseInactiveCameras();
         }
     }
 }