Ejemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        //alloc max buf size for float3
        outBufferData = new Vector3[maxBufferSize];

        //Get the sensor on the kinect
        this.sensor = KinectSensor.GetDefault();

        //Null? Throw a unity exception
        if (this.sensor == null)
        {
            throw new UnityException("Couldn't find the kinect sensor.");
        }

        //Open the sensor
        this.sensor.Open();

        //Open the reader
        this.depthReader = sensor.DepthFrameSource.OpenReader();

        //Build the buffer
        this.depthBuffer = new ushort[sensor.DepthFrameSource.FrameDescription.LengthInPixels];

        //Log out some info
        this.PrintKinectStatus();

        //Find the kernel, make the buffer
        kernelID           = computeShader.FindKernel("CSMain");
        depthComputeBuffer = new ComputeBuffer(maxBufferSize / 2, sizeof(int), ComputeBufferType.Raw);
        outBuffer          = new ComputeBuffer(maxBufferSize, sizeof(float) * 3);
    }
Ejemplo n.º 2
0
        public FingerTrackingPage()
        {
            InitializeComponent();

            _sensor = KinectSensor.GetDefault();

            if (_sensor != null)
            {
                _depthReader = _sensor.DepthFrameSource.OpenReader();
                _depthReader.FrameArrived += DepthReader_FrameArrived;

                _infraredReader = _sensor.InfraredFrameSource.OpenReader();
                _infraredReader.FrameArrived += InfraredReader_FrameArrived;

                _bodyReader = _sensor.BodyFrameSource.OpenReader();
                _bodyReader.FrameArrived += BodyReader_FrameArrived;
                _bodies = new Body[_sensor.BodyFrameSource.BodyCount];

                // Initialize the HandsController and subscribe to the HandsDetected event.
                _handsController = new HandsController();
                _handsController.HandsDetected += HandsController_HandsDetected;

                _sensor.Open();
            }
        }
Ejemplo n.º 3
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            kinectManager = KinectManager.GetInstance;

            if (kinectManager.Sensor != null && kinectManager.Sensor.IsOpen == false)
            {
                kinectManager.Open();

                wsClient = new WebSocketClient();
                wsClient.InitializeConnection();

                bodyTracker      = new CVision.Tracking.BodyTracker();
                frameProc        = new FrameProcessor(kinectManager.Sensor);
                colorFrameReader = kinectManager.Sensor.ColorFrameSource.OpenReader();
                colorFrameReader.FrameArrived += ColorFrameReader_FrameArrived;

                infraredFrameReader = kinectManager.Sensor.InfraredFrameSource.OpenReader();
                infraredFrameReader.FrameArrived += InfraredFrameReader_FrameArrived;

                depthFrameReader = kinectManager.Sensor.DepthFrameSource.OpenReader();
                depthFrameReader.FrameArrived += DepthFrameReader_FrameArrived;

                bodyFrameReader = kinectManager.Sensor.BodyFrameSource.OpenReader();
                bodyFrameReader.FrameArrived += BodyFrameReader_FramedArrived;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initialize Kinect Depth
        /// </summary>
        /// <param name="source"></param>
        public void InitializeDepth(Image source)
        {
            if (_kinect == null)
            {
                return;
            }

            if (_depthReader != null)
            {
                return;
            }
            // Get frame description for the color output
            FrameDescription desc = _kinect.DepthFrameSource.FrameDescription;

            // Get the framereader for Color
            _depthReader = _kinect.DepthFrameSource.OpenReader();

            // Allocate pixel array
            _depthData   = new ushort[desc.Width * desc.Height];
            _depthPixels = new byte[desc.Width * desc.Height * _bytePerPixel];

            // Create new WriteableBitmap
            _depthBitmap = new WriteableBitmap(desc.Width, desc.Height, 96, 96, PixelFormats.Bgr32, null);

            if (source != null)
            {
                source.Source = _depthBitmap;
            }
        }
Ejemplo n.º 5
0
    void Start()
    {
        _Sensor = KinectSensor.GetDefault();
        if (_Sensor != null)
        {
            _Reader_Infrared = _Sensor.InfraredFrameSource.OpenReader();
            _Reader_Depth    = _Sensor.DepthFrameSource.OpenReader();

            _Data_Depth = new ushort[_Sensor.DepthFrameSource.FrameDescription.LengthInPixels];

            var frameDesc = _Sensor.InfraredFrameSource.FrameDescription;
            _Data_Infrared = new ushort[frameDesc.LengthInPixels];
            _RawData       = new byte[frameDesc.LengthInPixels * 4];
            _Texture       = new Texture2D(frameDesc.Width, frameDesc.Height, TextureFormat.BGRA32, false);

            Debug.Log("Width: " + frameDesc.Width + ", Height: " + frameDesc.Height);
            width  = frameDesc.Width;
            height = frameDesc.Height;

            infrared_matrix = new int[height, width];
            depth_matrix    = new int[height, width];

            if (!_Sensor.IsOpen)
            {
                _Sensor.Open();
            }
        }
    }
        /// <summary>
        /// The main window of the app.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            _sensor = KinectSensor.GetDefault();

            if (_sensor != null)
            {
                _depthReader = _sensor.DepthFrameSource.OpenReader();
                _depthReader.FrameArrived += DepthReader_FrameArrived;

                _infraredReader = _sensor.InfraredFrameSource.OpenReader();
                _infraredReader.FrameArrived += InfraredReader_FrameArrived;

                _bodyReader = _sensor.BodyFrameSource.OpenReader();
                _bodyReader.FrameArrived += BodyReader_FrameArrived;
                _bodies = new Body[_sensor.BodyFrameSource.BodyCount];

                // Initialize the HandsController and subscribe to the HandsDetected event.
                _handsController = new HandsController();
                _handsController.HandsDetected += HandsController_HandsDetected;

                _sensor.Open();
            }
        }
Ejemplo n.º 7
0
 //終了時の処理
 public void OnClose()
 {
     //カラーリーダーの終了
     if (this.colorFrameReader != null)
     {
         this.colorFrameReader.Dispose();
         this.colorFrameReader = null;
     }
     //ボディリーダーの終了
     if (this.bodyFrameReader != null)
     {
         this.bodyFrameReader.Dispose();
         this.bodyFrameReader = null;
     }
     //ディプスリーダーの終了
     if (this.depthFrameReader != null)
     {
         this.depthFrameReader.Dispose();
         this.depthFrameReader = null;
     }
     //BodyIndexFrame
     if (this.bodyIndexFrameReader != null)
     {
         this.bodyIndexFrameReader.Dispose();
         this.bodyIndexFrameReader = null;
     }
     //キネクトの終了
     if (this.kinect != null)
     {
         this.kinect.Close();
     }
 }
        /// <summary>
        /// The KinectHelper constructor
        /// </summary>
        public KinectHelper()
        {
            kinectSensor = KinectSensor.GetDefault();

            if (kinectSensor != null)
            {
                kinectSensor.Open();
                if (kinectSensor.IsOpen)
                {
                    // grab the audio stream
                    IReadOnlyList <AudioBeam> audioBeamList = this.kinectSensor.AudioSource.AudioBeams;
                    Stream audioStream = audioBeamList[0].OpenInputStream();
                    this.convertStream = new KinectAudioStream(audioStream);

                    kinectBody     = kinectSensor.BodyFrameSource.OpenReader();
                    kinectColor    = kinectSensor.ColorFrameSource.OpenReader();
                    kinectDepth    = kinectSensor.DepthFrameSource.OpenReader();
                    kinectInfrared = kinectSensor.InfraredFrameSource.OpenReader();
                }
                else
                {
                    throw new Exception("Kinect - Cannot open the Kinect Sensor to receive data!");
                }
            }
            else
            {
                throw new Exception("Kinect - Cannot find a Kinect Sensor to open!");
            }
        }
