예제 #1
0
 public VideoMode[] getSupportedVideoModes()
 {
     WrapperArray csa = SensorInfo_getSupportedVideoModes(this.Handle);
     IntPtr[] array = new IntPtr[csa.Size];
     Marshal.Copy(csa.Data, array, 0, csa.Size);
     VideoMode[] arrayObjects = new VideoMode[csa.Size];
     for (int i = 0; i < csa.Size; i++)
         arrayObjects[i] = new VideoMode(array[i], true);
     SensorInfo_destroyVideoModesArray(csa);
     return arrayObjects;
 }
예제 #2
0
        public VideoMode[] getSupportedVideoModes()
        {
            WrapperArray csa = SensorInfo_getSupportedVideoModes(this.Handle);

            IntPtr[] array = new IntPtr[csa.Size];
            Marshal.Copy(csa.Data, array, 0, csa.Size);
            VideoMode[] arrayObjects = new VideoMode[csa.Size];
            for (int i = 0; i < csa.Size; i++)
            {
                arrayObjects[i] = new VideoMode(array[i], true);
            }
            SensorInfo_destroyVideoModesArray(csa);
            return(arrayObjects);
        }
예제 #3
0
        public IEnumerable <VideoMode> GetSupportedVideoModes()
        {
            var csa   = SensorInfo_getSupportedVideoModes(Handle);
            var array = new IntPtr[csa.Size];

            Marshal.Copy(csa.Data, array, 0, csa.Size);
            var arrayObjects = new VideoMode[csa.Size];

            for (var i = 0; i < csa.Size; i++)
            {
                arrayObjects[i] = new VideoMode(array[i], true);
            }

            SensorInfo_destroyVideoModesArray(csa);

            return(arrayObjects);
        }
예제 #4
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;
        }