AForge.Video.Kinect.KinectDepthCamera.Start C# (CSharp) Метод

Start() публичный Метод

Start video source.
Starts video source and returns execution to caller. Video camera will be started and will provide new video frames through the NewFrame event.
The specified resolution is not supported for the selected /// mode of the Kinect depth sensor. Could not connect to Kinect's depth sensor. Another connection to the specified depth sensor is already running.
public Start ( ) : void
Результат void
        public void Start( )
        {
            lock ( sync )
            {
                lock ( runningCameras )
                {
                    if ( device == null )
                    {
                        bool success = false;

                        try
                        {
                            if ( runningCameras.Contains( deviceID ) )
                            {
                                throw new DeviceBusyException( "Another connection to the specified depth camera is already running." );
                            }

                            device = Kinect.GetDevice( deviceID );

                            // find depth format parameters
                            depthModeInfo = KinectNative.freenect_find_depth_mode( resolution, KinectNative.DepthCameraFormat.Format11Bit );

                            if ( depthModeInfo.IsValid == 0 )
                            {
                                throw new ArgumentException( "The specified resolution is not supported for the selected mode of the Kinect depth camera." );
                            }

                            // set depth format
                            if ( KinectNative.freenect_set_depth_mode( device.RawDevice, depthModeInfo ) != 0 )
                            {
                                throw new VideoException( "Could not switch to the specified depth format." );
                            }

                            // allocate video buffer and provide it freenect
                            imageBuffer = Marshal.AllocHGlobal( (int) depthModeInfo.Bytes );
                            KinectNative.freenect_set_depth_buffer( device.RawDevice, imageBuffer );

                            // set video callback
                            videoCallback = new KinectNative.FreenectDepthDataCallback( HandleDataReceived );
                            KinectNative.freenect_set_depth_callback( device.RawDevice, videoCallback );

                            // start the camera
                            if ( KinectNative.freenect_start_depth( device.RawDevice ) != 0 )
                            {
                                throw new ConnectionFailedException( "Could not start depth stream." );
                            }

                            success = true;
                            runningCameras.Add( deviceID );

                            device.AddFailureHandler( deviceID, Stop );
                        }
                        finally
                        {
                            if ( !success )
                            {
                                if ( device != null )
                                {
                                    device.Dispose( );
                                    device = null;
                                }

                                if ( imageBuffer != IntPtr.Zero )
                                {
                                    Marshal.FreeHGlobal( imageBuffer );
                                    imageBuffer = IntPtr.Zero;
                                }
                            }
                        }
                    }
                }
            }
        }