Ejemplo n.º 9
0
    public void Init()
    {
        _Sensor = KinectSensor.GetDefault();

        if (_Sensor != null)
        {
            _Reader = _Sensor.DepthFrameSource.OpenReader();

            _Data       = new ushort[_Sensor.DepthFrameSource.FrameDescription.LengthInPixels];
            _DataCamera = new CameraSpacePoint[_Sensor.DepthFrameSource.FrameDescription.LengthInPixels];

            mapper = _Sensor.CoordinateMapper;

            if (!_Sensor.IsOpen)
            {
                _Sensor.Open();
            }
        }
        else
        {
            Debug.LogError("DepthSourceManager: No Kinect Sensor");
        }


        updateDataTimer = new System.Threading.Timer(UpdateData, null, 1000, 60);
    }
        private void Window_Loaded( object sender, RoutedEventArgs e )
        {
            try {
                kinect = KinectSensor.GetDefault();
                if ( kinect == null ) {
                    throw new Exception("Kinectを開けません");
                }

                kinect.Open();

                // 表示のためのデータを作成
                depthFrameDesc = kinect.DepthFrameSource.FrameDescription;

                // 表示のためのビットマップに必要なものを作成
                depthImage = new WriteableBitmap( depthFrameDesc.Width, depthFrameDesc.Height,
                    96, 96, PixelFormats.Gray16, null );
                depthBuffer = new ushort[depthFrameDesc.LengthInPixels];
                depthRect = new Int32Rect( 0, 0, depthFrameDesc.Width, depthFrameDesc.Height );
                depthStride = (int)(depthFrameDesc.Width * depthFrameDesc.BytesPerPixel);

                ImageDepth.Source = depthImage;

                // 初期の位置表示座標
                depthPoint = new Point( depthFrameDesc.Width / 2, depthFrameDesc.Height / 2 );

                // Depthリーダーを開く
                depthFrameReader = kinect.DepthFrameSource.OpenReader();
                depthFrameReader.FrameArrived += depthFrameReader_FrameArrived;
            }
            catch ( Exception ex ) {
                MessageBox.Show( ex.Message );
                Close();
            }
        }
Ejemplo n.º 11
0
    void OnApplicationQuit()
    {
        if (colorReader != null)
        {
            colorReader.Dispose();
            colorReader = null;
        }
        if (infraredReader != null)
        {
            infraredReader.Dispose();
            infraredReader = null;
        }
        if (depthReader != null)
        {
            depthReader.Dispose();
            depthReader = null;
        }

        if (sensor != null)
        {
            if (sensor.IsOpen)
            {
                sensor.Close();
            }
            sensor = null;
        }
    }
Ejemplo n.º 12
0
        private void btConnect_Click(object sender, RoutedEventArgs e)
        {
            connected = !connected;
            if (connected)
            {
                kinectSensor.Open();
                btConnect.Content = "Disconnect";
                countDep          = 0;
                countInf          = 0;

                //Depth calling
                depthFrameReader = kinectSensor.DepthFrameSource.OpenReader();
                depthFrameReader.FrameArrived += depthFrameReader_FrameArrived;

                //Infrared calling
                reader = kinectSensor.OpenMultiSourceFrameReader(FrameSourceTypes.Infrared);
                reader.MultiSourceFrameArrived += Reader_MultiSourceFrameArrived;

                gettingPath();
                lbPath.Content = path;
            }
            else
            {
                kinectSensor.Close();
                btConnect.Content = "Connect";
            }
        }
Ejemplo n.º 13
0
        public MainWindow()
        {
            // get the kinectSensor object
            this.kinectSensor = KinectSensor.GetDefault();

            // open the reader for the depth frames
            this.depthFrameReader = this.kinectSensor.DepthFrameSource.OpenReader();

            // wire handler for frame arrival
            this.depthFrameReader.FrameArrived += this.Reader_FrameArrived;

            // get FrameDescription from DepthFrameSource
            this.depthFrameDescription = this.kinectSensor.DepthFrameSource.FrameDescription;

            // allocate space to put the pixels being received and converted
            this.depthPixels = new byte[this.depthFrameDescription.Width * this.depthFrameDescription.Height];

            // create the bitmap to display
            this.depthBitmap = new WriteableBitmap(this.depthFrameDescription.Width, this.depthFrameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null);

            // open the sensor
            this.kinectSensor.Open();

            // use the window object as the view model in this simple example
            this.DataContext = this;

            this.ViewDataCommand           = new DelegateCommand(this.ViewData);
            this.DataCleanupCommand        = new DelegateCommand(this.LaunchDataCleanup);
            this.ParticipantNumberCommand  = new DelegateCommand(this.PromptParticipantNumber);
            this.ParticipantSettingsCommad = new DelegateCommand(this.ParticipantSettings);
            this.ShowTutorialCommand       = new DelegateCommand(this.ShowTutorial);

            InitializeComponent();
        }
        private void BtStart_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (kinectSensor.IsOpen)
                {
                    kinectSensor.Close();
                    LblStatus.Content = "Kinect Desconnect";
                    BtStart.Content   = "Start";
                }
                else
                {
                    kinectSensor.Open();
                    LblStatus.Content = "Kinect Connect";
                    BtStart.Content   = "Stop";

                    //Color manipulation
                    colorFrameDescription = kinectSensor.ColorFrameSource.CreateFrameDescription(colorImageFormat);

                    colorFrameReader = kinectSensor.ColorFrameSource.OpenReader();
                    colorFrameReader.FrameArrived += ColorFrameReader_colorArrived;

                    colorBitmap        = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96, 96, PixelFormats.Bgra32, null);
                    colorStride        = colorFrameDescription.Width * (int)colorFrameDescription.BytesPerPixel;
                    colorRect          = new Int32Rect(0, 0, colorFrameDescription.Width, colorFrameDescription.Height);
                    colorBuffer        = new byte[colorStride * colorFrameDescription.Height];
                    ScreenColor.Source = colorBitmap;

                    //Depth manipulation
                    depthFrameDescription = kinectSensor.DepthFrameSource.FrameDescription;

                    depthImage        = new WriteableBitmap(depthFrameDescription.Width, depthFrameDescription.Height, 96, 96, PixelFormats.Gray8, null);
                    depthBuffer       = new ushort[depthFrameDescription.LengthInPixels];
                    depthBitmapBuffer = new byte[depthFrameDescription.LengthInPixels];
                    depthRect         = new Int32Rect(0, 0, depthFrameDescription.Width, depthFrameDescription.Height);
                    depthStride       = (int)depthFrameDescription.Width;

                    ScreenDepth.Source = depthImage;

                    depthPoint = new Point(depthFrameDescription.Width / 2, depthFrameDescription.Height / 2);

                    depthFrameReader = kinectSensor.DepthFrameSource.OpenReader();
                    depthFrameReader.FrameArrived += depthFrameReader_FrameArrived;

                    //Face manipulation
                    FrameDescription frameDescription = kinectSensor.ColorFrameSource.FrameDescription;
                    displayRect     = new Rect(0, 0, frameDescription.Width, frameDescription.Height);
                    bodyFrameReader = kinectSensor.BodyFrameSource.OpenReader();
                    bodyFrameReader.FrameArrived += bodyFrameReader_FrameArrived;
                    bodyCount = kinectSensor.BodyFrameSource.BodyCount;
                    bodies    = new Body[bodyCount];
                    InitializeFace();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
                Close();
            }
        }
        //終了時の処理
        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);
            //カラーリーダーの終了
            if (this.colorFrameReader != null)
            {
                this.colorFrameReader.Dispose();
                this.colorFrameReader = null;
            }
            //ボディリーダーの終了

            if (this.bodyFrameReader != null)
            {
                this.bodyFrameReader.Dispose();
                this.bodyFrameReader = null;
            }

            //ディプスリーダーの終了
            if (this.depthFrameReader != null)
            {
                this.depthFrameReader.Dispose();
                this.depthFrameReader = null;
            }

            //キネクトの終了
            if (this.kinect != null)
            {
                this.kinect.Close();
            }
            //StreamWriter
            if (this.streamWriter != null)
            {
                this.streamWriter.Close();
            }
        }
