예제 #1
0
 internal static VideoStream Private_Create(Device device, Device.SensorType sensorType)
 {
     IntPtr handle;
     OpenNI.throwIfError(VideoStream_create(out handle, device.Handle, sensorType));
     VideoStream vs = new VideoStream(handle);
     vs.ParentDevice = device;
     vs.handler_events = VideoStream_RegisterListener(handle, vs.internal_NewFrame);
     return vs;
 }
예제 #2
0
 public static UserTracker Create(Device device = null)
 {
     IntPtr deviceHandle = IntPtr.Zero;
     if (device != null && device.isValid)
         deviceHandle = device.Handle;
     IntPtr handle;
     NiTE.throwIfError(UserTracker_create(out handle, deviceHandle));
     UserTracker ut = new UserTracker(handle);
     ut.handler_events = UserTracker_RegisterListener(handle, ut.internal_listener);
     return ut;
 }
예제 #3
0
 private void cb_devices_SelectedIndexChanged(object sender, EventArgs e)
 {
     cb_sensor.Items.Clear();
     if (cb_devices.SelectedItem != null)
     {
         if (currentDevice != null) currentDevice.Dispose();
         currentDevice = ((DeviceInfo)cb_devices.SelectedItem).OpenDevice();
         if (currentDevice.hasSensor(Device.SensorType.COLOR)) cb_sensor.Items.Add("Color");
         if (currentDevice.hasSensor(Device.SensorType.DEPTH)) cb_sensor.Items.Add("Depth");
         if (currentDevice.hasSensor(Device.SensorType.IR)) cb_sensor.Items.Add("IR");
     }
 }
