public KinectInterop.SensorData OpenDefaultSensor(KinectInterop.FrameSource dwFlags, float sensorAngle, bool bUseMultiSource)
    {
        KinectInterop.SensorData sensorData = new KinectInterop.SensorData();
        sensorFlags = dwFlags;

        kinectSensor = KinectSensor.GetDefault();
        if(kinectSensor == null)
            return null;

        coordMapper = kinectSensor.CoordinateMapper;

        this.bodyCount = kinectSensor.BodyFrameSource.BodyCount;
        sensorData.bodyCount = this.bodyCount;
        sensorData.jointCount = 25;

        sensorData.depthCameraFOV = 60f;
        sensorData.colorCameraFOV = 53.8f;
        sensorData.depthCameraOffset = -0.05f;
        sensorData.faceOverlayOffset = -0.04f;

        if((dwFlags & KinectInterop.FrameSource.TypeBody) != 0)
        {
            if(!bUseMultiSource)
                bodyFrameReader = kinectSensor.BodyFrameSource.OpenReader();

            bodyData = new Body[sensorData.bodyCount];
        }

        var frameDesc = kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba);
        sensorData.colorImageWidth = frameDesc.Width;
        sensorData.colorImageHeight = frameDesc.Height;

        if((dwFlags & KinectInterop.FrameSource.TypeColor) != 0)
        {
            if(!bUseMultiSource)
                colorFrameReader = kinectSensor.ColorFrameSource.OpenReader();

            sensorData.colorImage = new byte[frameDesc.BytesPerPixel * frameDesc.LengthInPixels];
        }

        sensorData.depthImageWidth = kinectSensor.DepthFrameSource.FrameDescription.Width;
        sensorData.depthImageHeight = kinectSensor.DepthFrameSource.FrameDescription.Height;

        if((dwFlags & KinectInterop.FrameSource.TypeDepth) != 0)
        {
            if(!bUseMultiSource)
                depthFrameReader = kinectSensor.DepthFrameSource.OpenReader();

            sensorData.depthImage = new ushort[kinectSensor.DepthFrameSource.FrameDescription.LengthInPixels];
        }

        if((dwFlags & KinectInterop.FrameSource.TypeBodyIndex) != 0)
        {
            if(!bUseMultiSource)
                bodyIndexFrameReader = kinectSensor.BodyIndexFrameSource.OpenReader();

            sensorData.bodyIndexImage = new byte[kinectSensor.BodyIndexFrameSource.FrameDescription.LengthInPixels];
        }

        if((dwFlags & KinectInterop.FrameSource.TypeInfrared) != 0)
        {
            if(!bUseMultiSource)
                infraredFrameReader = kinectSensor.InfraredFrameSource.OpenReader();

            sensorData.infraredImage = new ushort[kinectSensor.InfraredFrameSource.FrameDescription.LengthInPixels];
        }

        //if(!kinectSensor.IsOpen)
        {
            //Debug.Log("Opening sensor, available: " + kinectSensor.IsAvailable);
            kinectSensor.Open();
        }

        float fWaitTime = Time.realtimeSinceStartup + 3f;
        while(!kinectSensor.IsAvailable && Time.realtimeSinceStartup < fWaitTime)
        {
            // wait for sensor to open
        }

        Debug.Log("K2-sensor " + (kinectSensor.IsOpen ? "opened" : "closed") +
                  ", available: " + kinectSensor.IsAvailable);

        if(bUseMultiSource && dwFlags != KinectInterop.FrameSource.TypeNone && kinectSensor.IsOpen)
        {
            multiSourceFrameReader = kinectSensor.OpenMultiSourceFrameReader((FrameSourceTypes)((int)dwFlags & 0x3F));
        }

        return sensorData;
    }
Esempio n. 2
0
        private static void Windows_Data_PropertyChangedEventArgs_Delegate_Handler(IntPtr result, IntPtr pNative)
        {
            List <EventHandler <PropertyChangedEventArgs> > list = null;

            DepthFrameReader.Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryGetValue(pNative, out list);
            object obj = list;

            lock (obj)
            {
                DepthFrameReader         objThis = NativeObjectCache.GetObject <DepthFrameReader>(pNative);
                PropertyChangedEventArgs args    = new PropertyChangedEventArgs(result);
                using (List <EventHandler <PropertyChangedEventArgs> > .Enumerator enumerator = list.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        EventHandler <PropertyChangedEventArgs> func = enumerator.Current;
                        EventPump.Instance.Enqueue(delegate
                        {
                            try
                            {
                                func(objThis, args);
                            }
                            catch
                            {
                            }
                        });
                    }
                }
            }
        }