Ejemplo n.º 16
0
        public MainWindow()
        {
            Sensor = KinectSensor.GetDefault();
            Sensor.Open();

            FrameReader = Sensor.DepthFrameSource.OpenReader();

            BitmapToDisplay = new WriteableBitmap(
                FrameReader.DepthFrameSource.FrameDescription.Width,
                FrameReader.DepthFrameSource.FrameDescription.Height,
                96.0,
                96.0,
                PixelFormats.Gray16,
                null);

            InitializeComponent();

            this.WindowStyle = System.Windows.WindowStyle.None;
            this.WindowState = System.Windows.WindowState.Maximized;

            Loaded  += OpenKinect;
            Closing += CloseKinect;

            KeyDown += CheckForExit;
        }
Ejemplo n.º 17
0
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (_bodyReader != null)
            {
                _bodyReader.Dispose();
                _bodyReader = null;
            }

            if (_depthReader != null)
            {
                _depthReader.Dispose();
                _depthReader = null;
            }

            if (_infraredReader != null)
            {
                _infraredReader.Dispose();
                _infraredReader = null;
            }

            if (_sensor != null)
            {
                _sensor.Close();
                _sensor = null;
            }
        }
Ejemplo n.º 18
0
    void Start()
    {
        Application.targetFrameRate = 60; // Set the FPS to 30 - this is the max the Kinect can do.

        Debug.Log("FrameRate: " + Application.targetFrameRate);

        waterEnabledColor = new Color(1f, 0f, 0f);

        waterHeight   = new float[DEPTH_WIDTH, DEPTH_HEIGHT];
        terrainHeight = new float[DEPTH_WIDTH, DEPTH_HEIGHT];

        _Sensor = KinectSensor.GetDefault();

        waterTexture  = new Texture2D(DEPTH_WIDTH, DEPTH_HEIGHT);
        heightTexture = new Texture2D(DEPTH_WIDTH, DEPTH_HEIGHT);

        material = gameObject.GetComponent <Renderer>().material;
        material.SetTexture("_WaterMaskTex", waterTexture);
        material.SetTexture("_HeightTex", heightTexture);
        material.SetInt("_showSeaLevelGround", showSeaLevelIndicator);

        frameDesc = _Sensor.DepthFrameSource.FrameDescription;

        if (_Sensor != null)
        {
            _Reader = _Sensor.DepthFrameSource.OpenReader();
            _Data   = new ushort[_Sensor.DepthFrameSource.FrameDescription.LengthInPixels];
        }

        terrainUpdateThread = new Thread(updateTerrain);
        terrainUpdateThread.Start();
    }
Ejemplo n.º 19
0
        private async void _depthReader_FrameArrived(DepthFrameReader sender, DepthFrameArrivedEventArgs e)
        {
            bool   shouldRecord = _recorder != null && _recorder.IsStarted && DepthCheckBox.IsChecked.GetValueOrDefault();
            bool   shouldDisplay = _displayType == FrameTypes.Depth;
            ushort minDepth = 0, maxDepth = 0;

            if (shouldRecord || shouldDisplay)
            {
                using (var frame = e.FrameReference.AcquireFrame())
                {
                    if (frame != null)
                    {
                        frame.CopyFrameDataToArray(_depthData);
                        minDepth = frame.DepthMinReliableDistance;
                        maxDepth = frame.DepthMaxReliableDistance;
                        if (shouldRecord)
                        {
                            _recorder.RecordFrame(frame, _depthData);
                        }
                    }
                    else
                    {
                        shouldDisplay = false;
                        System.Diagnostics.Debug.WriteLine("!!! FRAME SKIPPED (Depth in MainPage)");
                    }
                }
                if (shouldDisplay)
                {
                    await _depthBitmap.UpdateAsync(_depthData, minDepth, maxDepth);
                }
            }
        }
Ejemplo n.º 20
0
        public MainWindow()
        {
            // Init window
            InitializeComponent();

            // Init Kinect
            kinectDevice          = KinectSensor.GetDefault();
            depthFrameReader      = kinectDevice.DepthFrameSource.OpenReader();
            depthFrameDescription = kinectDevice.DepthFrameSource.FrameDescription;
            bodyFrameReader       = kinectDevice.BodyFrameSource.OpenReader();

            // Init Serialport
            myPort       = new SerialPort();
            MySerialRecv = new SerialDataReceivedEventHandler(OnDataReceived);

            // Init detection
            bodyParts = new Joint[5];
            angles    = new double[3];
            angle0    = new double[filterLength];
            angle1    = new double[filterLength];
            angle2    = new double[filterLength];

            // Init window widgets
            btnClear.IsEnabled     = false;
            btnClosePort.IsEnabled = false;
            btnOpenPort.IsEnabled  = false;
            btnSend.IsEnabled      = false;
            btnCloseCam.IsEnabled  = false;
            lblAng0.Content        = "Angle0 = ";
            lblAng1.Content        = "Angle1 = ";
            lblAng2.Content        = "Angle2 = ";
            lblRHS.Content         = "State = ";

            // Serialport Options Init
            foreach (int bdr in baudrates)
            {
                cbBRate.Items.Add(bdr.ToString());
            }

            cbBRate.SelectedIndex = 0;

            ports = SerialPort.GetPortNames();

            if (ports.Length > 0)
            {
                cbPortNO.SelectedIndex = 0;
                btnOpenPort.IsEnabled  = true;
            }
            else
            {
                cbPortNO.SelectedIndex = -1;
            }

            Array.Sort(ports);

            foreach (string s in ports)
            {
                cbPortNO.Items.Add(s);
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Called when the main window is created, where everything needs to be initialized
        /// </summary>
        public MainWindow()
        {
            // grab the kinect object
            kinect = KinectSensor.GetDefault();

            // open the depth and color frame readers
            depthReader = kinect.DepthFrameSource.OpenReader();
            colorReader = kinect.ColorFrameSource.OpenReader();

            // event handler - calls frame arrival handler when a frame arrives from the reader
            depthReader.FrameArrived += depthFrameArrived;
            colorReader.FrameArrived += colorFrameArrived;

            // get the frame description from the source
            depthFrameDescription = kinect.DepthFrameSource.FrameDescription;
            colorFrameDescription = kinect.ColorFrameSource.FrameDescription;

            // allocate the array for the conversion of the depth data to color bitmap
            depthPixels = new byte[depthFrameDescription.Width * depthFrameDescription.Height];

            // create the bitmap to display
            depthBitmap = new WriteableBitmap(depthFrameDescription.Width, depthFrameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null);
            colorBitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);

            // initialize the gps device
            gpsDevice = new GPSHandler();
            FolderPath = "D:\\KinectTest\\";

            // start the kinect sensor
            kinect.Open();

            InitializeComponent();
        }
Ejemplo n.º 22
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try {
                kinect = KinectSensor.GetDefault();
                if (kinect == null)
                {
                    throw new Exception("Kinectを開けません");
                }

                kinect.Open();

                // 表示のためのデータを作成
                depthFrameDesc = kinect.DepthFrameSource.FrameDescription;

                // 表示のためのビットマップに必要なものを作成
                depthImage = new WriteableBitmap(depthFrameDesc.Width, depthFrameDesc.Height,
                                                 96, 96, PixelFormats.Gray16, null);
                depthBuffer = new ushort[depthFrameDesc.LengthInPixels];
                depthRect   = new Int32Rect(0, 0, depthFrameDesc.Width, depthFrameDesc.Height);
                depthStride = (int)(depthFrameDesc.Width * depthFrameDesc.BytesPerPixel);

                ImageDepth.Source = depthImage;

                // 初期の位置表示座標
                depthPoint = new Point(depthFrameDesc.Width / 2, depthFrameDesc.Height / 2);

                // Depthリーダーを開く
                depthFrameReader = kinect.DepthFrameSource.OpenReader();
                depthFrameReader.FrameArrived += depthFrameReader_FrameArrived;
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
                Close();
            }
        }
        //public httpc

        public MainWindow()
        {
            frameCount = 0;

            // get the kinectSensor object
            this.kinect = KinectSensor.GetDefault();

            // open the reader for the depth frames
            this.depthFrameReader = this.kinect.DepthFrameSource.OpenReader();

            // wire handler for frame arrival
            this.depthFrameReader.FrameArrived += this.Reader_FrameArrived;

            // get FrameDescription from DepthFrameSource
            this.depthFrameDescription = this.kinect.DepthFrameSource.FrameDescription;

            // allocate space to put the pixels being received and converted
            this.depthPixels = new byte[this.depthFrameDescription.Width * this.depthFrameDescription.Height];

            // open the sensor
            this.kinect.Open();

            // use the window object as the view model in this simple example
            this.DataContext = this;

            // initialize the components (controls) of the window
            this.InitializeComponent();
        }
