예제 #1
0
        private Camera()
        {
            // Check connected device
            deviceType = GetConnectedDevice();

            // Create camera subclass object, inherits from CameraBase
            switch (deviceType)
            {
            case DeviceTypeEnum.Thorlabs:
                camera = new ThorlabCamera();     // needs hwndSource to work, set by this.HwndSource property
                break;

            case DeviceTypeEnum.PS3Eye:
                camera = new PS3Camera();
                break;

            case DeviceTypeEnum.Kinect:
                camera = new KinectCamera();
                break;

            case DeviceTypeEnum.DirectShow:
                camera = new DirectShowCamera();
                break;
            }
        }
예제 #2
0
        private Camera()
        {
            // Check connected device
            deviceType = GetConnectedDevice();

            // Create camera subclass object, inherits from CameraBase
            switch (deviceType)
            {
                case DeviceTypeEnum.Thorlabs:
                    camera = new ThorlabCamera(); // needs hwndSource to work, set by this.HwndSource property
                    break;
                case DeviceTypeEnum.PS3Eye:
                    camera = new PS3Camera();
                    break;
                case DeviceTypeEnum.Kinect:
                    camera = new KinectCamera();
                    break;
                case DeviceTypeEnum.DirectShow:
                    camera = new DirectShowCamera();
                    break;

            }
        }
예제 #3
0
        public void SetDirectShowCamera(int newDeviceNumber, int newDeviceMode)
        {
            try
            {
                int InstanceDeviceNumber = 0;
                int InstanceDeviceMode = 0;
                bool initializeNew = true;
                DirectShowCamera localCam; // we store new camera here and then transfer it to this.camera on success

                // If no device mode was select use default
                if (newDeviceMode == -1)
                    newDeviceMode = 0;

                // Get Instance camera and mode
                if (camera != null && camera is DirectShowCamera)
                {
                    DirectShowCamera dCam = camera as DirectShowCamera;

                    // Store Instance mode to reset if new mode fails
                    InstanceDeviceNumber = dCam.DeviceNumber;
                    InstanceDeviceMode = dCam.DeviceMode;

                    // Dont init the same device & mode twice..
                    if (InstanceDeviceNumber == newDeviceNumber
                        && InstanceDeviceMode == newDeviceMode
                        && dCam.HasValidGraph)
                        initializeNew = false;
                }


                // Specific deviceMode (e.g. 800x600 @ 30fps)
                if (camera == null || newDeviceMode > -1)
                {
                    if (initializeNew == true)
                    {
                        if (camera != null)
                        {
                            camera.Stop();
                            camera.Cleanup();
                        }
                    }
                    else
                    {
                        // No changes, just return
                        return;
                    }
                }

                // Specific configuration
                localCam = new DirectShowCamera(
                    DirectShowDevices.Instance.Cameras[newDeviceNumber].DirectshowDevice,
                    newDeviceNumber,
                    newDeviceMode,
                    DirectShowDevices.Instance.Cameras[newDeviceNumber].SupportedSizesAndFPS[newDeviceMode].FPS,
                    DirectShowDevices.Instance.Cameras[newDeviceNumber].SupportedSizesAndFPS[newDeviceMode].Width,
                    DirectShowDevices.Instance.Cameras[newDeviceNumber].SupportedSizesAndFPS[newDeviceMode].Height);

                //  If last set camera failed, try default mode
                if (localCam.HasValidGraph == false) // No specific deviceMode
                {
                    localCam.Cleanup();
                    localCam = new DirectShowCamera(
                        DirectShowDevices.Instance.Cameras[newDeviceNumber].DirectshowDevice,
                        newDeviceNumber,
                        0,
                        0,
                        0,
                        0);
                }

                //  If this is already occupied by another application and there
                //  are more than one camera connected, try the next one.
                if (localCam.HasValidGraph == false && DirectShowDevices.Instance.Cameras.Count() > 1)
                {
                    localCam.Cleanup();
                    localCam = new DirectShowCamera(
                        DirectShowDevices.Instance.Cameras[1].DirectshowDevice, 1, 0, 0, 0, 0);
                }

                // Finally, if running set this.camera to localCam
                if (localCam.HasValidGraph)
                {
                    localCam.IsSupportingROI = false;

                    // Switch
                    camera = localCam;
                    camera.Initialize();
                    camera.Start();

                    // Trigger global command, signal that a new camera has been started 
                    // Listners for OnImage event has to re-subscribe
                    GTCommons.GTCommands.Instance.Camera.CameraChange();
                }
                else
                {
                    // Failed, start previous camera/mode again
                    camera.Start();
                }
            }
            catch (Exception ex)
            {
                //ErrorLogger.ProcessException(ex, false);
            }
        }