Esempio n. 3
0
    // Use this for initialization
    void Start()
    {
        this.imageHeight = 424;
        this.imageWidth = 512;

        this.sensor = Windows.Kinect.KinectSensor.GetDefault();
        this.depthreader = this.sensor.DepthFrameSource.OpenReader();
        this.RawData = new ushort[this.depthreader.DepthFrameSource.FrameDescription.LengthInPixels];
        this.SaveRawData = new ushort[this.depthreader.DepthFrameSource.FrameDescription.LengthInPixels];
        this.ListCube = new List<GameObject>();

        this.cameraSpacePoints = new Windows.Kinect.CameraSpacePoint[this.depthreader.DepthFrameSource.FrameDescription.LengthInPixels];

        if (!this.IsArchive)
        {
            this.depthreader.FrameArrived += depthreader_FrameArrived;
            this.sensor.Open();
        }
        if (this.IsArchive)
        {
            this.saveData = this.ReadDepth.GetComponent<ReadDepth>();

        }

        this.centerPos = new Vector3();        
    }
Esempio n. 4
0
    void Start()
    {
        _Sensor = KinectSensor.GetDefault();

        if (_Sensor != null)
        {
            _Reader = _Sensor.DepthFrameSource.OpenReader();
            _Data = new ushort[_Sensor.DepthFrameSource.FrameDescription.LengthInPixels];
        }
    }
    public void CloseSensor(KinectInterop.SensorData sensorData)
    {
        if(coordMapper != null)
        {
            coordMapper = null;
        }

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

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

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

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

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

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

        if(kinectSensor != null)
        {
            if (kinectSensor.IsOpen)
            {
                kinectSensor.Close();
            }

            kinectSensor = null;
        }
    }
Esempio n. 6
0
        // Token: 0x06002C3A RID: 11322 RVA: 0x000DCDF8 File Offset: 0x000DB1F8
        public DepthFrame AcquireLatestFrame()
        {
            if (this._pNative == IntPtr.Zero)
            {
                throw new ObjectDisposedException("DepthFrameReader");
            }
            IntPtr intPtr = DepthFrameReader.Windows_Kinect_DepthFrameReader_AcquireLatestFrame(this._pNative);

            ExceptionHelper.CheckLastError();
            if (intPtr == IntPtr.Zero)
            {
                return(null);
            }
            return(NativeObjectCache.CreateOrGetObject <DepthFrame>(intPtr, (IntPtr n) => new DepthFrame(n)));
        }
Esempio n. 7
0
 // Token: 0x06002C2A RID: 11306 RVA: 0x000DC8B0 File Offset: 0x000DACB0
 private void Dispose(bool disposing)
 {
     if (this._pNative == IntPtr.Zero)
     {
         return;
     }
     this.__EventCleanup();
     NativeObjectCache.RemoveObject <DepthFrameReader>(this._pNative);
     if (disposing)
     {
         DepthFrameReader.Windows_Kinect_DepthFrameReader_Dispose(this._pNative);
     }
     DepthFrameReader.Windows_Kinect_DepthFrameReader_ReleaseObject(ref this._pNative);
     this._pNative = IntPtr.Zero;
 }
Esempio n. 8
0
    // Use this for initialization
    void Start()
    {
        this.imageHeight = 424;
        this.imageWidth = 512;

        this.sensor = Windows.Kinect.KinectSensor.GetDefault();
        this.depthreader = this.sensor.DepthFrameSource.OpenReader();
        this.RawData = new ushort[this.depthreader.DepthFrameSource.FrameDescription.LengthInPixels];
        this.ListCube = new List<GameObject>();

        this.cameraSpacePoints = new Windows.Kinect.CameraSpacePoint[this.depthreader.DepthFrameSource.FrameDescription.LengthInPixels];
        this.depthreader.FrameArrived += depthreader_FrameArrived;
        this.sensor.Open();
        
        this.centerPos = new Vector3();
        this.hidePositon = new Vector3(0, -100, 0);
    }