Ejemplo n.º 24
0
        private void InitializeDepth()
        {
            if (_kinect == null)
            {
                return;
            }

            // Get frame description for the color output
            FrameDescription desc = _kinect.DepthFrameSource.FrameDescription;

            // Get the framereader for Color
            _depthReader = _kinect.DepthFrameSource.OpenReader();

            // Allocate pixel array
            _depthData   = new ushort[desc.Width * desc.Height];
            _depthPixels = new byte[desc.Width * desc.Height * _bytePerPixel];

            // Create new WriteableBitmap
            _depthBitmap = new WriteableBitmap(desc.Width, desc.Height, 96, 96, PixelFormats.Bgr32, null);

            // Link WBMP to UI
            DepthImage.Source = _depthBitmap;

            // Hook-up event
            _depthReader.FrameArrived += OnDepthFrameArrived;
        }
Ejemplo n.º 25
0
    private void Start()
    {
        kinect = KinectSensor.GetDefault();
        if (kinect != null)
        {
            reader = kinect.DepthFrameSource.OpenReader();
            var desc = kinect.DepthFrameSource.FrameDescription;
            width  = desc.Width;
            height = desc.Height;

            depthTexture = new RenderTexture(width, height, 0, RenderTextureFormat.ARGBHalf);
            depthTexture.enableRandomWrite = true;
            depthTexture.Create();
            var r = GetComponent <Renderer>();
            if (r != null)
            {
                r.material.mainTexture = depthTexture;
            }

            depthBuffer  = new ComputeBuffer((int)desc.LengthInPixels, Marshal.SizeOf(typeof(int)));
            depthData    = new ushort[desc.LengthInPixels];
            depthDataInt = new int[desc.LengthInPixels];

            depthTexGen.SetInt("_DWidth", width);
            depthTexGen.SetInt("_DHeight", height);
        }
    }
Ejemplo n.º 26
0
    // Use this for initialization
    void Start()
    {
        System.GC.Collect();

        //Inicializo las variables
        string path = Application.dataPath + "\\Assets\\format.jpg";

        frameOpenCV = new Mat(path);

        rawDepthPixels     = new ushort[WIDTH * HEIGHT];
        averageDepthConfig = new int[WIDTH * HEIGHT];
        listConfig         = new List <int[]>();
        colorImage         = new byte[WIDTH * HEIGHT * 3];


        colorDetected = new MCvScalar(0, 255, 0);
        colorBounce   = new MCvScalar(0, 0, 255);

        debugBounces = new List <System.Drawing.Point>();

        _sensor = KinectSensor.GetDefault();

        if (_sensor != null)
        {
            IsAvailable = _sensor.IsAvailable;


            depthFrameReader = _sensor.DepthFrameSource.OpenReader();

            if (!_sensor.IsOpen)
            {
                _sensor.Open();
            }
        }
    }
Ejemplo n.º 27
0
        private void MainWindow_Closing(object sender, CancelEventArgs e)
        {
            if (this._recording | this._processing)
            {
                // Do not allow user to shutdown the program if there is incomplete process
                e.Cancel = true;
            }
            if (this._readerColor != null)
            {
                // ColorFrameReder is IDisposable
                this._readerColor.Dispose();
                this._readerColor = null;
            }
            if (this._readerDepth != null)
            {
                // ColorFrameReder is IDisposable
                this._readerDepth.Dispose();
                this._readerDepth = null;
            }

            if (this._sensor != null)
            {
                this._sensor.Close();
                this._sensor = null;
            }
        }
Ejemplo n.º 28
0
    void Start()
    {
        try
        {
            _Sensor = KinectSensor.GetDefault();
        }
        catch (Exception e)
        {
            Debug.LogWarning("Kinect dll not installed.");
        }

        if (_Sensor != null)
        {
            _Reader = _Sensor.DepthFrameSource.OpenReader();
            _Data   = new ushort[_Sensor.DepthFrameSource.FrameDescription.LengthInPixels];

            if (_UpdateModel == UpdateModel.Event)
            {
                _Reader.FrameArrived += _OnFrameArrived;
            }

            if (!_Sensor.IsOpen)
            {
                _Sensor.Open();
            }
        }
    }
Ejemplo n.º 29
0
    private void OnDestroy()
    {
        if (depthFrameReader != null)
        {
            depthFrameReader.Dispose();
            depthFrameReader = null;
        }

        if (sensor != null)
        {
            if (sensor.IsOpen && ManageSensor)
            {
                sensor.Close();
            }

            sensor = null;
        }

        if (positionBuffer != null)
        {
            positionBuffer.Dispose();
            positionBuffer = null;
        }

        if (tempPositionTexture != null)
        {
            Destroy(tempPositionTexture);
            tempPositionTexture = null;
        }
    }
Ejemplo n.º 30
0
    // Use this for initialization
    void Start()
    {
        sensor = KinectSensor.GetDefault();
        reader = sensor?.DepthFrameSource.OpenReader();

        if ((!sensor?.IsOpen) ?? false)
        {
            sensor.Open();
        }

        image = GetComponent <Image>();

        AddDisposable(reader);
        AddDisposable(sensor.Close);

        diff = highPlane - lowPlane;

        if (reader != null)
        {
            var desc = reader.DepthFrameSource.FrameDescription;
            width                = desc.Width;
            height               = desc.Height;
            depthTexture         = new Texture2D(width, height);
            buffer               = new ushort[desc.LengthInPixels];
            colourBuffer         = new Color[desc.LengthInPixels];
            material             = image.material;
            material.mainTexture = depthTexture;
        }
    }
Ejemplo n.º 31
0
    void Start()
    {
        _Sensor = KinectSensor.GetDefault();

        if (_Sensor != null)
        {
            _Reader = _Sensor.DepthFrameSource.OpenReader();
            var frameDesc = _Sensor.DepthFrameSource.FrameDescription;
            _Data    = new ushort[frameDesc.LengthInPixels];
            _RawData = new byte[frameDesc.LengthInPixels * 2];

            // 16bit のテクスチャ。適切な単色のフォーマットがないので
            // RGBA4444 or ARGB4444 or R16 で16bit分確保する
            //_Texture = new Texture2D(frameDesc.Width, frameDesc.Height, TextureFormat.RGBA4444, false);
            //_Texture = new Texture2D(frameDesc.Width, frameDesc.Height, TextureFormat.ARGB4444, false);
            _Texture = new Texture2D(frameDesc.Width, frameDesc.Height, TextureFormat.R16, false);

            if (!_Sensor.IsOpen)
            {
                // スタート
                _Sensor.Open();
            }
        }

        mat.SetTexture("_MainTex", _Texture);
    }