예제 #4
0
파일: Camera.cs 프로젝트: odins1970/Ogama
        public void SetDirectShowCamera(int newDeviceNumber, int newDeviceMode)
        {
            try
            {
                bool             initializeNew = true;
                DirectShowCamera localCam; // we store new camera here and then transfer it to this.camera on success

                // If no device mode was select use default
                if (newDeviceMode == -1)
                {
                    newDeviceMode = 0;
                }

                // Get Instance camera and mode
                if (camera != null && camera is DirectShowCamera)
                {
                    var dCam = camera as DirectShowCamera;

                    // Store Instance mode to reset if new mode fails
                    var instanceDeviceNumber = dCam.DeviceNumber;
                    var instanceDeviceMode   = dCam.DeviceMode;

                    // Dont init the same device & mode twice..
                    if (instanceDeviceNumber == newDeviceNumber &&
                        instanceDeviceMode == newDeviceMode &&
                        dCam.HasValidGraph)
                    {
                        initializeNew = false;
                    }
                }


                // Specific deviceMode (e.g. 800x600 @ 30fps)
                if (camera == null || newDeviceMode > -1)
                {
                    if (initializeNew)
                    {
                        if (camera != null)
                        {
                            camera.Stop();
                            camera.Cleanup();
                        }
                    }
                    else
                    {
                        // No changes, just return
                        return;
                    }
                }

                // Specific configuration
                localCam = new DirectShowCamera(
                    DirectShowDevices.Instance.Cameras[newDeviceNumber].DirectshowDevice,
                    newDeviceNumber,
                    newDeviceMode,
                    DirectShowDevices.Instance.Cameras[newDeviceNumber].SupportedSizesAndFPS[newDeviceMode].FPS,
                    DirectShowDevices.Instance.Cameras[newDeviceNumber].SupportedSizesAndFPS[newDeviceMode].Width,
                    DirectShowDevices.Instance.Cameras[newDeviceNumber].SupportedSizesAndFPS[newDeviceMode].Height);

                //  If last set camera failed, try default mode
                if (localCam.HasValidGraph == false) // No specific deviceMode
                {
                    localCam.Cleanup();
                    localCam = new DirectShowCamera(
                        DirectShowDevices.Instance.Cameras[newDeviceNumber].DirectshowDevice,
                        newDeviceNumber,
                        0,
                        0,
                        0,
                        0);
                }

                //  If this is already occupied by another application and there
                //  are more than one camera connected, try the next one.
                if (localCam.HasValidGraph == false && DirectShowDevices.Instance.Cameras.Count() > 1)
                {
                    localCam.Cleanup();
                    localCam = new DirectShowCamera(
                        DirectShowDevices.Instance.Cameras[1].DirectshowDevice, 1, 0, 0, 0, 0);
                }

                // Finally, if running set this.camera to localCam
                if (localCam.HasValidGraph)
                {
                    localCam.IsSupportingROI = false;

                    // Switch
                    camera = localCam;
                    camera.Initialize();
                    camera.Start();

                    // Trigger global command, signal that a new camera has been started
                    // Listners for OnImage event has to re-subscribe
                    GTCommons.GTCommands.Instance.Camera.CameraChange();
                }
                else
                {
                    // Failed, start previous camera/mode again
                    camera.Start();
                }
            }
            catch (Exception)
            {
                //ErrorLogger.ProcessException(ex, false);
            }
        }