Esempio n. 9
0
    // Use this for initialization
    void Start()
    {
        this.imageHeight = 424;
        this.imageWidth  = 512;

        this.sensor      = Windows.Kinect.KinectSensor.GetDefault();
        this.depthreader = this.sensor.DepthFrameSource.OpenReader();
        this.RawData     = new ushort[this.depthreader.DepthFrameSource.FrameDescription.LengthInPixels];
        this.ListCube    = new List <GameObject>();

        this.cameraSpacePoints         = new Windows.Kinect.CameraSpacePoint[this.depthreader.DepthFrameSource.FrameDescription.LengthInPixels];
        this.depthreader.FrameArrived += depthreader_FrameArrived;
        this.sensor.Open();

        this.centerPos   = new Vector3();
        this.hidePositon = new Vector3(0, -100, 0);
    }
Esempio n. 10
0
    // Use this for initialization
	void Start () {

        

        this.sensor = Windows.Kinect.KinectSensor.GetDefault();
        this.depthreader = this.sensor.DepthFrameSource.OpenReader();
        this.depthreader.FrameArrived += depthreader_FrameArrived;
        this.RawData = new ushort[this.depthreader.DepthFrameSource.FrameDescription.LengthInPixels];

        // particles to be drawn
        particles = new ParticleSystem.Particle[this.depthreader.DepthFrameSource.FrameDescription.LengthInPixels];
        
        this.cameraSpacePoints = new Windows.Kinect.CameraSpacePoint[this.depthreader.DepthFrameSource.FrameDescription.LengthInPixels];
        this.sensor.Open();


    }
Esempio n. 11
0
        // Token: 0x06002C3D RID: 11325 RVA: 0x000DCE90 File Offset: 0x000DB290
        private void __EventCleanup()
        {
            DepthFrameReader.Windows_Kinect_DepthFrameArrivedEventArgs_Delegate_callbacks.TryAddDefault(this._pNative);
            List <EventHandler <DepthFrameArrivedEventArgs> > list = DepthFrameReader.Windows_Kinect_DepthFrameArrivedEventArgs_Delegate_callbacks[this._pNative];
            object obj = list;

            lock (obj)
            {
                if (list.Count > 0)
                {
                    list.Clear();
                    if (this._pNative != IntPtr.Zero)
                    {
                        IntPtr pNative = this._pNative;
                        if (DepthFrameReader.f__mg2 == null)
                        {
                            DepthFrameReader.f__mg2 = new DepthFrameReader._Windows_Kinect_DepthFrameArrivedEventArgs_Delegate(DepthFrameReader.Windows_Kinect_DepthFrameArrivedEventArgs_Delegate_Handler);
                        }
                        DepthFrameReader.Windows_Kinect_DepthFrameReader_add_FrameArrived(pNative, DepthFrameReader.f__mg2, true);
                    }
                    DepthFrameReader._Windows_Kinect_DepthFrameArrivedEventArgs_Delegate_Handle.Free();
                }
            }
            DepthFrameReader.Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(this._pNative);
            List <EventHandler <PropertyChangedEventArgs> > list2 = DepthFrameReader.Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[this._pNative];
            object obj2 = list2;

            lock (obj2)
            {
                if (list2.Count > 0)
                {
                    list2.Clear();
                    if (this._pNative != IntPtr.Zero)
                    {
                        IntPtr pNative2 = this._pNative;
                        if (DepthFrameReader.f__mg3 == null)
                        {
                            DepthFrameReader.f__mg3 = new DepthFrameReader._Windows_Data_PropertyChangedEventArgs_Delegate(DepthFrameReader.Windows_Data_PropertyChangedEventArgs_Delegate_Handler);
                        }
                        DepthFrameReader.Windows_Kinect_DepthFrameReader_add_PropertyChanged(pNative2, DepthFrameReader.f__mg3, true);
                    }
                    DepthFrameReader._Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free();
                }
            }
        }
Esempio n. 12
0
    void OnApplicationQuit()
    {
        if (_Reader != null)
        {
            _Reader.Dispose();
            _Reader = null;
        }

        if (_Sensor != null)
        {
            if (_Sensor.IsOpen)
            {
                _Sensor.Close();
            }

            _Sensor = null;
        }
    }