Ejemplo n.º 32
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            try {
                // Kinectを開く
                kinect = KinectSensor.GetDefault();
                kinect.Open();

                // 表示のためのデータを作成
                depthFrameDesc = kinect.DepthFrameSource.FrameDescription;

                // Depthリーダーを開く
                depthFrameReader = kinect.DepthFrameSource.OpenReader();
                depthFrameReader.FrameArrived += depthFrameReader_FrameArrived;

                // 表示のためのデータ
                depthBitmap = new WriteableBitmap(depthFrameDesc.Width,
                                                  depthFrameDesc.Height);
                ImageDepth.Source = depthBitmap;

                depthBuffer       = new ushort[depthFrameDesc.LengthInPixels];
                depthBitmapBuffer = new byte[depthFrameDesc.LengthInPixels * 4];

                depthPoint = new Point(depthFrameDesc.Width / 2,
                                       depthFrameDesc.Height / 2);
            }
            catch (Exception ex) {
                MessageDialog dlg = new MessageDialog(ex.Message);
                dlg.ShowAsync();
            }
        }
Ejemplo n.º 33
0
        protected override void OnNavigatedTo( NavigationEventArgs e )
        {
            base.OnNavigatedTo( e );

            try {
                // Kinectを開く
                kinect = KinectSensor.GetDefault();
                kinect.Open();

                // 表示のためのデータを作成
                depthFrameDesc = kinect.DepthFrameSource.FrameDescription;

                // Depthリーダーを開く
                depthFrameReader = kinect.DepthFrameSource.OpenReader();
                depthFrameReader.FrameArrived += depthFrameReader_FrameArrived;

                // 表示のためのデータ
                depthBitmap = new WriteableBitmap( depthFrameDesc.Width,
                                                   depthFrameDesc.Height );
                ImageDepth.Source = depthBitmap;

                depthBuffer = new ushort[depthFrameDesc.LengthInPixels];
                depthBitmapBuffer = new byte[depthFrameDesc.LengthInPixels * 4];

                depthPoint = new Point( depthFrameDesc.Width / 2,
                                        depthFrameDesc.Height / 2 );
            }
            catch ( Exception ex ) {
                MessageDialog dlg = new MessageDialog(ex.Message);
                dlg.ShowAsync();
            }
        }
        public MainWindow()
        {
            _kinectSensor = KinectSensor.GetDefault();

            _depthFrameDescription = _kinectSensor.DepthFrameSource.FrameDescription;

            _depthFrameReader = _kinectSensor.DepthFrameSource.OpenReader();

            _depthFrameReader.FrameArrived += Reader_FrameArrived;

            _cameraSpacePoints = new CameraSpacePoint[_depthFrameDescription.Width * _depthFrameDescription.Height];

            _trackingDiagnostics = new TrackingDiagnostics();

            _heatMap = new HeatMap();

            _energyHistory = new EnergyHistory();

            _temporalMedianImage = new TemporalMedianImage(GlobVar.TemporalFrameCounter);

            _stopwatch = new Stopwatch();

            BodiesHistory.Initialize();

            GlobVar.CoordinateMapper = _kinectSensor.CoordinateMapper;

            GlobVar.TimeStamps = new List<TimeSpan>();

            // initialize the components (controls) of the GUI window
            InitializeComponent();

            _kinectSensor.Open();
        }
Ejemplo n.º 35
0
        public MainWindow()
        {
            _kinectSensor = KinectSensor.GetDefault();

            _depthFrameDescription = _kinectSensor.DepthFrameSource.FrameDescription;

            _depthFrameReader = _kinectSensor.DepthFrameSource.OpenReader();

            _depthFrameReader.FrameArrived += Reader_FrameArrived;

            _cameraSpacePoints = new CameraSpacePoint[_depthFrameDescription.Width * _depthFrameDescription.Height];

            _trackingDiagnostics = new TrackingDiagnostics();

            _heatMap = new HeatMap();

            _energyHistory = new EnergyHistory();

            _temporalMedianImage = new TemporalMedianImage(GlobVar.TemporalFrameCounter);

            _stopwatch = new Stopwatch();

            BodiesHistory.Initialize();

            GlobVar.CoordinateMapper = _kinectSensor.CoordinateMapper;

            GlobVar.TimeStamps = new List <TimeSpan>();

            // initialize the components (controls) of the GUI window
            InitializeComponent();

            _kinectSensor.Open();
        }
Ejemplo n.º 36
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            w    = GraphicsDevice.Viewport.Bounds.Width;
            h    = GraphicsDevice.Viewport.Bounds.Height;
            data = new uint[w * h];
            sw   = GraphicsDevice.Viewport.Bounds.Width;
            sh   = GraphicsDevice.Viewport.Bounds.Height;

            // texture = new Texture2D(GraphicsDevice, w, h);
            textureFade = new Texture2D(GraphicsDevice, 1, 1);
            textureFade.SetData(new uint[] { 0x0f000000 });
            textureWhite = new Texture2D(GraphicsDevice, 1, 1);
            textureWhite.SetData(new uint[] { 0xFFFFFFFF });

            // Setup our BasicEffect for drawing the quad
            worldMatrix = Matrix.CreateScale(w / (float)h, 1, 1);
            display     = Content.Load <Effect>("basic");
            depthEffect = Content.Load <Effect>("depth");

            Matrix projection = Matrix.CreateOrthographicOffCenter(0,
                                                                   GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 0, 1);
            Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0);

            display.Parameters["MatrixTransform"].SetValue(halfPixelOffset * projection);
            depthEffect.Parameters["MatrixTransform"].SetValue(halfPixelOffset * projection);

            // Create a vertex declaration
            vertexDeclaration = new VertexDeclaration(
                new VertexElement[] {
                new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
                new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0),
                new VertexElement(24, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0)
            });

            velocity           = new RenderTargetDouble(GraphicsDevice, w, h);
            density            = new RenderTargetDouble(GraphicsDevice, w, h);
            velocityDivergence = new RenderTargetDouble(GraphicsDevice, w, h);
            velocityVorticity  = new RenderTargetDouble(GraphicsDevice, w, h);
            pressure           = new RenderTargetDouble(GraphicsDevice, w, h);

            advect               = new Advect(w, h, timestep, Content);
            boundary             = new Boundary(w, h, Content);
            diffuse              = new Jacobi(Content.Load <Effect>("jacobivector"), w, h);
            divergence           = new Divergence(w, h, Content);
            poissonPressureEq    = new Jacobi(Content.Load <Effect>("jacobiscalar"), w, h);
            gradient             = new Gradient(w, h, Content);
            splat                = new Splat(w, h, Content);
            vorticity            = new Vorticity(w, h, Content);
            vorticityConfinement = new VorticityConfinement(Content.Load <Effect>("vorticityforce"), w, h, timestep);

            // this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader();
            this.depthFrameReader = this.kinectSensor.DepthFrameSource.OpenReader();
            this.kinectSensor.Open();
            // this.bodyFrameReader.FrameArrived += this.Reader_FrameArrived;
            this.depthFrameReader.FrameArrived += DepthFrameReader_FrameArrived;
        }
Ejemplo n.º 37
0
        public KinnectFrameProvider()
        {
            var sensor = KinectSensor.GetDefault();
            sensor.Open();

            depthReader = sensor.DepthFrameSource.OpenReader();
            depthReader.FrameArrived += KinnectFrameArrived;
        }
Ejemplo n.º 38
0
 public void TerminateFrame()
 {
     if (this.depthFrameReader != null)
     {
         // DepthFrameReader is IDisposable
         this.depthFrameReader.Dispose();
         this.depthFrameReader = null;
     }
 }
