Example #1
0
		internal DepthRecorder(BinaryWriter writer,KinectSensor sensor)
		{
            _sensor = sensor;
			this.writer = writer;
			referenceTime = DateTime.Now;
            this._tmpDepthPixels = new DepthImagePixel[sensor.DepthStream.FramePixelDataLength];
            this._tmpDepthPoints = new DepthImagePoint[sensor.DepthStream.FramePixelDataLength];
		}
Example #2
0
 public DepthImage(GraphicsDevice graphics, int width, int height)
 {
     Width = width;
     Height = height;
     Points = new DepthImagePoint[width * height];
     RgbaData = new byte[width * height * 4];
     Texture = new Texture2D(graphics, width, height);
     SourceRectangle = new Rectangle(0, 0, width, height);
     GraphicsDevice = graphics;
 }
        private void DiscoverKinectSensor()
        {
            if (this._Kinect != null && this._Kinect.Status != KinectStatus.Connected)
            {
                this._Kinect.ColorStream.Disable();
                this._Kinect.DepthStream.Disable();
                this._Kinect.SkeletonStream.Disable();
                this._Kinect.Stop();
                this._Kinect.AudioSource.Stop();
                this._Kinect = null;
            }
            if (this._Kinect == null)
            {
                this._Kinect = KinectSensor.KinectSensors.FirstOrDefault(x => x.Status == KinectStatus.Connected);
                if (this._Kinect != null)
                {
                    //this._Kinect.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
                    this._Kinect.ColorStream.Enable(ColorImageFormat.RgbResolution1280x960Fps12);
                    this._Kinect.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
                    this._Kinect.DepthStream.Range = DepthRange.Default; //(Near from 400mm to 3000mm;   Default: xboxRange: from 800 mm to 4000mm)
                    this._Kinect.SkeletonStream.Enable();
                    this._Kinect.Start();
                    ColorImageStream colorStream = this._Kinect.ColorStream;
                    DepthImageStream depthStream = this._Kinect.DepthStream;

                    this.ColorImageElement.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        this._ColorImageBitmap = new WriteableBitmap(colorStream.FrameWidth, colorStream.FrameHeight, 96, 96, PixelFormats.Bgr32, null);
                        this._ColorImageBitmapRect = new Int32Rect(0, 0, colorStream.FrameWidth, colorStream.FrameHeight);
                        this._ColorImageStride = colorStream.FrameWidth * colorStream.FrameBytesPerPixel;
                        this._ColorImagePixelData = new byte[colorStream.FramePixelDataLength];
                        this.depthPoints = new DepthImagePoint[colorStream.FrameWidth * colorStream.FrameHeight];
                        this.ColorImageElement.Source = this._ColorImageBitmap;
                    }));

                    this.DepthImageElement.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        //this._DepthImageBitmap = new WriteableBitmap(depthStream.FrameWidth, depthStream.FrameHeight, 96, 96, PixelFormats.Gray16, null);
                        this._DepthImageBitmap = new WriteableBitmap(depthStream.FrameWidth, depthStream.FrameHeight, 96, 96, PixelFormats.Bgr32, null);
                        this._DepthImageBitmapRect = new Int32Rect(0, 0, depthStream.FrameWidth, depthStream.FrameHeight);
                        this._DepthImageStride = depthStream.FrameWidth * depthStream.FrameBytesPerPixel;
                        this._DepthColoredImageStride = depthStream.FrameWidth * colorStream.FrameBytesPerPixel;
                        this.depthPixels = new DepthImagePixel[depthStream.FramePixelDataLength];
                        this.RawDepthData = new short[depthStream.FramePixelDataLength];
                        this.colorPoints = new ColorImagePoint[depthStream.FrameWidth * depthStream.FrameHeight];
                        this.DepthImageElement.Source = this._DepthImageBitmap;
                    }));


                }
            }
        }
        internal void OnFrameReady(KinectSensor kinectSensor, ColorImageFormat colorImageFormat, byte[] colorImage, DepthImageFormat depthImageFormat, DepthImagePixel[] depthImage, DepthImagePoint[] colorMappedDepthPoints, Skeleton skeletonOfInterest = null)
        {
            this.Sensor = kinectSensor;

            if (this.ColorImageFormat != colorImageFormat)
            {
                this.ColorImageFormat = colorImageFormat;
            }

            if (this.DepthImageFormat != depthImageFormat)
            {
                this.DepthImageFormat = depthImageFormat;
            }
            this._colorMappedDepthPoints = colorMappedDepthPoints;
            OnFrameReadyOverride(kinectSensor, colorImageFormat, colorImage, depthImageFormat, depthImage, skeletonOfInterest);
        }
        public KinectSensorItem(MainWindow _controller, KinectSensor Sensor, string id, int kinectN)
        {
            this.controller = _controller;
            this.Sensor = Sensor;
            this.Id = id;
            this.USBID = RemoveSpecialCharacters(this.Id);
            this.kinectNr = kinectN;
            Name = "Default Kinect";
            StreamingStatus = "Not Ready";
            LoadSettings();

            int tries = 0;
            if (null != this.Sensor)
            {
                while (this.Sensor.Status != KinectStatus.Connected)
                {
                    System.Threading.Thread.Sleep(1000);
                    tries++;
                    if (tries == 4)
                        break;

                }
            }
            if (null != this.Sensor && this.Sensor.Status == KinectStatus.Connected)
            {
                //streams
                this.Sensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
                this.Sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);

                //the preview window
                this.depthPreview           = new byte[this.Sensor.DepthStream.FramePixelDataLength];

                //original input
                this.depthPixels            = new DepthImagePixel[this.Sensor.DepthStream.FramePixelDataLength];
                this.colorPixelsAligned     = new byte[this.Sensor.ColorStream.FramePixelDataLength];

                //alignment Data
                this.colorCoordinates       = new ColorImagePoint[this.Sensor.DepthStream.FramePixelDataLength];
                this.depthPoints            = new DepthImagePoint[this.Sensor.DepthStream.FramePixelDataLength];

                //World & depth data (shorts)
                this.pixelsToSendWorld      = new short[this.Sensor.DepthStream.FramePixelDataLength * 3]; //x
                this.pixelsToSendD          = new short[this.Sensor.DepthStream.FramePixelDataLength];
                this.worldPoints            = new SkeletonPoint[this.Sensor.DepthStream.FramePixelDataLength];

                //thnings that actually will be send
                this.pixelsToSendRGB        = new byte[this.Sensor.DepthStream.FramePixelDataLength * 3];
                this.pixelsToSendDByte      = new byte[pixelsToSendD.Length * sizeof(short)];
                this.pixelsToSendWorldByte  = new byte[pixelsToSendWorld.Length * sizeof(short)];
                this.emptyRGB = new byte[this.Sensor.DepthStream.FramePixelDataLength * 3];

                //some kinect stuff
                this.depthBitmap = new WriteableBitmap(this.Sensor.DepthStream.FrameWidth, this.Sensor.DepthStream.FrameHeight, 96.0, 96.0, PixelFormats.Gray8, null);
                this.Sensor.SkeletonStream.Enable();
                this.Sensor.AllFramesReady += SensorAllFramesReady;

                //the memory map
                this.mmf = MemoryMappedFile.CreateNew("kinect" + kinectN, 100 + this.Sensor.DepthStream.FramePixelDataLength * 11); //3 rgb, 2 depth, 3x2 world + 100 txt

                //pre-allocate the empty array
                for (int i = 0; i < emptyRGB.Length; i++)
                    emptyRGB[i] = 0;

                try
                {
                    this.Sensor.Start();
                }
                catch (IOException)
                {
                    this.Sensor = null;
                }
            }

            if (null == this.Sensor)
            {
                setStreamingStatus("Unable to connect");
            }
            else
            {
                setStreamingStatus("MMF = [kinect" + kinectNr + "]");
            }

            intensityLookupTable = new byte[8193];
            for (int i = 0; i < 8193; i++)
            {
                intensityLookupTable[i] = (byte)(((255 - (255 * i / 8192))));
            }

            lastTime = DateTime.Now;

            SaveSettings();
        }