Esempio n. 13
0
    private void Start()
    {
        _Sensor = Kinect.KinectSensor.GetDefault();

        if (_Sensor != null)
        {
            _ColorReader = _Sensor.ColorFrameSource.OpenReader();
            _DepthReader = _Sensor.DepthFrameSource.OpenReader();

            var colorFrameDesc = _Sensor.ColorFrameSource.CreateFrameDescription(Kinect.ColorImageFormat.Rgba);
            var depthFrameDesc = _Sensor.DepthFrameSource.FrameDescription;

            if (!_Sensor.IsOpen)
            {
                _Sensor.Open();
            }
        }

        bodySourceManager = gameObject.AddComponent <BodySourceManager>();
    }
Esempio n. 14
0
	// Use this for initialization
	void Start () {

		mySensor = KinectSensor.GetDefault();

		if (mySensor != null)
		{
			depthFrameReader = mySensor.DepthFrameSource.OpenReader();
			var depthFrameDescrip = mySensor.DepthFrameSource.FrameDescription;

			depthFrameData = new ushort[depthFrameDescrip.LengthInPixels];

			// Raw data contains B, G, R, A values
			depthRawData = new byte[depthFrameDescrip.LengthInPixels * BYTES_PER_PIXEL];

			depthTex = new Texture2D(depthFrameDescrip.Width, depthFrameDescrip.Height, TextureFormat.BGRA32, false);

			if (!mySensor.IsOpen)
			{
				mySensor.Open();
			}

			//Get the IR image size
			depthImageHeight = depthFrameDescrip.Height;
			depthImageWidth = depthFrameDescrip.Width;

			//Calculate the foreground rectangles
			Rect cameraRect = Camera.main.pixelRect;
			float rectHeight = cameraRect.height;
			float rectWidth = cameraRect.width;

			if (rectWidth > rectHeight)
				rectWidth = rectHeight * depthImageWidth / depthImageHeight;
			else
				rectHeight = rectWidth * depthImageHeight / depthImageWidth;

			float foregroundOfsX = (cameraRect.width - rectWidth) / 2;
			float foregroundOfsY = (cameraRect.height - rectHeight) / 2;
			foregroundImgRect = new Rect(foregroundOfsX, foregroundOfsY, rectWidth, rectHeight);
			foregroundGuiRect = new Rect(foregroundOfsX, cameraRect.height - foregroundOfsY, rectWidth, -rectHeight);
		}
	}
Esempio n. 15
0
    private void OnApplicationQuit()
    {
        if (_ColorReader != null)
        {
            _ColorReader.Dispose();
            _ColorReader = null;
        }

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

        if (_Sensor != null)
        {
            if (_Sensor.IsOpen)
            {
                _Sensor.Close();
            }

            _Sensor = null;
        }
    }
    public void CloseSensor(KinectInterop.SensorData sensorData)
    {
        if(coordMapper != null)
        {
            coordMapper = null;
        }

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

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

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

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

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

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

        if(kinectSensor != null)
        {
            //if (kinectSensor.IsOpen)
            {
                //Debug.Log("Closing sensor, available: " + kinectSensor.IsAvailable);
                kinectSensor.Close();
            }

            float fWaitTime = Time.realtimeSinceStartup + 3f;
            while(kinectSensor.IsOpen && Time.realtimeSinceStartup < fWaitTime)
            {
                // wait for sensor to close
            }

            Debug.Log("K2-sensor " + (kinectSensor.IsOpen ? "opened" : "closed") +
                      ", available: " + kinectSensor.IsAvailable);

            kinectSensor = null;
        }
    }