Ejemplo n.º 39
0
		static void Main(string[] args)
		{
			var sensor = KinectSensor.GetDefault();
			sensor.Open();
			writer = new BinaryWriter(new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write));
			reader = sensor.DepthFrameSource.OpenReader();
			reader.FrameArrived += Reader_FrameArrived;
			Console.Read();
		}
Ejemplo n.º 40
0
        public void Start()
        {
            if (_isRunning)
                return;

            _depthReader = _sensorService.Sensor.DepthFrameSource.OpenReader();
            _depthReader.FrameArrived += _depthReader_FrameArrived;
            _isRunning = true;
        }
Ejemplo n.º 41
0
 private bool Setup()
 {
     filepath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
     sensor = KinectSensor.GetDefault();
     sensor.IsAvailableChanged += sensor_IsAvailableChanged;
     depth = sensor.DepthFrameSource.OpenReader();
     depth.FrameArrived += depth_FrameArrived;
     sensor.Open();
     return true;
 }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="sensor">Kinect sensor</param>
        public KinectSensorDepthFrameProvider(KinectSensor sensor)
        {
            if (sensor == null)
                throw new ArgumentNullException("sensor");

            this.sensor = sensor;
            this.depthReader = this.sensor.DepthFrameSource.OpenReader();
            this.depthReader.FrameArrived += depthReader_FrameArrived;
            this.frameData = new DepthFrameData();
        }
        private void Window_Closing( object sender, System.ComponentModel.CancelEventArgs e )
        {
            if ( depthFrameReader != null ) {
                depthFrameReader.Dispose();
                depthFrameReader = null;
            }

            if ( kinect != null ) {
                kinect.Close();
                kinect = null;
            }
        }
Ejemplo n.º 44
0
 public bool InitializeFrame()
 {
     this.depthFrameReader = this.kinectSensor.DepthFrameSource.OpenReader();
     if (this.depthFrameReader != null)
     {
         this.depthFrameReader.FrameArrived += this.Reader_FrameArrived;
         this.depthFrameDescription = this.kinectSensor.DepthFrameSource.FrameDescription;
         this.depthPixels = new byte[this.depthFrameDescription.Width * this.depthFrameDescription.Height];
         this.depthBitmap = new WriteableBitmap(this.depthFrameDescription.Width, this.depthFrameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null);
         this.stopwatch.Start();
         return true;
     }
     return false;
 }
Ejemplo n.º 45
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainPage"/> class.
        /// </summary>
        public MainPage()
        {
            this.InitializeComponent();

            RecordButton.Click += RecordButton_Click;

            ColorCompressionCombo.Items.Add("None (1920x1080)");
            ColorCompressionCombo.Items.Add("None (1280x720)");
            ColorCompressionCombo.Items.Add("None (640x360)");
            ColorCompressionCombo.Items.Add("JPEG (1920x1080)");
            ColorCompressionCombo.Items.Add("JPEG (1280x720)");
            ColorCompressionCombo.Items.Add("JPEG (640x360)");
            ColorCompressionCombo.SelectedIndex = 0;

            SmoothingCombo.Items.Add("None");
            SmoothingCombo.Items.Add("Kalman Filter");
            SmoothingCombo.Items.Add("Double Exponential");
            SmoothingCombo.SelectionChanged += SmoothingCombo_SelectionChanged;
            SmoothingCombo.SelectedIndex = 0;

            DisplayCombo.Items.Add("Body");
            DisplayCombo.Items.Add("Color");
            DisplayCombo.Items.Add("Depth");
            DisplayCombo.Items.Add("Infrared");
            DisplayCombo.SelectionChanged += DisplayCombo_SelectionChanged;
            DisplayCombo.SelectedIndex = 0;

            _sensor = KinectSensor.GetDefault();

            _bodyReader = _sensor.BodyFrameSource.OpenReader();
            _bodyReader.FrameArrived += _bodyReader_FrameArrived;

            _colorReader = _sensor.ColorFrameSource.OpenReader();
            _colorReader.FrameArrived += _colorReader_FrameArrived;
            var colorFrameDesc = _sensor.ColorFrameSource.FrameDescription;
            _colorData = new byte[colorFrameDesc.LengthInPixels * 4];

            _depthReader = _sensor.DepthFrameSource.OpenReader();
            _depthReader.FrameArrived += _depthReader_FrameArrived;
            var depthFrameDesc = _sensor.DepthFrameSource.FrameDescription;
            _depthData = new ushort[depthFrameDesc.LengthInPixels];

            _infraredReader = _sensor.InfraredFrameSource.OpenReader();
            _infraredReader.FrameArrived += _infraredReader_FrameArrived;
            var infraredFrameDesc = _sensor.InfraredFrameSource.FrameDescription;
            _infraredData = new ushort[infraredFrameDesc.LengthInPixels];

            _sensor.Open();
        }
Ejemplo n.º 46
0
		static void Main(string[] args)
		{
			var sensor = KinectSensor.GetDefault();
			sensor.Open();
			writer = new BinaryWriter(new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write));
			System.Console.WriteLine("File opened: " + fileName);
			reader = sensor.DepthFrameSource.OpenReader();
			reader.FrameArrived += Reader_FrameArrived;
			Console.WriteLine("Press Enter to stop recording.");
			Console.Read();
			reader.FrameArrived -= Reader_FrameArrived;
			reader.Dispose();
			sensor.Close();

		}
Ejemplo n.º 47
0
        public MainWindow()
        {
            this.depthFrameReader = this.kinectSensor.DepthFrameSource.OpenReader();
            this.depthFrameReader.FrameArrived += this.Reader_FrameArrived;
            this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader();

            this.bodyFrameReader.FrameArrived += this.Reader_BodyFrameArrived;

            depth = new DepthInterpreter(kinectSensor);

            InitializeComponent();

            kinectSensor.Open();

        }
Ejemplo n.º 48
0
        public void ListenForFrames()
        {
            sensor = KinectSensor.GetDefault();

            depthFrameReader = sensor.DepthFrameSource.OpenReader();

            depthFrameReader.FrameArrived += Reader_FrameArrived;

            depthFrameDescription = sensor.DepthFrameSource.FrameDescription;

            // allocate space to put the pixels being received and converted
            depthPixels = new ushort[this.depthFrameDescription.Width * this.depthFrameDescription.Height];

            sensor.Open();

            Console.WriteLine("Extractor ready to grab frames.");
        }
        public DepthRecorder()
        {
            InitializeComponent();

            this.Sensor = new KinectV2();
            this.Sensor.Initialize();

            this.depthFrameReader = this.Kinect.DepthFrameSource.OpenReader();
            this.depthFrameReader.FrameArrived += depthFrameReader_FrameArrived;
            this.depthFrameDescription = this.Kinect.DepthFrameSource.FrameDescription;
            this.depthPixels = new byte[this.depthFrameDescription.Width * this.depthFrameDescription.Height];
            this.depthBitmap = new WriteableBitmap(this.depthFrameDescription.Width, this.depthFrameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null);

            #region Coordinate Mapper Configuration
            this.coordinateMapper = this.Kinect.CoordinateMapper;
            FrameDescription depthFrameDescription = this.Kinect.DepthFrameSource.FrameDescription;

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

            // allocate space to put the pixels being received and converted
            this.depthFrameData = new ushort[depthWidth * depthHeight];
            this.colorPoints = new ColorSpacePoint[depthWidth * depthHeight];
            this.cameraPoints = new CameraSpacePoint[depthWidth * depthHeight];
            // get FrameDescription from ColorFrameSource
            FrameDescription colorFrameDescription = this.Kinect.ColorFrameSource.FrameDescription;

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

            // allocate space to put the pixels being received
            this.colorFrameData = new byte[colorWidth * colorHeight * this.bytesPerPixel];
            #endregion

            #region Recorder
            this.Recorder = new PointCloudRecorder(ConfigurationManager.AppSettings["RecordFolder"], new PCL());
            this.Recorder.RecordRGB = false;
            this.Recorder.StateChanged += Recorder_StateChanged;
            this.Recorder.Stopped += Recorder_Stopped;
            this.Recorder.CloudProcessed += Recorder_CloudProcessed;
            #endregion

            this.Sensor.Open();
            this.DataContext = this;
        }
