Пример #1
0
        public static void DisposeSensor()
        {
            try
            {
                var sensor = Sensor;
                if (sensor != null && sensor.IsOpen)
                {
                    sensor.Close();
                    sensor = null;
                    Sensor = null;
                }

                if (context != null)
                {
                    context.Exit();
                    context.Dispose();
                    context = null;

                    contexThread.Abort();
                    refreshThread.Abort();
                }
            }
            catch
            {
                Trace.WriteLine("Error of disable the Kinect sensor!");
            }
        }
Пример #2
0
        public static void DisposeSensor()
        {
            try
            {
                var sensor = Sensor;
                if (sensor != null && sensor.IsOpen)
                {
                    sensor.Close();
                    sensor = null;
                    Sensor = null;
                }

                if (context != null)
                {
                    context.Exit();
                    context.Dispose();
                    context = null;

                    contexThread.Abort();
                    refreshThread.Abort();
                }
            }
            catch
            {
                Trace.WriteLine("Error of disable the Kinect sensor!");
            }
        }
Пример #3
0
        static void InitializeSensor()
        {
            var sensor = Sensor;

            if (sensor != null)
            {
                return;
            }

            try
            {
                sensor = KinectSensor.GetDefault();
                if (sensor == null)
                {
                    return;
                }

                //var reader = sensor.BodyIndexFrameSource.OpenReader();

                var reader = sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Color | FrameSourceTypes.BodyIndex);

                //reader.FrameArrived += reader_BodyIndexFrameArrived;

                reader.MultiSourceFrameArrived += reader_MultiSourceFrameArrived;

                sensor.Open();

                Sensor = sensor;

                if (context == null)
                {
                    contexThread = new Thread(() =>
                    {
                        context = new KinectCamApplicationContext();
                        Application.Run(context);
                    });
                    refreshThread = new Thread(() =>
                    {
                        while (true)
                        {
                            Thread.Sleep(250);
                            Application.DoEvents();
                        }
                    });
                    contexThread.IsBackground  = true;
                    refreshThread.IsBackground = true;
                    contexThread.SetApartmentState(ApartmentState.STA);
                    refreshThread.SetApartmentState(ApartmentState.STA);
                    contexThread.Start();
                    refreshThread.Start();
                }
            }
            catch
            {
                Trace.WriteLine("Error of enable the Kinect sensor!");
            }
        }
Пример #4
0
        static void InitializeSensor()
        {
            var sensor = Sensor;
            if (sensor != null) return;

            try
            {
                sensor = KinectSensor.GetDefault();
                if (sensor == null) return;

                //var reader = sensor.ColorFrameSource.OpenReader();

                var reader = sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Color | FrameSourceTypes.BodyIndex);

                //reader.FrameArrived += reader_FrameArrived;

                reader.MultiSourceFrameArrived += reader_MultiSourceFrameArrived;

                sensor.Open();

                Sensor = sensor;

                if (context == null)
                {
                    contexThread = new Thread(() =>
                    {
                        context = new KinectCamApplicationContext();
                        Application.Run(context);
                    });
                    refreshThread = new Thread(() =>
                    {
                        while (true)
                        {
                            Thread.Sleep(250);
                            Application.DoEvents();
                        }
                    });
                    contexThread.IsBackground = true;
                    refreshThread.IsBackground = true;
                    contexThread.SetApartmentState(ApartmentState.STA);
                    refreshThread.SetApartmentState(ApartmentState.STA);
                    contexThread.Start();
                    refreshThread.Start();
                }
            }
            catch
            {
                Trace.WriteLine("Error of enable the Kinect sensor!");
            }
        }
        static void InitializeSensor()
        {
            var sensor = Sensor;

            if (sensor != null)
            {
                return;
            }

            try
            {
                sensor = KinectSensor.GetDefault();
                if (sensor == null)
                {
                    return;
                }

                var reader = sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Depth | FrameSourceTypes.Color | FrameSourceTypes.BodyIndex);
                reader.MultiSourceFrameArrived += Reader_MultiSourceFrameArrived;

                coordinateMapper = sensor.CoordinateMapper;

                FrameDescription depthFrameDescription = sensor.DepthFrameSource.FrameDescription;

                int depthWidth  = depthFrameDescription.Width;
                int depthHeight = depthFrameDescription.Height;

                /*FrameDescription colorFrameDescription = sensor.ColorFrameSource.FrameDescription;
                 *
                 * int colorWidth = colorFrameDescription.Width;
                 * int colorHeight = colorFrameDescription.Height;
                 *
                 * colorMappedToDepthPoints = new DepthSpacePoint[colorWidth * colorHeight];
                 *
                 * bitmap = new WriteableBitmap(colorWidth, colorHeight, 96.0, 96.0, PixelFormats.Bgra32, null);
                 *
                 * // Calculate the WriteableBitmap back buffer size
                 * bitmapBackBufferSize = (uint)((bitmap.BackBufferStride * (bitmap.PixelHeight - 1)) + (bitmap.PixelWidth * bytesPerPixel));*/


                sensor.Open();

                Sensor = sensor;

                if (context == null)
                {
                    contexThread = new Thread(() =>
                    {
                        context = new KinectCamApplicationContext();
                        Application.Run(context);
                    });
                    refreshThread = new Thread(() =>
                    {
                        while (true)
                        {
                            Thread.Sleep(250);
                            Application.DoEvents();
                        }
                    });
                    contexThread.IsBackground  = true;
                    refreshThread.IsBackground = true;
                    contexThread.SetApartmentState(ApartmentState.STA);
                    refreshThread.SetApartmentState(ApartmentState.STA);
                    contexThread.Start();
                    refreshThread.Start();
                }
            }
            catch
            {
                Trace.WriteLine("Error of enable the Kinect sensor!");
            }
        }
Пример #6
0
        static void InitializeSensor()
        {
            var sensor = Sensor;

            if (sensor != null)
            {
                return;
            }

            try
            {
                sensor = KinectSensor.GetDefault();
                if (sensor == null)
                {
                    return;
                }

                var reader = sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Depth | FrameSourceTypes.Color | FrameSourceTypes.BodyIndex);
                reader.MultiSourceFrameArrived += Reader_MultiSourceFrameArrived;

                coordinateMapper = sensor.CoordinateMapper;

                FrameDescription depthFrameDescription = sensor.DepthFrameSource.FrameDescription;

                int depthWidth  = depthFrameDescription.Width;
                int depthHeight = depthFrameDescription.Height;

                FrameDescription colorFrameDescription = sensor.ColorFrameSource.FrameDescription;

                int colorWidth  = colorFrameDescription.Width;
                int colorHeight = colorFrameDescription.Height;

                colorMappedToDepthPoints = new DepthSpacePoint[colorWidth * colorHeight];

                sensor.Open();

                Sensor = sensor;

                if (context == null)
                {
                    contexThread = new Thread(() =>
                    {
                        context = new KinectCamApplicationContext();
                        Application.Run(context);
                    });
                    refreshThread = new Thread(() =>
                    {
                        while (true)
                        {
                            Thread.Sleep(250);
                            Application.DoEvents();
                        }
                    });
                    contexThread.IsBackground  = true;
                    refreshThread.IsBackground = true;
                    contexThread.SetApartmentState(ApartmentState.STA);
                    refreshThread.SetApartmentState(ApartmentState.STA);
                    contexThread.Start();
                    refreshThread.Start();
                }
            }
            catch
            {
                Trace.WriteLine("Error of enable the Kinect sensor!");
            }
        }