Esempio n. 17
0
    public KinectInterop.SensorData OpenDefaultSensor(KinectInterop.FrameSource dwFlags, float sensorAngle, bool bUseMultiSource)
    {
        KinectInterop.SensorData sensorData = new KinectInterop.SensorData();
        //sensorFlags = dwFlags;

        kinectSensor = KinectSensor.GetDefault();
        if(kinectSensor == null)
            return null;

        coordMapper = kinectSensor.CoordinateMapper;

        this.bodyCount = kinectSensor.BodyFrameSource.BodyCount;
        sensorData.bodyCount = this.bodyCount;
        sensorData.jointCount = 25;

        sensorData.depthCameraFOV = 60f;
        sensorData.colorCameraFOV = 53.8f;
        sensorData.depthCameraOffset = -0.03f;

        if((dwFlags & KinectInterop.FrameSource.TypeBody) != 0)
        {
            if(!bUseMultiSource)
                bodyFrameReader = kinectSensor.BodyFrameSource.OpenReader();

            bodyData = new Body[sensorData.bodyCount];
        }

        var frameDesc = kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba);
        sensorData.colorImageWidth = frameDesc.Width;
        sensorData.colorImageHeight = frameDesc.Height;

        if((dwFlags & KinectInterop.FrameSource.TypeColor) != 0)
        {
            if(!bUseMultiSource)
                colorFrameReader = kinectSensor.ColorFrameSource.OpenReader();

            sensorData.colorImage = new byte[frameDesc.BytesPerPixel * frameDesc.LengthInPixels];
        }

        sensorData.depthImageWidth = kinectSensor.DepthFrameSource.FrameDescription.Width;
        sensorData.depthImageHeight = kinectSensor.DepthFrameSource.FrameDescription.Height;

        if((dwFlags & KinectInterop.FrameSource.TypeDepth) != 0)
        {
            if(!bUseMultiSource)
                depthFrameReader = kinectSensor.DepthFrameSource.OpenReader();

            sensorData.depthImage = new ushort[kinectSensor.DepthFrameSource.FrameDescription.LengthInPixels];
        }

        if((dwFlags & KinectInterop.FrameSource.TypeBodyIndex) != 0)
        {
            if(!bUseMultiSource)
                bodyIndexFrameReader = kinectSensor.BodyIndexFrameSource.OpenReader();

            sensorData.bodyIndexImage = new byte[kinectSensor.BodyIndexFrameSource.FrameDescription.LengthInPixels];
        }

        if((dwFlags & KinectInterop.FrameSource.TypeInfrared) != 0)
        {
            if(!bUseMultiSource)
                infraredFrameReader = kinectSensor.InfraredFrameSource.OpenReader();

            sensorData.infraredImage = new ushort[kinectSensor.InfraredFrameSource.FrameDescription.LengthInPixels];
        }

        if(!kinectSensor.IsOpen)
        {
            kinectSensor.Open();
        }

        if(bUseMultiSource && dwFlags != KinectInterop.FrameSource.TypeNone && kinectSensor.IsOpen)
        {
            multiSourceFrameReader = kinectSensor.OpenMultiSourceFrameReader((FrameSourceTypes)dwFlags);
        }

        return sensorData;
    }
Esempio n. 18
0
	void OnApplicationQuit()
	{
		if (depthFrameReader != null)
		{
			depthFrameReader.Dispose();
			depthFrameReader = null;
		}
		if (mySensor != null)
		{
			if (mySensor.IsOpen)
				mySensor.Close();
			mySensor = null;
		}
	}
Esempio n. 19
0
 // Token: 0x06002C25 RID: 11301 RVA: 0x000DC85D File Offset: 0x000DAC5D
 internal DepthFrameReader(IntPtr pNative)
 {
     this._pNative = pNative;
     DepthFrameReader.Windows_Kinect_DepthFrameReader_AddRefObject(ref this._pNative);
 }
Esempio n. 20
0
    // Use this for initialization
    void Start()
    {
        terrCollider = GetComponent<TerrainCollider>();
        terrData = terrCollider.terrainData;
        _Sensor = KinectSensor.GetDefault();

        if (_Sensor != null)
        {
            _Reader = _Sensor.DepthFrameSource.OpenReader();
            _Reader.FrameArrived += _Reader_FrameArrived;
            _Data = new ushort[_Sensor.DepthFrameSource.FrameDescription.LengthInPixels];
            Debug.LogFormat("Depth:H:{0} x W:{1}", _Sensor.DepthFrameSource.FrameDescription.Height, _Sensor.DepthFrameSource.FrameDescription.Width);
            Debug.LogFormat("TerrData:H:{0} x W:{1}", terrData.heightmapHeight, terrData.heightmapWidth);
            minDist = _Sensor.DepthFrameSource.DepthMinReliableDistance;
            maxDist = 1500f;// _Sensor.DepthFrameSource.DepthMaxReliableDistance;
            scale = 0.1f / (maxDist - minDist);
            Debug.LogFormat("Depth:Min:{0} x Max:{1} (Scale:{2})", minDist, maxDist, scale);
            mapper = _Sensor.CoordinateMapper;
            _Sensor.Open();
        }
        logFile = new System.IO.StreamWriter(new System.IO.FileStream("e:\\log.txt", System.IO.FileMode.OpenOrCreate));
        Debug.LogFormat("Scale:{0}", terrData.heightmapScale);
        data = new float[terrData.heightmapHeight, terrData.heightmapWidth];
    }