Ejemplo n.º 50
0
        public DepthInterpreter(KinectSensor sensor)
        {

            kinectSensor = sensor;
            this.depthFrameReader = this.kinectSensor.DepthFrameSource.OpenReader();
            this.depthFrameReader.FrameArrived += this.Reader_DepthFrameArrived;
            this.depthFrameDescription = this.kinectSensor.DepthFrameSource.FrameDescription;

            this.depthBitmap = new WriteableBitmap(displayWidth, displayHeight, 96.0, 96.0, format, null);
            this.depthPixelData = new byte[displayWidth * displayWidth];

            this.drawingGroup = new DrawingGroup();
            this.depthOverlay = new DrawingImage(this.drawingGroup);

            depthData = new ushort[this.depthFrameDescription.Width * this.depthFrameDescription.Height];
            depthMap = new DepthMap(depthData, displayWidth);
            
        }
Ejemplo n.º 51
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            #region Interface

            ColorRButton.IsChecked = true;
            RecordButton.IsEnabled = false;
            BodyCheckBox.IsEnabled = false;
            ColorCheckBox.IsEnabled = false;
            DepthCheckBox.IsEnabled = false;
            InfraredCheckBox.IsEnabled = false;
            FaceCheckBox.IsEnabled = false;
            AudioCheckBox.IsEnabled = false;

            #endregion

            _sensor = KinectSensor.GetDefault();

            if (_sensor != null)
            {
                _sensor.Open();
                _bodies = new List<CustomBody>();

                _faceSource = new HighDefinitionFaceFrameSource(_sensor);
                _faceModel = new FaceModel();
                _faceAlignment = new FaceAlignment();

                _bodyReader = _sensor.BodyFrameSource.OpenReader();
                _bodyReader.FrameArrived += _bodyReader_FrameArrived;

                _colorReader = _sensor.ColorFrameSource.OpenReader();
                _colorReader.FrameArrived += _colorReader_FrameArrived;

                _depthReader = _sensor.DepthFrameSource.OpenReader();
                _depthReader.FrameArrived += _depthReader_FrameArrived;

                _faceReader = _faceSource.OpenReader();
                _faceReader.FrameArrived += _faceReader_FrameArrived;

                _infraredReader = _sensor.InfraredFrameSource.OpenReader();
                _infraredReader.FrameArrived += _infraredReader_FrameArrived;


            }
        }
Ejemplo n.º 52
0
        public MainWindow()
        {
            InitializeComponent();

            RecordButton.Click += RecordButton_Click;

            ColorCompressionCombo.Items.Add("None (1920x1080)");
            ColorCompressionCombo.Items.Add("None (1280x720)");
            ColorCompressionCombo.Items.Add("None (640x360)");
            ColorCompressionCombo.Items.Add("JPEG (1920x1080)");
            ColorCompressionCombo.Items.Add("JPEG (1280x720)");
            ColorCompressionCombo.Items.Add("JPEG (640x360)");
            ColorCompressionCombo.SelectedIndex = 0;

            SmoothingCombo.Items.Add("None");
            SmoothingCombo.Items.Add("Kalman Filter");
            SmoothingCombo.Items.Add("Double Exponential");
            SmoothingCombo.SelectionChanged += SmoothingCombo_SelectionChanged;
            SmoothingCombo.SelectedIndex = 0;

            DisplayCombo.Items.Add("Body");
            DisplayCombo.Items.Add("Color");
            DisplayCombo.Items.Add("Depth");
            DisplayCombo.Items.Add("Infrared");
            DisplayCombo.SelectionChanged += DisplayCombo_SelectionChanged;
            DisplayCombo.SelectedIndex = 0;

            _sensor = KinectSensor.GetDefault();

            _bodyReader = _sensor.BodyFrameSource.OpenReader();
            _bodyReader.FrameArrived += _bodyReader_FrameArrived;

            _colorReader = _sensor.ColorFrameSource.OpenReader();
            _colorReader.FrameArrived += _colorReader_FrameArrived;

            _depthReader = _sensor.DepthFrameSource.OpenReader();
            _depthReader.FrameArrived += _depthReader_FrameArrived;

            _infraredReader = _sensor.InfraredFrameSource.OpenReader();
            _infraredReader.FrameArrived += _infraredReader_FrameArrived;

            _sensor.Open();
            OutputImage.Source = _colorBitmap.Bitmap;
        }
Ejemplo n.º 53
0
 public KinectDevice()
 {
     //kinect設定
     this.kinect = KinectSensor.GetDefault();
     //設定とハンドラ
     //colorImage
     #region
     this.colorImageFormat = ColorImageFormat.Bgra;
     this.colorFrameDescription = this.kinect.ColorFrameSource.CreateFrameDescription(this.colorImageFormat);
     this.colorFrameReader = this.kinect.ColorFrameSource.OpenReader();
     this.colorFrameReader.FrameArrived += ColorFrame_Arrived;
     this.colors = new byte[this.colorFrameDescription.Width
                                    * this.colorFrameDescription.Height
                                    * this.colorFrameDescription.BytesPerPixel];
     #endregion
     //骨格情報
     #region
     this.bodyFrameReader = this.kinect.BodyFrameSource.OpenReader();
     this.bodyFrameReader.FrameArrived += BodyFrame_Arrived;
     #endregion
     //震度情報
     #region
     this.depthFrameReader = this.kinect.DepthFrameSource.OpenReader();
     this.depthFrameReader.FrameArrived += DepthFrame_Arrived;
     this.depthFrameDescription = this.kinect.DepthFrameSource.FrameDescription;
     this.depthBuffer = new ushort[this.depthFrameDescription.LengthInPixels];
     #endregion
     //BodyIndex
     #region
     this.bodyIndexFrameDes = this.kinect.BodyIndexFrameSource.FrameDescription;
     this.bodyIndexFrameReader = this.kinect.BodyIndexFrameSource.OpenReader();
     this.bodyIndexFrameReader.FrameArrived += this.BodyIndexFrame_Arrived;
     this.bodyIndexBuffer = new byte[this.bodyIndexFrameDes.Width *
                                         this.bodyIndexFrameDes.Height * this.bodyIndexFrameDes.BytesPerPixel];
     #endregion
     //kinect開始
     this.package = new ShadowPackage();
     this.imageWidth = this.bodyIndexFrameDes.Width; 
     this.imageHeight = this.bodyIndexFrameDes.Height; 
     this.imageBytePerPixel = (int)this.bodyIndexFrameDes.BytesPerPixel;
     this.kinectImage = new Mat(this.imageHeight, this.imageWidth, MatType.CV_8UC1);
     this.kinect.Open();
 }
