コード例 #1
1
    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;
    }
コード例 #2
0
        private static void Windows_Data_PropertyChangedEventArgs_Delegate_Handler(IntPtr result, IntPtr pNative)
        {
            List <EventHandler <PropertyChangedEventArgs> > list = null;

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

            lock (obj)
            {
                InfraredFrameReader      objThis = NativeObjectCache.GetObject <InfraredFrameReader>(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
                            {
                            }
                        });
                    }
                }
            }
        }
コード例 #3
0
    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;
        }
    }
コード例 #4
0
ファイル: NinjaUser.cs プロジェクト: iEmily/nutra-ninja
	void OnApplicationQuit()
	{
		if (irFrameReader != null)
		{
			irFrameReader.Dispose();
			irFrameReader = null;
		}
		if (mySensor != null)
		{
			if (mySensor.IsOpen)
				mySensor.Close();
			mySensor = null;
		}
	}
コード例 #5
0
 // Token: 0x06002CB6 RID: 11446 RVA: 0x000DDFE4 File Offset: 0x000DC3E4
 private void Dispose(bool disposing)
 {
     if (this._pNative == IntPtr.Zero)
     {
         return;
     }
     this.__EventCleanup();
     NativeObjectCache.RemoveObject <InfraredFrameReader>(this._pNative);
     if (disposing)
     {
         InfraredFrameReader.Windows_Kinect_InfraredFrameReader_Dispose(this._pNative);
     }
     InfraredFrameReader.Windows_Kinect_InfraredFrameReader_ReleaseObject(ref this._pNative);
     this._pNative = IntPtr.Zero;
 }
コード例 #6
0
        // Token: 0x06002CC6 RID: 11462 RVA: 0x000DE52C File Offset: 0x000DC92C
        public InfraredFrame AcquireLatestFrame()
        {
            if (this._pNative == IntPtr.Zero)
            {
                throw new ObjectDisposedException("InfraredFrameReader");
            }
            IntPtr intPtr = InfraredFrameReader.Windows_Kinect_InfraredFrameReader_AcquireLatestFrame(this._pNative);

            ExceptionHelper.CheckLastError();
            if (intPtr == IntPtr.Zero)
            {
                return(null);
            }
            return(NativeObjectCache.CreateOrGetObject <InfraredFrame>(intPtr, (IntPtr n) => new InfraredFrame(n)));
        }
コード例 #7
0
 void Start()
 {
     _Sensor = KinectSensor.GetDefault();
     if (_Sensor != null) 
     {
         _Reader = _Sensor.InfraredFrameSource.OpenReader();
         var frameDesc = _Sensor.InfraredFrameSource.FrameDescription;
         _Data = new ushort[frameDesc.LengthInPixels];
         _RawData = new byte[frameDesc.LengthInPixels * 4];
         _Texture = new Texture2D(frameDesc.Width, frameDesc.Height, TextureFormat.BGRA32, false);
         
         if (!_Sensor.IsOpen)
         {
             _Sensor.Open();
         }
     }
 }
コード例 #8
0
        // Token: 0x06002CC9 RID: 11465 RVA: 0x000DE5C4 File Offset: 0x000DC9C4
        private void __EventCleanup()
        {
            InfraredFrameReader.Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate_callbacks.TryAddDefault(this._pNative);
            List <EventHandler <InfraredFrameArrivedEventArgs> > list = InfraredFrameReader.Windows_Kinect_InfraredFrameArrivedEventArgs_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 (InfraredFrameReader.f__mg2 == null)
                        {
                            InfraredFrameReader.f__mg2 = new InfraredFrameReader._Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate(InfraredFrameReader.Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate_Handler);
                        }
                        InfraredFrameReader.Windows_Kinect_InfraredFrameReader_add_FrameArrived(pNative, InfraredFrameReader.f__mg2, true);
                    }
                    InfraredFrameReader._Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate_Handle.Free();
                }
            }
            InfraredFrameReader.Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(this._pNative);
            List <EventHandler <PropertyChangedEventArgs> > list2 = InfraredFrameReader.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 (InfraredFrameReader.f__mg3 == null)
                        {
                            InfraredFrameReader.f__mg3 = new InfraredFrameReader._Windows_Data_PropertyChangedEventArgs_Delegate(InfraredFrameReader.Windows_Data_PropertyChangedEventArgs_Delegate_Handler);
                        }
                        InfraredFrameReader.Windows_Kinect_InfraredFrameReader_add_PropertyChanged(pNative2, InfraredFrameReader.f__mg3, true);
                    }
                    InfraredFrameReader._Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free();
                }
            }
        }
コード例 #9
0
 void OnApplicationQuit()
 {
     if (_Reader != null) 
     {
         _Reader.Dispose();
         _Reader = null;
     }
     
     if (_Sensor != null) 
     {
         if (_Sensor.IsOpen)
         {
             _Sensor.Close();
         }
         
         _Sensor = null;
     }
 }
コード例 #10
0
ファイル: NinjaUser.cs プロジェクト: iEmily/nutra-ninja
	// Use this for initialization
	void Start()
	{
		mySensor = KinectSensor.GetDefault();

		if (mySensor != null)
		{
			irFrameReader = mySensor.InfraredFrameSource.OpenReader();
			var irFrameDescrip = mySensor.InfraredFrameSource.FrameDescription;

			irFrameData = new ushort[irFrameDescrip.LengthInPixels * irFrameDescrip.Width * irFrameDescrip.Height];

			// Raw data contains B, G, R, A values 
			irRawData = new byte[irFrameDescrip.LengthInPixels * irFrameDescrip.Width * irFrameDescrip.Height * 4];

			irTexture = new Texture2D(irFrameDescrip.Width, irFrameDescrip.Height, TextureFormat.BGRA32, false);

			if (!mySensor.IsOpen)
			{
				mySensor.Open();
			}
		}
	}
コード例 #11
0
    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;
        }
    }
コード例 #12
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;
    }
コード例 #13
0
 // Token: 0x06002CB1 RID: 11441 RVA: 0x000DDF91 File Offset: 0x000DC391
 internal InfraredFrameReader(IntPtr pNative)
 {
     this._pNative = pNative;
     InfraredFrameReader.Windows_Kinect_InfraredFrameReader_AddRefObject(ref this._pNative);
 }