Video source for Microsoft Kinect's video camera.

The video source captures video data from Microsoft Kinect video camera, which is aimed originally as a gaming device for XBox 360 platform.

Prior to using the class, make sure you've installed Kinect's drivers as described on Open Kinect project's page.

In order to run correctly the class requires libfreenect.dll library to be put into solution's output folder. This can be found within the AForge.NET framework's distribution in Externals folder.

Sample usage:

// create video source KinectVideoCamera videoSource = new KinectVideoCamera( 0 ); // set NewFrame event handler videoSource.NewFrame += new NewFrameEventHandler( video_NewFrame ); // start the video source videoSource.Start( ); // ... private void video_NewFrame( object sender, NewFrameEventArgs eventArgs ) { // get new frame Bitmap bitmap = eventArgs.Frame; // process the frame }
Inheritance: IVideoSource
Beispiel #1
0
        // Disconnect from Kinect cameras
        private void Disconnect()
        {
            timer.Stop();

            if (videoCamera != null)
            {
                videoCameraPlayer.VideoSource = null;
                videoCamera.Stop();
                videoCamera = null;
            }

            if (depthCamera != null)
            {
                depthCameraPlayer.VideoSource = null;
                depthCamera.Stop();
                depthCamera = null;
            }

            if (kinectDevice != null)
            {
                kinectDevice.Dispose();
                kinectDevice = null;
            }
        }
Beispiel #2
0
        // Connect to Kinect cameras
        private bool Connect()
        {
            bool ret = false;

            Cursor = Cursors.WaitCursor;

            if (Kinect.DeviceCount != 0)
            {
                int deviceID = devicesCombo.SelectedIndex;

                try
                {
                    kinectDevice = Kinect.GetDevice(deviceID);

                    if (videoCamera == null)
                    {
                        videoCamera = kinectDevice.GetVideoCamera();
                        videoCamera.CameraMode = (videoModeCombo.SelectedIndex == 0) ? VideoCameraMode.Color :
                            ((videoModeCombo.SelectedIndex == 1) ? VideoCameraMode.Bayer : VideoCameraMode.InfraRed);
                        videoCameraPlayer.VideoSource = videoCamera;
                        videoCameraPlayer.Start();
                    }

                    if (depthCamera == null)
                    {
                        depthCamera = kinectDevice.GetDepthCamera();
                        depthCameraPlayer.VideoSource = depthCamera;
                        depthCameraPlayer.Start();
                    }

                    ledColorCombo.SelectedIndex = 0;

                    if (tiltUpDown.Value != 0)
                    {
                        tiltUpDown.Value = 0;
                    }
                    else
                    {
                        kinectDevice.SetMotorTilt((int)tiltUpDown.Value);
                    }

                    timer.Start();

                    ret = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed connecting to Kinect device.\n" + ex.Message,
                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    Disconnect();
                }
            }

            Cursor = Cursors.Default;

            return ret;
        }
Beispiel #3
0
        private void btnSelectCamera_Click(object sender, EventArgs e)
        {
            VideoCaptureDeviceForm form = new VideoCaptureDeviceForm();

            if (form.ShowDialog() == DialogResult.OK)
            {
                int deviceId = form.DeviceId;

                kinectDevice = Kinect.GetDevice(deviceId);

                if (videoCamera == null)
                {
                    videoCamera = kinectDevice.GetVideoCamera();
                    videoCamera.CameraMode = VideoCameraMode.Color;
                    videoCamera.NewFrame += new AForge.Video.NewFrameEventHandler(videoCamera_NewFrame);
                    videoCamera.Start();
                }

                if (depthCamera == null)
                {
                    depthCamera = new KinectDepthCamera(deviceId, CameraResolution.Medium,
                        provideOriginalDepthImage: true);

                    videoSourcePlayer1.VideoSource = depthCamera;
                    videoSourcePlayer1.Start();
                }

                toolStripStatusLabel1.Text = "Initializing...";
            }
        }