Ejemplo n.º 54
0
        //コンストラクタ
        public getdepth()
        {
            try {
                kinect = KinectSensor.GetDefault();

                this.depthFrameReader = this.kinect.DepthFrameSource.OpenReader();
                this.depthFrameReader.FrameArrived += DepthFrame_Arrived;
                this.depthFrameDescription = this.kinect.DepthFrameSource.FrameDescription;
                this.depthBuffer = new ushort[this.depthFrameDescription.LengthInPixels];
                this.depthImageWidth = this.depthFrameDescription.Width;
                this.depthImageHeight = this.depthFrameDescription.Height;
                this.depthStride = (int)(depthFrameDescription.Width * depthFrameDescription.BytesPerPixel);


                this.kinect.Open();
            }catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 55
0
        public MainWindow()
        {
            this.kinectSensor = KinectSensor.GetDefault();

            this.frameDescription = this.kinectSensor.DepthFrameSource.FrameDescription;
            this.colorFrameDescription = this.kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra);

            this.depthFrameReader = this.kinectSensor.DepthFrameSource.OpenReader();
            //this.depthFrameReader.FrameArrived += depthFrameReader_FrameArrived;
            this.depthBitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
            this.depthPixels = new byte[this.frameDescription.Width * this.frameDescription.Height];

            this.colorFrameReader = this.kinectSensor.ColorFrameSource.OpenReader();
            this.colorFrameReader.FrameArrived += this.colorFrameReader_FrameArrived;     
            this.colorBitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);

            this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader();
            this.bodyFrameReader.FrameArrived += bodyFrameReader_FrameArrived;
            
            this.bodyDrawingGroup = new DrawingGroup();
            this.imageSource = new DrawingImage(bodyDrawingGroup);

            this.coordinateMapper = this.kinectSensor.CoordinateMapper;

            this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged;

            this.kinectSensor.Open();
    
            this.StatusText = this.kinectSensor.IsAvailable ? Properties.Resources.KinectReady : Properties.Resources.NoSensor;
            this.GestureText = "";

            this.DataContext = this;

            descriptionNumber = Convert.ToInt32(Properties.Resources.Precarriage); //Vorlauf Frames

            maxTrainData = Convert.ToInt32(Properties.Resources.MaxTrainData);
            maxTestData = Convert.ToInt32(Properties.Resources.MaxTestData);

            this.InitializeComponent();
        }
Ejemplo n.º 56
0
        public DepthRenderer2(Image Image, KinectSensor sensor)
        {
            // Set the Kinect sensor
            this.kinectSensor = sensor;
            FrameDescription frameDescription = this.kinectSensor.DepthFrameSource.FrameDescription;

            // open the reader for the depth frames
            this.reader = this.kinectSensor.DepthFrameSource.OpenReader();

            // allocate space to put the pixels being received and converted
            this.frameData = new ushort[frameDescription.Width * frameDescription.Height];
            this.pixels = new byte[frameDescription.Width * frameDescription.Height * this.cbytesPerPixel];

            // create the bitmap to display
            this.bitmap = new WriteableBitmap(frameDescription.Width, frameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);

            // Initialize the image
            this.Image = Image;

            // Set the image we display to point to the bitmap where we'll put the image data
            this.Image.Source = this.bitmap;
        }
        /// <summary>
        /// Initializes a new instance of the KinectDepthView class
        /// </summary>
        /// <param name="kinectSensor">Active instance of the Kinect sensor</param>
        public KinectDepthView(KinectSensor kinectSensor)
        {
            if (kinectSensor == null)
            {
                throw new ArgumentNullException("kinectSensor");
            }

            // open the reader for the depth frames
            this.depthFrameReader = kinectSensor.DepthFrameSource.OpenReader();

            // wire handler for frame arrival
            this.depthFrameReader.FrameArrived += this.Reader_DepthFrameArrived;

            // get FrameDescription from DepthFrameSource
            this.depthFrameDescription = kinectSensor.DepthFrameSource.FrameDescription;

            // allocate space to put the pixels being received and converted
            this.depthPixels = new byte[this.depthFrameDescription.Width * this.depthFrameDescription.Height];

            // create the bitmap to display
            this.depthBitmap = new WriteableBitmap(this.depthFrameDescription.Width, this.depthFrameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null);
        }
        protected override void OnNavigatedTo( NavigationEventArgs e )
        {
            base.OnNavigatedTo( e );

            try {
                kinect = KinectSensor.GetDefault();
                if ( kinect == null ) {
                    throw new Exception( "Kinectを開けません" );
                }

                kinect.Open();

                // 表示のためのデータを作成
                depthFrameDesc = kinect.DepthFrameSource.FrameDescription;

                // ビットマップ
                depthBitmap = new WriteableBitmap( depthFrameDesc.Width, depthFrameDesc.Height );
                ImageDepth.Source = depthBitmap;

                // Depthデータ用のバッファ
                depthBuffer = new ushort[depthFrameDesc.LengthInPixels];

                // DepthデータをBGRA(カラー)データにするためのバッファ
                depthBitmapBuffer = new byte[depthFrameDesc.LengthInPixels * 4];

                // 距離を表示する位置
                depthPoint = new Point( depthFrameDesc.Width / 2, depthFrameDesc.Height / 2 );


                // カラーリーダーを開く
                depthFrameReader = kinect.DepthFrameSource.OpenReader();
                depthFrameReader.FrameArrived += depthFrameReader_FrameArrived;
            }
            catch ( Exception ex ) {
                MessageDialog dlg = new MessageDialog(ex.Message);
                dlg.ShowAsync();
            }
        }
Ejemplo n.º 59
0
        /// <summary>
        /// Initializes a new instance of the MainWindow class.
        /// </summary>
        public MainWindow()
        {
            // get the kinectSensor object
            kinectSensor = KinectSensor.GetDefault();

            // open the reader for the depth frames
            depthFrameReader = kinectSensor.DepthFrameSource.OpenReader();

            // wire handler for frame arrival
            depthFrameReader.FrameArrived += Reader_FrameArrived;

            // get FrameDescription from DepthFrameSource
            depthFrameDescription = kinectSensor.DepthFrameSource.FrameDescription;

            // allocate space to put the pixels being received and converted
            depthPixels = new byte[ChunkSize * scale * ChunkSize * scale];
            depthGrid = new ushort[depthFrameDescription.Width, depthFrameDescription.Height];

            // create the bitmap to display
            depthBitmap = new WriteableBitmap(ChunkSize * scale, ChunkSize * scale, ChunkSize, ChunkSize, PixelFormats.Gray8, null);

            // set IsAvailableChanged event notifier
            kinectSensor.IsAvailableChanged += Sensor_IsAvailableChanged;

            // open the sensor
            kinectSensor.Open();

            // set the status text
            StatusText = kinectSensor.IsAvailable ? Properties.Resources.RunningStatusText
                                                            : Properties.Resources.NoSensorStatusText;

            // use the window object as the view model in this simple example
            DataContext = this;

            // initialize the components (controls) of the window
            InitializeComponent();
        }
Ejemplo n.º 60
0
        //CoordinateMappingExample cooordinateMappingExample;

        void CoordinateMapper_CoordinateMappingChanged(object sender, CoordinateMappingChangedEventArgs e)
        {
            kinect2Calibration = new RoomAliveToolkit.Kinect2Calibration();
            kinect2Calibration.RecoverCalibrationFromSensor(kinectSensor);
            kinect2CalibrationReady.Set();

            //cooordinateMappingExample = new CoordinateMappingExample();
            //cooordinateMappingExample.Run(kinect2Calibration, kinectSensor);

            depthFrameReader = kinectSensor.DepthFrameSource.OpenReader();
            depthFrameReader.FrameArrived += depthFrameReader_FrameArrived;

            colorFrameReader = kinectSensor.ColorFrameSource.OpenReader();
            colorFrameReader.FrameArrived += colorFrameReader_FrameArrived;

            bodyFrameReader = kinectSensor.BodyFrameSource.OpenReader();
            bodyFrameReader.FrameArrived += bodyFrameReader_FrameArrived;

            audioBeamFrameReader = kinectSensor.AudioSource.OpenReader();
            audioBeamFrameReader.FrameArrived += audioBeamFrameReader_FrameArrived;

            audioBeamFrameReader.AudioSource.AudioBeams[0].AudioBeamMode = AudioBeamMode.Manual;
            audioBeamFrameReader.AudioSource.AudioBeams[0].BeamAngle = 0;
        }