예제 #4
0
        public static void Main(string[] args)
        {
            try
            {
                OpenNI.Initialize();
                device = Device.Open(Device.AnyDevice);

                depthStream = device.CreateVideoStream(Device.SensorType.Depth);
                depthStream.VideoMode = new VideoMode
                                            {
                                                DataPixelFormat = VideoMode.PixelFormat.Depth1Mm, 
                                                Fps = 30, 
                                                Resolution = new Size(640, 480)
                                            };

                colorStream = device.CreateVideoStream(Device.SensorType.Color);
                colorStream.VideoMode = new VideoMode
                                            {
                                                DataPixelFormat = VideoMode.PixelFormat.Rgb888, 
                                                Fps = 30, 
                                                Resolution = new Size(640, 480)
                                            };
                device.DepthColorSyncEnabled = true;
                depthStream.Start();
                colorStream.Start();
                device.ImageRegistration = Device.ImageRegistrationMode.DepthToColor;
                Console.WriteLine("Image registration is active and working well.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Press enter to exit.");
            Console.ReadLine();
            if (device != null)
            {
                device.Close();
            }

            OpenNI.Shutdown();
        }
예제 #5
0
        public KinectOpenNi2()
        {
            HandleError(OpenNI.Initialize());

              DeviceInfo[] devices = OpenNI.EnumerateDevices();
              if (devices.Length == 0)
            HandleError(OpenNI.Status.NO_DEVICE);

              kinectDevice = devices[0].OpenDevice();

              colorSensor = kinectDevice.CreateVideoStream(Device.SensorType.COLOR);
              VideoMode[] videoModes = colorSensor.SensorInfo.getSupportedVideoModes();
              colorSensor.VideoMode = videoModes[1];
              colorSensor.Start();
              colorSensor.onNewFrame += new VideoStream.VideoStreamNewFrame(colorSensor_onNewFrame);

              depthSensor = kinectDevice.CreateVideoStream(Device.SensorType.DEPTH);
              videoModes = depthSensor.SensorInfo.getSupportedVideoModes();
              depthSensor.VideoMode = videoModes[0];
              depthSensor.Start();
              depthSensor.onNewFrame += new VideoStream.VideoStreamNewFrame(depthSensor_onNewFrame);
        }
예제 #6
0
        public OpenKinect()
        {
            HandleOpenNIError(OpenNI.Initialize());
            DeviceInfo[] devices = OpenNI.EnumerateDevices();
            if (devices.Length == 0)
                HandleOpenNIError(OpenNI.Status.NoDevice);
            kinectDevice = devices[0].OpenDevice();

            colorSensor = kinectDevice.CreateVideoStream(Device.SensorType.Color);
            colorSensor.VideoMode = colorSensor.SensorInfo.GetSupportedVideoModes()[1];

            //Start Skeleton Sensor
            HandleNiteError(NiTE.Initialize());
            try
            {
                SkeletonSensor = UserTracker.Create();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
예제 #7
0
        private void CbDevicesSelectedIndexChanged(object sender, EventArgs e)
        {
            this.cb_sensor.Items.Clear();
            if (this.cb_devices.SelectedItem != null)
            {
                if (this.currentDevice != null)
                {
                    this.currentDevice.Dispose();
                }

                this.currentDevice = ((DeviceInfo)this.cb_devices.SelectedItem).OpenDevice();
                if (this.currentDevice.HasSensor(Device.SensorType.Color))
                {
                    this.cb_sensor.Items.Add("Color");
                }

                if (this.currentDevice.HasSensor(Device.SensorType.Depth))
                {
                    this.cb_sensor.Items.Add("Depth");
                }

                if (this.currentDevice.HasSensor(Device.SensorType.Ir))
                {
                    this.cb_sensor.Items.Add("IR");
                }
            }
        }
예제 #8
0
        public static HandTracker Create(Device device = null)
        {
            IntPtr deviceHandle = IntPtr.Zero;
            if (device != null && device.IsValid)
            {
                deviceHandle = device.Handle;
            }

            IntPtr handle;
            NiTE.ThrowIfError(HandTracker_create(out handle, deviceHandle));
            HandTracker ut = new HandTracker(handle);
            ut.handlerEvents = HandTracker_RegisterListener(handle, ut.internalListener);
            return ut;
        }
예제 #9
0
        //private Bitmap DepthFix(Bitmap depthBitmap)
        //{
        //    Bitmap x = new Bitmap(640, 480);
        //    Graphics g = Graphics.FromImage(x);
        //    g.DrawImage(depthBitmap, new Rectangle(30, 8, 600, 450));
        //    g.Flush();
        //    g.Dispose();
        //    return x;
        //}
        private void DeviceChanged()
        {
            this.but_anag.Enabled = false;
            this.but_stereo.Enabled = false;
            this.but_saveall.Enabled = false;
            if (this.selectedDevice != null)
            {
                this.selectedDevice.Close();
            }

            if (this.cb_devices.Items.Count < 1)
            {
                this.selectedDevice = null;
                return;
            }

            if (this.cb_devices.SelectedItem == null)
            {
                this.selectedDevice = null;
                return;
            }

            if (this.cb_devices.SelectedItem is string && this.cb_devices.SelectedItem.ToString() == "None")
            {
                this.selectedDevice = null;
                return;
            }

            if (!(this.cb_devices.SelectedItem is DeviceInfo))
            {
                this.selectedDevice = null;
                MessageBox.Show(
                    "Selected item is not a device.",
                    "Device Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            try
            {
                this.selectedDevice = (this.cb_devices.SelectedItem as DeviceInfo).OpenDevice();
            }
            catch (Exception)
            {
                this.selectedDevice = null;
                MessageBox.Show(
                    "Can not open selected device.",
                    "Device Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            if (!this.selectedDevice.hasSensor(Device.SensorType.COLOR))
            {
                this.selectedDevice.Close();
                this.selectedDevice = null;
                MessageBox.Show(
                    "Selected device can not offer depth stream.",
                    "Device Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            if (!this.selectedDevice.hasSensor(Device.SensorType.DEPTH))
            {
                this.selectedDevice.Close();
                this.selectedDevice = null;
                MessageBox.Show(
                    "Selected device can not offer depth stream.",
                    "Device Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            try
            {
                this.depthStream = this.selectedDevice.CreateVideoStream(Device.SensorType.DEPTH);
                this.colorStream = this.selectedDevice.CreateVideoStream(Device.SensorType.COLOR);
            }
            catch (Exception)
            {
                this.selectedDevice.Close();
                this.selectedDevice = null;
                this.depthStream = null;
                this.colorStream = null;
                MessageBox.Show(
                    "Can not create Depth and Color streams.",
                    "Device Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            this.cb_hd.Enabled = false;
            foreach (VideoMode vm in this.colorStream.SensorInfo.getSupportedVideoModes())
            {
                if (vm.Resolution.Equals(new Size(1280, 1024)) || vm.Resolution.Equals(new Size(1280, 960)))
                {
                    this.cb_hd.Enabled = true;
                    this.isUse960asHD = vm.Resolution.Height == 960;
                    break;
                }
            }

            VideoMode depthMode = new VideoMode
                                      {
                                          Resolution = new Size(640, 480),
                                          FPS = 30,
                                          DataPixelFormat = VideoMode.PixelFormat.DEPTH_1MM
                                      };
            VideoMode colorMode = new VideoMode
                                      {
                                          Resolution = new Size(640, 480),
                                          FPS = 30,
                                          DataPixelFormat = VideoMode.PixelFormat.RGB888
                                      };
            if (this.cb_hd.Enabled && this.cb_hd.Checked)
            {
                colorMode.Resolution = this.isUse960asHD ? new Size(1280, 960) : new Size(1280, 1024);
            }

            try
            {
                this.depthStream.VideoMode = depthMode;
                this.colorStream.VideoMode = colorMode;
            }
            catch (Exception)
            {
                this.selectedDevice.Close();
                this.selectedDevice = null;
                this.depthStream = null;
                this.colorStream = null;
                MessageBox.Show(
                    "Can not set Depth and Color streams video mode to 640x480@30fps. This application need at least this resolution.",
                    "Device Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            try
            {
                this.selectedDevice.ImageRegistration = Device.ImageRegistrationMode.DEPTH_TO_COLOR;
            }
            catch (Exception)
            {
                MessageBox.Show(
                    "We failed to register image over depth map.",
                    "Device Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);
            }

            try
            {
                // this.selectedDevice.DepthColorSyncEnabled = true;
            }
            catch (Exception)
            {
            }

            if (!this.HandleError(this.depthStream.Start()) || !this.HandleError(this.colorStream.Start()))
            {
                this.selectedDevice.Close();
                this.selectedDevice = null;
                this.depthStream = null;
                this.colorStream = null;
                MessageBox.Show(
                    "Can not start depth and color streams.",
                    "Device Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            this.depthStream.onNewFrame += this.depthStream_onNewFrame;
            this.colorStream.onNewFrame += this.colorStream_onNewFrame;
            this.but_anag.Enabled = true;
            this.but_stereo.Enabled = true;
            this.but_saveall.Enabled = true;
        }
예제 #10
0
 public static VideoStream Create(Device device, Device.SensorType sensorType)
 {
     return device.CreateVideoStream(sensorType);
 }
예제 #11
0
 static extern OpenNI.Status VideoStream_create(out IntPtr objectHandler, IntPtr device, Device.SensorType sensorType);
예제 #12
0
 void Stop(bool isApply)
 {
     bool isSameDevice = isApply && currentDevice != null && currentDevice.isValid && currentDevice.DeviceInfo.URI == NiUI.Properties.Settings.Default.DeviceURI;
     bool isSameSensor = isApply && isSameDevice && currentSensor != null && currentSensor.isValid && currentSensor.SensorInfo.getSensorType() == (Device.SensorType)NiUI.Properties.Settings.Default.CameraType;
     if (!isSameSensor)
     {
         if (currentSensor != null && currentSensor.isValid)
         {
             currentSensor.Stop();
             currentSensor.onNewFrame -= currentSensor_onNewFrame;
         }
         currentSensor = null;
     }
     if (!isSameDevice)
     {
         //if (uTracker != null && uTracker.isValid)
         //    uTracker.Destroy();
         //if (hTracker != null && hTracker.isValid)
         //    hTracker.Destroy();
         if (currentDevice != null && currentDevice.isValid)
             currentDevice.Close();
         //hTracker = null;
         //uTracker = null;
         currentDevice = null;
     }
     isIdle = true;
     btn_stopstart.Text = "Start Streaming";
     if (!isApply)
     {
         broadcaster.ClearScreen();
         pb_image.Image = null;
         pb_image.Refresh();
     }
     if (NiUI.Properties.Settings.Default.AutoNotification)
         notify.Visible = false;
 }
예제 #13
0
        bool Start()
        {
            RegisterFilter();
            if (this.isIdle && broadcaster.hasServer())
            {
                MessageBox.Show("Only one server is allowed.", "Multi-Server", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            bool isSameDevice = currentDevice != null && currentDevice.isValid && currentDevice.DeviceInfo.URI == NiUI.Properties.Settings.Default.DeviceURI;
            bool isSameSensor = isSameDevice && currentSensor != null && currentSensor.isValid && currentSensor.SensorInfo.getSensorType() == (Device.SensorType)NiUI.Properties.Settings.Default.CameraType;
            if (!isSameDevice)
            {
                if (NiUI.Properties.Settings.Default.DeviceURI == string.Empty)
                {
                    currentDevice = null;
                    MessageBox.Show("Please select a device to open and then click Apply.", "Device Open", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return false;
                }
            }
            if (!isSameSensor)
            {
                if (NiUI.Properties.Settings.Default.CameraType == -1)
                {
                    currentDevice = null;
                    MessageBox.Show("Please select a sensor to open and then click Apply.", "Sensor Create", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return false;
                }
            }
            if (!isSameDevice)
            {
                try
                {
                    currentDevice = Device.Open(NiUI.Properties.Settings.Default.DeviceURI);
                }
                catch (Exception ex)
                {
                    currentDevice = null;
                    MessageBox.Show("Can not open selected Device. " + ex.Message, "Device Open", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return false;
                }
            }
            if (!isSameSensor)
            {
                try
                {
                    currentSensor = currentDevice.CreateVideoStream((Device.SensorType)NiUI.Properties.Settings.Default.CameraType);
                    currentSensor.onNewFrame += currentSensor_onNewFrame;
                }
                catch (Exception ex)
                {
                    currentSensor = null;
                    MessageBox.Show("Can not open selected Sensor from selected Device. " + ex.Message, "Sensor Create", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return false;
                }
            }
            else
            {
                currentSensor.Stop();
            }
            VideoMode[] vmodes = currentSensor.SensorInfo.getSupportedVideoModes();
            VideoMode selectedVideoMode = null;
            switch (currentSensor.SensorInfo.getSensorType())
            {
                case Device.SensorType.COLOR:
                    renderOptions = VideoFrameRef.copyBitmapOptions.Force24BitRGB;
                    if (NiUI.Properties.Settings.Default.Color_HD)
                    {
                        foreach (VideoMode vm in vmodes)
                            if (vm.Resolution.Width == 1280 && (vm.Resolution.Height == 960 || vm.Resolution.Height == 1024))
                                if ((selectedVideoMode == null || (selectedVideoMode.FPS < vm.FPS && vm.DataPixelFormat < selectedVideoMode.DataPixelFormat)) &&
                                    vm.DataPixelFormat != VideoMode.PixelFormat.JPEG && vm.DataPixelFormat != VideoMode.PixelFormat.YUV422)
                                    selectedVideoMode = vm;
                        isHD = selectedVideoMode != null;
                        if (!isHD)
                            MessageBox.Show("This device doesn't support ~1.3MP resolution.", "HD Resolution", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    if (selectedVideoMode == null)
                        foreach (VideoMode vm in vmodes)
                            if (vm.Resolution == new Size(640, 480))
                                if ((selectedVideoMode == null || (selectedVideoMode.FPS < vm.FPS && vm.DataPixelFormat < selectedVideoMode.DataPixelFormat)) &&
                                    vm.DataPixelFormat != VideoMode.PixelFormat.JPEG && vm.DataPixelFormat != VideoMode.PixelFormat.YUV422)
                                    selectedVideoMode = vm;
                    break;
                case Device.SensorType.DEPTH:
                    renderOptions = VideoFrameRef.copyBitmapOptions.Force24BitRGB | VideoFrameRef.copyBitmapOptions.DepthFillShadow;
                    if (NiUI.Properties.Settings.Default.Depth_Fill)
                        if (cb_mirror.Enabled && cb_mirror.Checked)
                            renderOptions |= VideoFrameRef.copyBitmapOptions.DepthFillRigthBlack;
                        else
                            renderOptions |= VideoFrameRef.copyBitmapOptions.DepthFillLeftBlack;
                    if (NiUI.Properties.Settings.Default.Depth_Invert)
                        renderOptions |= VideoFrameRef.copyBitmapOptions.DepthInvert;
                    if (NiUI.Properties.Settings.Default.Depth_Histogram)
                        renderOptions |= VideoFrameRef.copyBitmapOptions.DepthHistogramEqualize;
                    foreach (VideoMode vm in vmodes)
                        if (vm.Resolution == new Size(640, 480))
                            if ((selectedVideoMode == null || selectedVideoMode.FPS < vm.FPS) &&
                                (vm.DataPixelFormat == VideoMode.PixelFormat.DEPTH_1MM || vm.DataPixelFormat == VideoMode.PixelFormat.DEPTH_100UM))
                                selectedVideoMode = vm;
                    break;
                case Device.SensorType.IR:
                    renderOptions = VideoFrameRef.copyBitmapOptions.Force24BitRGB;
                    foreach (VideoMode vm in vmodes)
                        if (vm.Resolution == new Size(640, 480))
                            if ((selectedVideoMode == null || (selectedVideoMode.FPS < vm.FPS && vm.DataPixelFormat < selectedVideoMode.DataPixelFormat)) &&
                                vm.DataPixelFormat != VideoMode.PixelFormat.JPEG && vm.DataPixelFormat != VideoMode.PixelFormat.YUV422)
                                selectedVideoMode = vm;
                    break;
                default:
                    break;
            }

            if (selectedVideoMode != null)
                try
                {
                    if (currentSensor.VideoMode.FPS != selectedVideoMode.FPS || currentSensor.VideoMode.DataPixelFormat != selectedVideoMode.DataPixelFormat || currentSensor.VideoMode.Resolution != selectedVideoMode.Resolution)
                        currentSensor.VideoMode = selectedVideoMode;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Can not set active video mode to " + selectedVideoMode.ToString() + ". " + ex.Message, "Sensor Config", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return false;
                }
            else
            {
                MessageBox.Show("No acceptable video mode found.", "Sensor Config", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            softMirror = NiUI.Properties.Settings.Default.Mirroring;
            //if (NiUI.Properties.Settings.Default.Mirroring)
                //try
                //{
                //    if (currentSensor.Mirroring != cb_mirror.Checked)
                //        currentSensor.Mirroring = cb_mirror.Checked;
                //}
                //catch (Exception ex)
                //{
                //    MessageBox.Show("Can not enable mirroring. " + ex.Message, "Sensor Config", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                //}
            if (NiUI.Properties.Settings.Default.SmartCam)
            {
                try
                {
                    if (!isSameDevice || (uTracker == null || hTracker == null || !uTracker.isValid || !hTracker.isValid))
                    {
                        uTracker = NiTEWrapper.UserTracker.Create(currentDevice);
                        hTracker = NiTEWrapper.HandTracker.Create(currentDevice);
                        hTracker.StartGestureDetection(NiTEWrapper.GestureData.GestureType.HAND_RAISE);
                        hTracker.onNewData += new NiTEWrapper.HandTracker.HandTrackerListener(NiTE_onNewData);
                    }
                }
                catch (Exception) { }
            }
            if (!HandleError(currentSensor.Start()))
            {
                Stop(false);
                return false;
            }
            btn_stopstart.Text = "Stop Streaming";
            isIdle = false;
            notify.Visible = true;
            return true;
        }
예제 #14
0
 private void Stop(bool isApply)
 {
     bool isSameDevice = isApply && this.currentDevice != null && this.currentDevice.IsValid
                         && this.currentDevice.DeviceInfo.Uri == Settings.Default.DeviceURI;
     bool isSameSensor = isApply && isSameDevice && this.currentSensor != null && this.currentSensor.IsValid
                         && this.currentSensor.SensorInfo.GetSensorType()
                         == (Device.SensorType)Settings.Default.CameraType;
     if (!isSameSensor)
     {
         if (this.currentSensor != null && this.currentSensor.IsValid)
         {
             this.currentSensor.Stop();
             this.currentSensor.OnNewFrame -= this.CurrentSensorOnNewFrame;
         }
         this.currentSensor = null;
     }
     if (!isSameDevice)
     {
         if (this.currentDevice != null && this.currentDevice.IsValid)
         {
             this.currentDevice.Close();
         }
         this.currentDevice = null;
     }
     this.isIdle = true;
     this.btn_stopstart.Text = @"Start Streaming";
     if (!isApply)
     {
         this.broadcaster.ClearScreen();
         this.pb_image.Image = null;
         this.pb_image.Refresh();
     }
     if (Settings.Default.AutoNotification)
     {
         this.notify.Visible = false;
     }
 }
예제 #15
0
        private bool Start()
        {
            RegisterFilter();
            if (this.isIdle && this.broadcaster.HasServer())
            {
                MessageBox.Show(
                    @"Only one server is allowed.",
                    @"Multi-Server",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return false;
            }
            bool isSameDevice = this.currentDevice != null && this.currentDevice.IsValid
                                && this.currentDevice.DeviceInfo.Uri == Settings.Default.DeviceURI;
            bool isSameSensor = isSameDevice && this.currentSensor != null && this.currentSensor.IsValid
                                && this.currentSensor.SensorInfo.GetSensorType()
                                == (Device.SensorType)Settings.Default.CameraType;
            if (!isSameDevice)
            {
                if (Settings.Default.DeviceURI == string.Empty)
                {
                    this.currentDevice = null;
                    MessageBox.Show(
                        @"Please select a device to open and then click Apply.",
                        @"Device Open",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning);
                    return false;
                }
            }
            if (!isSameSensor)
            {
                if (Settings.Default.CameraType == -1)
                {
                    this.currentDevice = null;
                    MessageBox.Show(
                        @"Please select a sensor to open and then click Apply.",
                        @"Sensor Create",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning);
                    return false;
                }
            }
            if (!isSameDevice)
            {
                try
                {
                    this.currentDevice = Device.Open(Settings.Default.DeviceURI);
                }
                catch (Exception ex)
                {
                    this.currentDevice = null;
                    MessageBox.Show(
                        string.Format("Can not open selected Device. {0}", ex.Message),
                        @"Device Open",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    return false;
                }
            }
            if (!isSameSensor)
            {
                try
                {
                    this.currentSensor =
                        this.currentDevice.CreateVideoStream((Device.SensorType)Settings.Default.CameraType);
                    this.currentSensor.OnNewFrame += this.CurrentSensorOnNewFrame;
                }
                catch (Exception ex)
                {
                    this.currentSensor = null;
                    MessageBox.Show(
                        string.Format("Can not open selected Sensor from selected Device. {0}", ex.Message),
                        @"Sensor Create",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    return false;
                }
            }
            else
            {
                this.currentSensor.Stop();
            }
            VideoMode[] vmodes = this.currentSensor.SensorInfo.GetSupportedVideoModes().ToArray();
            VideoMode selectedVideoMode = null;
            switch (this.currentSensor.SensorInfo.GetSensorType())
            {
                case Device.SensorType.Color:
                    this.renderOptions = VideoFrameRef.CopyBitmapOptions.Force24BitRgb;
                    if (Settings.Default.Color_HD)
                    {
                        foreach (VideoMode vm in vmodes)
                        {
                            if (vm.Resolution.Width == 1280
                                && (vm.Resolution.Height == 960 || vm.Resolution.Height == 1024))
                            {
                                if ((selectedVideoMode == null
                                     || (selectedVideoMode.Fps < vm.Fps
                                         && vm.DataPixelFormat < selectedVideoMode.DataPixelFormat))
                                    && vm.DataPixelFormat != VideoMode.PixelFormat.Jpeg
                                    && vm.DataPixelFormat != VideoMode.PixelFormat.Yuv422)
                                {
                                    selectedVideoMode = vm;
                                }
                            }
                        }
                        this.isHd = selectedVideoMode != null;
                        if (!this.isHd)
                        {
                            MessageBox.Show(
                                @"This device doesn't support ~1.3MP resolution.",
                                @"HD Resolution",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                        }
                    }
                    if (selectedVideoMode == null)
                    {
                        foreach (VideoMode vm in vmodes)
                        {
                            if (vm.Resolution == new Size(640, 480))
                            {
                                if ((selectedVideoMode == null
                                     || (selectedVideoMode.Fps < vm.Fps
                                         && vm.DataPixelFormat < selectedVideoMode.DataPixelFormat))
                                    && vm.DataPixelFormat != VideoMode.PixelFormat.Jpeg
                                    && vm.DataPixelFormat != VideoMode.PixelFormat.Yuv422)
                                {
                                    selectedVideoMode = vm;
                                }
                            }
                        }
                    }
                    break;
                case Device.SensorType.Depth:
                    this.renderOptions = VideoFrameRef.CopyBitmapOptions.Force24BitRgb
                                         | VideoFrameRef.CopyBitmapOptions.DepthFillShadow;
                    if (Settings.Default.Depth_Fill)
                    {
                        if (this.cb_mirror.Enabled && this.cb_mirror.Checked)
                        {
                            this.renderOptions |= VideoFrameRef.CopyBitmapOptions.DepthFillRigthBlack;
                        }
                        else
                        {
                            this.renderOptions |= VideoFrameRef.CopyBitmapOptions.DepthFillLeftBlack;
                        }
                    }
                    if (Settings.Default.Depth_Invert)
                    {
                        this.renderOptions |= VideoFrameRef.CopyBitmapOptions.DepthInvert;
                    }
                    if (Settings.Default.Depth_Histogram)
                    {
                        this.renderOptions |= VideoFrameRef.CopyBitmapOptions.DepthHistogramEqualize;
                    }
                    foreach (VideoMode vm in vmodes)
                    {
                        if (vm.Resolution == new Size(640, 480))
                        {
                            if ((selectedVideoMode == null || selectedVideoMode.Fps < vm.Fps)
                                && (vm.DataPixelFormat == VideoMode.PixelFormat.Depth1Mm
                                    || vm.DataPixelFormat == VideoMode.PixelFormat.Depth100Um))
                            {
                                selectedVideoMode = vm;
                            }
                        }
                    }
                    break;
                case Device.SensorType.Ir:
                    this.renderOptions = VideoFrameRef.CopyBitmapOptions.Force24BitRgb;
                    foreach (VideoMode vm in vmodes)
                    {
                        if (vm.Resolution == new Size(640, 480))
                        {
                            if ((selectedVideoMode == null
                                 || (selectedVideoMode.Fps < vm.Fps
                                     && vm.DataPixelFormat < selectedVideoMode.DataPixelFormat))
                                && vm.DataPixelFormat != VideoMode.PixelFormat.Jpeg
                                && vm.DataPixelFormat != VideoMode.PixelFormat.Yuv422)
                            {
                                selectedVideoMode = vm;
                            }
                        }
                    }
                    break;
            }

            if (selectedVideoMode != null)
            {
                try
                {
                    if (this.currentSensor.VideoMode.Fps != selectedVideoMode.Fps
                        || this.currentSensor.VideoMode.DataPixelFormat != selectedVideoMode.DataPixelFormat
                        || this.currentSensor.VideoMode.Resolution != selectedVideoMode.Resolution)
                    {
                        this.currentSensor.VideoMode = selectedVideoMode;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(
                        string.Format("Can not set active video mode to {0}. {1}", selectedVideoMode, ex.Message),
                        @"Sensor Config",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    return false;
                }
            }
            else
            {
                MessageBox.Show(
                    @"No acceptable video mode found.",
                    @"Sensor Config",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return false;
            }
            this.softMirror = Settings.Default.Mirroring;
            if (Settings.Default.SmartCam)
            {
                try
                {
                    if (!isSameDevice
                        || (this.uTracker == null || this.hTracker == null || !this.uTracker.IsValid
                            || !this.hTracker.IsValid))
                    {
                        this.uTracker = UserTracker.Create(this.currentDevice);
                        this.hTracker = HandTracker.Create(this.currentDevice);
                        this.hTracker.StartGestureDetection(GestureData.GestureType.HandRaise);
                        this.hTracker.OnNewData += this.NiTeOnNewData;
                    }
                }
                catch (Exception)
                {
                }
            }
            if (!HandleError(this.currentSensor.Start()))
            {
                this.Stop(false);
                return false;
            }
            this.btn_stopstart.Text = @"Stop Streaming";
            this.isIdle = false;
            this.notify.Visible = true;
            return true;
        }