예제 #1
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();        
    }
예제 #2
0
    // Use this for initialization
    void Start()
    {
        _bones = new GameObject[7] {
            Head, HandLeft, HandRight, KneeLeft, KneeRight, ShoulderLeft, ShoulderRight
        };

        _Sensor = Kinect2.KinectSensor.GetDefault();

        if (_Sensor != null)
        {
            if (!_Sensor.IsOpen)
            {
                if (bDebugLog)
                {
                    Debug.Log("[Kinect2] KinectSensor Open");
                }
                _Sensor.Open();

                // ボディリーダーを開く
                _Reader = _Sensor.BodyFrameSource.OpenReader();
                _Reader.FrameArrived += BodyFrameReader_FrameArrived;
            }
        }

        //gimmick = GameObject.Find("ita");
        flag = false;
    }
예제 #3
0
    public KinectManager()
    {
        _Sensor = Kinect.KinectSensor.GetDefault();
        if (_Sensor == null)
        {
            ExitWithLog("Kinect Sensor not avalibalbe");
        }

        _Reader = _Sensor.OpenMultiSourceFrameReader(
            Kinect.FrameSourceTypes.Depth |
            Kinect.FrameSourceTypes.Body
            );
        if (_Reader == null)
        {
            ExitWithLog("Fail to load multiframe source reader.");
        }

        DepthFrameDesc = _Sensor.DepthFrameSource.FrameDescription;
        Mapper         = _Sensor.CoordinateMapper;

        DepthData = new ushort[DepthFrameDesc.LengthInPixels];
        _BodyData = new Kinect.Body[_Sensor.BodyFrameSource.BodyCount];

        if (!_Sensor.IsOpen)
        {
            _Sensor.Open();
        }
    }
	void Start()
	{
		_Sensor = Kinect.KinectSensor.GetDefault();
		_CoordinateMapper = _Sensor.CoordinateMapper;

		SensorWidth = _Sensor.ColorFrameSource.FrameDescription.Width;
		SensorHeight = _Sensor.ColorFrameSource.FrameDescription.Height;
	}
    void Start()
    {
        _Sensor           = Kinect.KinectSensor.GetDefault();
        _CoordinateMapper = _Sensor.CoordinateMapper;

        SensorWidth  = _Sensor.ColorFrameSource.FrameDescription.Width;
        SensorHeight = _Sensor.ColorFrameSource.FrameDescription.Height;
    }
예제 #6
0
    void Start()
    {
        leftHandCube  = GameObject.CreatePrimitive(PrimitiveType.Cube);
        rightHandCube = GameObject.CreatePrimitive(PrimitiveType.Cube);

        sensor         = Kinect.KinectSensor.GetDefault();
        mapper         = sensor.CoordinateMapper;
        depthFrameInfo = sensor.DepthFrameSource.FrameDescription;
        depthImg       = new Texture2D(depthFrameInfo.Width, depthFrameInfo.Height, TextureFormat.RGB24, false);
    }
    void Start()
    {
        _Sensor = Windows.Kinect.KinectSensor.GetDefault();

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

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

                if (!_Sensor.IsOpen) {
                    _Sensor.Open();
                }
            }
        }
예제 #9
0
 void Start()
 {
     _Sensor = Windows.Kinect.KinectSensor.GetDefault();
     if (_Sensor != null)
     {
         _Reader = _Sensor.BodyFrameSource.OpenReader();
         if (!_Sensor.IsOpen)
         {
             _Sensor.Open();
         }
     }
 }
        public override void SetupReader(Windows.Kinect.KinectSensor kinect2Sensor)
        {
            if (kinect2Sensor != null)
            {
                frameReader = kinect2Sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Color);
                var colorFrameDesc = kinect2Sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba);

                _ColorTexture = new Texture2D(colorFrameDesc.Width, colorFrameDesc.Height, TextureFormat.RGBA32, false);
                _ColorData    = new byte[colorFrameDesc.BytesPerPixel * colorFrameDesc.LengthInPixels];

                coordinateMapper = kinect2Sensor.CoordinateMapper;
            }
        }
예제 #11
0
        public override void SetupReader(Windows.Kinect.KinectSensor kinect2Sensor)
        {
            if (kinect2Sensor != null)
            {
                infraredReader = kinect2Sensor.InfraredFrameSource.OpenReader();
                var infraredFrameDesc = kinect2Sensor.InfraredFrameSource.FrameDescription;
                _InfraredData    = new ushort[infraredFrameDesc.LengthInPixels];
                _InfraredRawData = new byte[infraredFrameDesc.LengthInPixels * 4];
                _InfraredTexture = new Texture2D(infraredFrameDesc.Width, infraredFrameDesc.Height, TextureFormat.BGRA32, false);

                coordinateMapper = kinect2Sensor.CoordinateMapper;
            }
        }
예제 #12
0
        void Start()
        {
            _sensor = Kinect.KinectSensor.GetDefault();

            if (_sensor != null)
            {
                _reader = _sensor.BodyFrameSource.OpenReader();

                if (!_sensor.IsOpen)
                {
                    _sensor.Open();
                }
            }
        }
예제 #13
0
        void Start()
        {
            _sensor   = Kinect.KinectSensor.GetDefault();
            bodies    = new Dictionary <ulong, GameObject>();
            trackedID = new List <string>();
            if (_sensor != null)
            {
                _reader = _sensor.BodyFrameSource.OpenReader();

                if (!_sensor.IsOpen)
                {
                    _sensor.Open();
                }
            }
        }
        void OnApplicationQuit()
        {
            if (_Reader != null) {
                _Reader.Dispose();
                _Reader = null;
            }

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

                _Sensor = null;
            }
        }
예제 #15
0
    private void OnApplicationQuit()
    {
        if (bDebugLog)
        {
            Debug.Log("AutoMotionCaptureDevicesSelecter.OnApplicationQuit");
        }
        // Perception Neuron(1-5)
        int i = 0;

        foreach (SNeuronConnection sNeuronConnection in sNeuronConnections)
        {
            if (sNeuronConnection.sNeuronSource != null)
            {
                NeuronConnection.DestroyConnection(sNeuronConnection.sNeuronSource);
                if (bDebugLog)
                {
                    Debug.Log("[Perception Neuron_" + (i + 1) + "] DestroyConnection");
                }
            }
            i++;
        }
        // Kinect1
        NativeMethods.NuiShutdown();
        if (bDebugLog)
        {
            Debug.Log("[Kinect1] KinectSensor Shutdown");
        }
        // Kinect2
        Kinect2.KinectSensor _Sensor = Kinect2.KinectSensor.GetDefault();
        if (_Sensor != null)
        {
            if (_Sensor.IsOpen)
            {
                _Sensor.Close();
                if (bDebugLog)
                {
                    Debug.Log("[Kinect2] KinectSensor Close");
                }
            }
            else
            {
                if (bDebugLog)
                {
                    Debug.Log("[Kinect2] KinectSensor Closed");
                }
            }
        }
    }
예제 #16
0
 void OnApplicationQuit()
 {
     if (_Reader != null)
     {
         _Reader.Dispose();
         _Reader = null;
     }
     if (_Sensor != null)
     {
         if (_Sensor.IsOpen)
         {
             _Sensor.Close();
         }
         _Sensor = null;
     }
 }
    void Start()
    {
        _Sensor = Windows.Kinect.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();
            }
        }
    }
예제 #18
0
파일: Test.cs 프로젝트: 0tsukq/LabLife
    // 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();


    }
예제 #19
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);
    }
예제 #20
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);
    }
예제 #21
0
    private void OnDestroy()
    {
        if (reader != null)
        {
            reader.Dispose();
            reader = null;
        }

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

            sensor = null;
        }
    }
예제 #22
0
    private void OnApplicationQuit()
    {
        if (Reader != null)
        {
            Reader.Dispose();
            Reader = null;
        }

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

            Sensor = null;
        }
    }
예제 #23
0
        void OnApplicationQuit()
        {
            if (_reader != null)
            {
                _reader.Dispose();
                _reader = null;
            }

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

                _sensor = null;
            }
        }
예제 #24
0
        //
        public GestureDetector(KinectSensor sensor, string databaseFilename)
        {
            // check
            if (sensor == null)
            {
                Debug.LogError("There is not Kinect Device.");
                return;
            }

            // 创建VGB帧数据源
            m_VGBSource = VisualGestureBuilderFrameSource.Create(sensor, 0);
            m_VGBSource.TrackingIdLost += this.Source_TrackingIdLost;

            // 获得VGB帧读取器
            m_VGBReader = m_VGBSource.OpenReader();

            // check
            if (m_VGBReader != null)
            {
                m_VGBReader.IsPaused = true;
                m_VGBReader.FrameArrived += GestureFrameArrived;
                //Debug.Log("VGBFrameReader is paused");
            } else
            {
                Debug.LogError("Can not get VGBReader.");
                return;
            }

            // 加载手势特征库
            var databasePath = Path.Combine(Application.streamingAssetsPath, databaseFilename);
            m_VGBDatabase = VisualGestureBuilderDatabase.Create(databasePath);

            if (m_VGBDatabase != null)
            {
                m_VGBGestures = m_VGBDatabase.AvailableGestures;
            } else
            {
                Debug.LogError("Can not load VGBDatabase.");
                return;
            }

            //
            m_bInit = true;
        }
예제 #25
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>();
    }
예제 #26
0
    protected virtual void Start()
    {
        try
        {
            Sensor = Kinect.KinectSensor.GetDefault();

            if (Sensor != null)
            {
                Reader = Sensor.BodyFrameSource.OpenReader();

                if (!Sensor.IsOpen)
                {
                    Sensor.Open();
                }
            }
        }
        catch
        {
            Debug.Log("Error: No Kinect found.");
        }
    }
예제 #27
0
    private void Start()
    {
        sensor = Windows.Kinect.KinectSensor.GetDefault();

        if (sensor != null)
        {
            reader = sensor.DepthFrameSource.OpenReader();
            data   = new ushort[sensor.DepthFrameSource.FrameDescription.LengthInPixels];
            width  = sensor.DepthFrameSource.FrameDescription.Width;
            heigth = sensor.DepthFrameSource.FrameDescription.Height;

            if (!sensor.IsOpen)
            {
                sensor.Open();
            }
        }
        else
        {
            Debug.LogErrorFormat("Failed to acquire Kinect Sensor!");
        }
    }
    void Start()
    {
        _Sensor = Windows.Kinect.KinectSensor.GetDefault();

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

            var frameDesc = _Sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba);
            ColorWidth = frameDesc.Width;
            ColorHeight = frameDesc.Height;

            _Texture = new Texture2D(frameDesc.Width, frameDesc.Height, TextureFormat.RGBA32, false);
            _Data = new byte[frameDesc.BytesPerPixel * frameDesc.LengthInPixels];

            if (!_Sensor.IsOpen)
            {
                _Sensor.Open();
            }
        }
    }
예제 #29
0
    protected virtual void Start()
    {
        try
        {
            Sensor = Kinect.KinectSensor.GetDefault();

            if (Sensor != null)
            {
                Reader = Sensor.BodyFrameSource.OpenReader();

                if (!Sensor.IsOpen)
                {
                    Sensor.Open();
                }
            }
        }
        catch
        {
            Debug.Log("Error: No Kinect found.");
        }
    }
예제 #30
0
    void Start()
    {
        if (instance == null)
        {
            instance = this;
        }

        sensor = Kinect.KinectSensor.GetDefault();

        if (sensor != null)
        {
            sensor.Open();
        }

        reader = sensor.OpenMultiSourceFrameReader(Kinect.FrameSourceTypes.Body | Kinect.FrameSourceTypes.Color | Kinect.FrameSourceTypes.Depth | Kinect.FrameSourceTypes.Infrared);
        reader.MultiSourceFrameArrived += Reader_MultiSourceFrameArrived;
        playersIdBreak = new List <ulong>();
        playersIdBreak.Clear();
        players     = new bool[6];
        countBodies = 0;
    }
    void InitializeDefaultSensor()
    {
        m_pKinectSensor = Windows.Kinect.KinectSensor.GetDefault();

        if (m_pKinectSensor != null)
        {
            // Initialize the Kinect and get coordinate mapper and the frame reader
            m_pCoordinateMapper = m_pKinectSensor.CoordinateMapper;

            m_pKinectSensor.Open();
            if (m_pKinectSensor.IsOpen)
            {
                m_pMultiSourceFrameReader = m_pKinectSensor.OpenMultiSourceFrameReader(
                    FrameSourceTypes.Color | FrameSourceTypes.Depth | FrameSourceTypes.BodyIndex);
            }
        }

        if (m_pKinectSensor == null)
        {
            UnityEngine.Debug.LogError("No ready Kinect found!");
        }
    }
예제 #32
0
    //Methof to initialise your kinect
    void InitKinect()
    {
        _getsureBasePath = Path.Combine(Application.streamingAssetsPath, "GestureDB/JumpDB.gbd");
        _dbGestures      = VisualGestureBuilderDatabase.Create(_getsureBasePath);
        _bodies          = new Windows.Kinect.Body[6];
        _kinect          = Windows.Kinect.KinectSensor.GetDefault();
        _kinect.Open();
        _gestureFrameSource = VisualGestureBuilderFrameSource.Create(_kinect, 0);

        //for each gesture in trained database of custom gestures - add them to kinect frame source
        foreach (Gesture gest in _dbGestures.AvailableGestures)
        {
            _gestureFrameSource.AddGesture(gest);
            if (gest.Name == "Jump")
            {
                _jump = gest;
            }
            else if (gest.Name == "Lean_Left")
            {
                _moveLeft = gest;
            }
            else if (gest.Name == "Lean_Right")
            {
                _moveRight = gest;
            }
            else if (gest.Name == "Swing")
            {
                _swing = gest;
            }
        }
        _bodyFrameSource = _kinect.BodyFrameSource;
        _bodyFrameReader = _bodyFrameSource.OpenReader();
        _bodyFrameReader.FrameArrived += _bodyFrameReader_FrameArrived;

        _gestureFrameReader               = _gestureFrameSource.OpenReader();
        _gestureFrameReader.IsPaused      = true;
        _gestureFrameReader.FrameArrived += _gestureFrameReader_FrameArrived;
    }
    void Start()
    {
        Kinect2Interface sensorInterface = KinectManager.Instance.GetSensorData().sensorInterface as Kinect2Interface;

        Windows.Kinect.KinectSensor kinectSensor = sensorInterface != null ? sensorInterface.kinectSensor : null;

        if (kinectSensor != null)
        {
            this.audioSource = kinectSensor.AudioSource;
            this.audioReader = audioSource.OpenReader();

            Debug.Log("AudioSource IsActive: " + audioSource.IsActive);

            if (audioReader != null)
            {
                Debug.Log("KinectAudio successfully initialized.");
            }
            else
            {
                Debug.Log("KinectAudio initialization failed.");
            }
        }
    }
    void Start()
    {
        _Sensor = Windows.Kinect.KinectSensor.GetDefault();

        if (_Sensor != null)
        {
            _Reader = _Sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Color | FrameSourceTypes.Depth);

            var colorFrameDesc = _Sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba);
            ColorWidth = colorFrameDesc.Width;
            ColorHeight = colorFrameDesc.Height;

            _ColorTexture = new Texture2D(colorFrameDesc.Width, colorFrameDesc.Height, TextureFormat.RGBA32, false);
            _ColorData = new byte[colorFrameDesc.BytesPerPixel * colorFrameDesc.LengthInPixels];

            var depthFrameDesc = _Sensor.DepthFrameSource.FrameDescription;
            _DepthData = new ushort[depthFrameDesc.LengthInPixels];

            if (!_Sensor.IsOpen)
            {
                _Sensor.Open();
            }
        }
    }
예제 #35
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;
        }
    }
예제 #36
0
        //
        private void Start()
        {
            m_Sensor = KinectSensor.GetDefault();

            if (m_Sensor != null)
            {
                //
                m_CoordinateMapper = m_Sensor.CoordinateMapper;

                //
                m_Reader = m_Sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Color | FrameSourceTypes.Depth | FrameSourceTypes.Body | FrameSourceTypes.BodyIndex);

                var colorFrameDesc = m_Sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba);
                ColorWidth = colorFrameDesc.Width;
                ColorHeight = colorFrameDesc.Height;

                m_ColorTexture = new Texture2D(colorFrameDesc.Width, colorFrameDesc.Height, TextureFormat.RGBA32, false);
                m_ColorData = new byte[colorFrameDesc.BytesPerPixel * colorFrameDesc.LengthInPixels];

                m_ColorMappedToDepthPoints = new DepthSpacePoint[ColorWidth * ColorHeight];

                //
                var depthFrameDesc = m_Sensor.DepthFrameSource.FrameDescription;
                DepthWidth = depthFrameDesc.Width;
                DepthHeight = depthFrameDesc.Height;

                m_DepthData = new ushort[depthFrameDesc.Width * depthFrameDesc.Height];

                m_DepthCoordinates = new DepthSpacePoint[colorFrameDesc.Width * colorFrameDesc.Height];

                //
                m_BodyData = new Body[m_Sensor.BodyFrameSource.BodyCount];

                //
                var bodyIndexFrameDesc = m_Sensor.BodyIndexFrameSource.FrameDescription;
                BodyIndexWidth = bodyIndexFrameDesc.Width;
                BodyIndexHeight = bodyIndexFrameDesc.Height;
                m_BodyIndexData = new byte[ bodyIndexFrameDesc.Width * bodyIndexFrameDesc.Height ];

                //
                if (!m_Sensor.IsOpen)
                {
                    m_Sensor.Open();
                }
            }
        }
    void OnApplicationQuit()
    {
        pDepthBuffer = null;
        pColorBuffer = null;
        pBodyIndexBuffer = null;

        if (m_pDepthCoordinates != null)
        {
            m_pDepthCoordinates = null;
        }

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

        if (m_pKinectSensor != null)
        {
            m_pKinectSensor.Close();
            m_pKinectSensor = null;
        }
    }
예제 #38
0
    void Start()
    {
        // FBX Exporter for Unity (Sync Animation Custom Frame)
        if (sFBXExporterForUnity != null)
        {
            if (sFBXExporterForUnity.enabled)
            {
                sFBXExporterForUnity.bOutAnimation            = false;
                sFBXExporterForUnity.bOutAnimationCustomFrame = true;
            }
        }
        else
        {
            if (GameObject.Find(strFBXExporterForUnity) != null)
            {
                sFBXExporterForUnity = GameObject.Find(strFBXExporterForUnity).GetComponent <FBXExporterForUnity>();
            }
        }

        switch (eAutoMotionCaptureDevicesSelecter)
        {
        case EAutoMotionCaptureDevicesSelecter.eAuto:
        {
            // Perception Neuron(1-5)
            int iSelect = 0;
            foreach (SNeuronConnection sNeuronConnection in sNeuronConnections)
            {
                sNeuronConnections[iSelect].sNeuronSource = NeuronConnection.CreateConnection(sNeuronConnection.address, sNeuronConnection.port, sNeuronConnection.commandServerPort, sNeuronConnection.socketType);
                if (sNeuronConnections[iSelect].sNeuronSource != null)
                {
                    eAutoMotionCaptureDevicesSelecter = (EAutoMotionCaptureDevicesSelecter)(EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_1 + iSelect);
                    NeuronConnection.DestroyConnection(sNeuronConnections[iSelect].sNeuronSource);
                    bCheckedDevices = true;
                    if (bDebugLog)
                    {
                        Debug.Log("Auto Devices Selecter Enabled [Perception Neuron_" + (iSelect + 1) + "]");
                    }
                    return;
                }
                iSelect++;
            }

            // Kinect1
            int hr = NativeMethods.NuiInitialize(NuiInitializeFlags.UsesDepthAndPlayerIndex | NuiInitializeFlags.UsesSkeleton | NuiInitializeFlags.UsesColor);
            if (hr == 0)
            {
                eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eKinect1;
                NativeMethods.NuiShutdown();
                bCheckedDevices = true;
                if (bDebugLog)
                {
                    Debug.Log("Auto Devices Selecter Enabled [Kinect1]");
                }
                return;
            }

            // Kinect2
            Kinect2.KinectSensor _Sensor = Kinect2.KinectSensor.GetDefault();
            if (_Sensor != null)
            {
                //if (!_Sensor.IsOpen)
                {
                    _Sensor.Open();
                    if (_Sensor.IsOpen)
                    {
                        _Sensor.IsAvailableChanged += (sender, evt) =>
                        {
                            if (!bCheckedDevices)
                            {
                                if (_Sensor.IsAvailable)
                                {
                                    eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eKinect2;
                                    bCheckedDevices = true;
                                    if (bDebugLog)
                                    {
                                        Debug.Log("Auto Devices Selecter Enabled [Kinect2]");
                                    }
                                    return;
                                }
                            }
                        };
                    }
                }
            }
            break;
        }

        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_1:
        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_2:
        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_3:
        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_4:
        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_5:
        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_6:
        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_7:
        case EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_8:
        {
            // Perception Neuron(1-5)
            int iSelect = (int)eAutoMotionCaptureDevicesSelecter - (int)EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_1;
            sNeuronConnections[iSelect].sNeuronSource = NeuronConnection.CreateConnection(sNeuronConnections[iSelect].address, sNeuronConnections[iSelect].port, sNeuronConnections[iSelect].commandServerPort, sNeuronConnections[iSelect].socketType);
            if (sNeuronConnections[iSelect].sNeuronSource != null)
            {
                eAutoMotionCaptureDevicesSelecter = (EAutoMotionCaptureDevicesSelecter)(EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron_1 + iSelect);
                NeuronConnection.DestroyConnection(sNeuronConnections[iSelect].sNeuronSource);
                bCheckedDevices = true;
                if (bDebugLog)
                {
                    Debug.Log("Auto Devices Selecter Enabled [Perception Neuron_" + (iSelect + 1) + "]");
                }
                return;
            }
            break;
        }

        case EAutoMotionCaptureDevicesSelecter.eKinect1:
        {
            // Kinect1
            int hr = NativeMethods.NuiInitialize(NuiInitializeFlags.UsesDepthAndPlayerIndex | NuiInitializeFlags.UsesSkeleton | NuiInitializeFlags.UsesColor);
            if (hr == 0)
            {
                eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eKinect1;
                NativeMethods.NuiShutdown();
                bCheckedDevices = true;
                if (bDebugLog)
                {
                    Debug.Log("Auto Devices Selecter Enabled [Kinect1]");
                }
                return;
            }
            break;
        }

        case EAutoMotionCaptureDevicesSelecter.eKinect2:
        {
            // Kinect2
            Kinect2.KinectSensor _Sensor = Kinect2.KinectSensor.GetDefault();
            if (_Sensor != null)
            {
                if (!_Sensor.IsOpen)
                {
                    _Sensor.Open();
                    if (_Sensor.IsOpen)
                    {
                        _Sensor.IsAvailableChanged += (sender, evt) =>
                        {
                            if (!bCheckedDevices)
                            {
                                if (_Sensor.IsAvailable)
                                {
                                    eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eKinect2;
                                    bCheckedDevices = true;
                                    if (bDebugLog)
                                    {
                                        Debug.Log("Auto Devices Selecter Enabled [Kinect2]");
                                    }
                                    return;
                                }
                            }
                        };
                    }
                }
                else
                {
                    eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eKinect2;
                    bCheckedDevices = true;
                    if (bDebugLog)
                    {
                        Debug.Log("Auto Devices Selecter Enabled [Kinect2] -Sensor Opened-");
                    }
                    return;
                }
            }
            break;
        }
        }
        eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eNone;
    }
예제 #39
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.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;
        }
예제 #40
0
    void OnApplicationQuit()
    {
        if (_Mapper != null)
        {
            _Mapper = null;
        }

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

            _Sensor = null;
        }
    }
예제 #41
0
        //
        private void OnApplicationQuit()
        {
            //
            if (m_Sensor != null)
            {
                if (m_Sensor.IsOpen)
                {
                    m_Sensor.Close();
                }

                m_Sensor = null;
            }

            //
            foreach (var detector in m_GestureDetectorList)
            {
                detector.OnGesture -= this.OnGestureInLocal;
                detector.Dispose();
            }
            //
            m_GestureDetectorList.Clear();
        }
예제 #42
0
 public CoordinateMapper(KinectSensor sensor)
 {
     this.sensor = sensor;
 }
예제 #43
0
    void Start()
    {
        // FBX Exporter for Unity (Sync Animation Custom Frame)
        if (sFBXExporterForUnity != null)
        {
            if (sFBXExporterForUnity.enabled)
            {
                sFBXExporterForUnity.bOutAnimation            = false;
                sFBXExporterForUnity.bOutAnimationCustomFrame = true;
            }
        }

        // Perception Neuron
        NeuronSource source = CreateConnection(Neuron_address, Neuron_port, Neuron_commandServerPort, Neuron_socketType);

        if (source != null)
        {
            eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.ePerceptionNeuron;
            if (source != null)
            {
                source.OnDestroy();
            }
            bCheckedDevices = true;
            if (bDebugLog)
            {
                Debug.Log("Auto Devices Selecter Enabled [Perception Neuron]");
            }
            return;
        }
        // Kinect1
        int hr = NativeMethods.NuiInitialize(NuiInitializeFlags.UsesDepthAndPlayerIndex | NuiInitializeFlags.UsesSkeleton | NuiInitializeFlags.UsesColor);

        if (hr != 0)
        {
        }
        else
        {
            eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eKinect1;
            NativeMethods.NuiShutdown();
            bCheckedDevices = true;
            if (bDebugLog)
            {
                Debug.Log("Auto Devices Selecter Enabled [Kinect1]");
            }
            return;
        }
        // Kinect2
        Kinect2.KinectSensor _Sensor = Kinect2.KinectSensor.GetDefault();
        if (_Sensor != null)
        {
            if (!_Sensor.IsOpen)
            {
                _Sensor.Open();
                _Sensor.IsAvailableChanged += (sender, evt) => {
                    if (!bCheckedDevices)
                    {
                        if (_Sensor.IsAvailable)
                        {
                            eAutoMotionCaptureDevicesSelecter = EAutoMotionCaptureDevicesSelecter.eKinect2;
                            if (_Sensor != null)
                            {
                                if (bDebugLog)
                                {
                                    Debug.Log("[Kinect2] KinectSensor Close");
                                }
                                _Sensor.Close();
                            }
                        }
                        bCheckedDevices = true;
                        if (bDebugLog)
                        {
                            Debug.Log("Auto Devices Selecter Enabled [Kinect2]");
                        }
                        return;
                    }
                };
            }
        }
    }
예제 #44
0
 void Start()
 {
     _Sensor = Kinect.KinectSensor.GetDefault();
 }
예제 #45
0
    private void OnApplicationQuit()
    {
        if (Reader != null)
        {
            Reader.Dispose();
            Reader = null;
        }

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

            Sensor = null;
        }
    }
예제 #46
0
    void Start()
    {
        _Sensor = Windows.Kinect.KinectSensor.GetDefault();
        if (_Sensor != null)
        {
            _Mapper = _Sensor.CoordinateMapper;
            var frameDesc = _Sensor.DepthFrameSource.FrameDescription;

            // Downsample to lower resolution
            CreateMesh(frameDesc.Width / _DownsampleSize, frameDesc.Height / _DownsampleSize);

            if (!_Sensor.IsOpen)
            {
                _Sensor.Open();
            }
        }
    }
예제 #47
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;
            }
        }
 void Awake()
 {
     this.Config = new Configuration();
     this.sensor = KinectSensor.GetDefault();
 }
예제 #49
0
    // Use this for initialization
    void Start()
    {
        AddTag("realtime01");
        AddTag("Body_Replay");

        lineMat       = new Material(Shader.Find("Diffuse"));
        lineMat.color = Color.yellow;
        GameObject temp = GameObject.CreatePrimitive(PrimitiveType.Capsule);

        cylinderMesh = temp.GetComponent <MeshFilter> ().sharedMesh;
        GameObject.Destroy(temp);
        radius      = 0.03f;
        sensitive   = 1.0f;
        body_scale  = 1.0f;
        bone_scale  = 0.02f;
        joint_scale = 0.04f;

        skeletonlist = new GameObject[] {
            skeleton_spinebased
            , skeleton_hipleft
            , skeleton_hipright
            , skeleton_spinemid
            , skeleton_kneeleft
            , skeleton_ankleleft
            , skeleton_kneeright
            , skeleton_ankleright
            , skeleton_spineshoulder
            , skeleton_neck
            , skeleton_shoulderleft
            , skeleton_head
            , skeleton_shoulderright
            , skeleton_elbowleft
            , skeleton_wristleft
            , skeleton_handleft
            , skeleton_elbowright
            , skeleton_wristright
            , skeleton_handright
        };

        canvash = ((RectTransform)canvas.transform).rect.height / 2.0f;
        canvasw = ((RectTransform)canvas.transform).rect.width / 2.0f;
        lefthand.SetActive(false);
        realtime_relation = GameObject.Find("realtime_relation");
        //turnScript = Player.GetComponent<Turning>();
        // get the sensor object

        this.kinectSensor = Kinect.KinectSensor.GetDefault();

        if (this.kinectSensor != null)
        {
            this.bodyCount = this.kinectSensor.BodyFrameSource.BodyCount;

            // color reader
            this.colorFrameReader = this.kinectSensor.ColorFrameSource.OpenReader();

            // create buffer from RGBA frame description
            var desc = this.kinectSensor.ColorFrameSource.CreateFrameDescription(Kinect.ColorImageFormat.Rgba);


            // body data
            this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader();

            // body frame to use
            this.bodies = new Kinect.Body[this.bodyCount];

            // initialize the gesture detection objects for our gestures
            this.gestureDetectorList = new List <GestureDetector>();


            //real_time_skeleton_init ();
            for (int bodyIndex = 0; bodyIndex < this.bodyCount; bodyIndex++)
            {
                //PUT UPDATED UI STUFF HERE FOR NO GESTURE
                //GestureTextGameObject.text = "none";
                //this.bodyText[bodyIndex] = "none";
                this.gestureDetectorList.Add(new GestureDetector(this.kinectSensor));
            }

            // start getting data from runtime
            this.kinectSensor.Open();
        }
        else
        {
            //kinect sensor not connected
        }
    }
	private Vector3 _chestRight; //right vectory of the chest	
	
	// Use this for initialization
	void Start () {
        if (sFBXExporterForUnity != null)
        {
            sFBXExporterForUnity.bOutAnimation = false;
            sFBXExporterForUnity.bOutAnimationCustomFrame = true;
        }
		_Sensor = Kinect2.KinectSensor.GetDefault();
        if (_Sensor != null)
        {
            if (!_Sensor.IsOpen)
            {
                if (bDebugLog) Debug.Log("[Kinect2] KinectSensor Open");
                _Sensor.Open();
                _Reader = _Sensor.OpenMultiSourceFrameReader(/*Kinect2.FrameSourceTypes.Color |
				                                             Kinect2.FrameSourceTypes.Depth |
				                                             Kinect2.FrameSourceTypes.Infrared |
				                                             */
                                                             Kinect2.FrameSourceTypes.Body);
                _Reader.MultiSourceFrameArrived += Reader_MultiSourceFrameArrived;
            }
            else
            {
                if (bDebugLog) Debug.Log("[Kinect2] KinectSensor Opened");
                _Reader = _Sensor.OpenMultiSourceFrameReader(/*Kinect2.FrameSourceTypes.Color |
				                                             Kinect2.FrameSourceTypes.Depth |
				                                             Kinect2.FrameSourceTypes.Infrared |
				                                             */
                                                             Kinect2.FrameSourceTypes.Body);
                _Reader.MultiSourceFrameArrived += Reader_MultiSourceFrameArrived;
            }
        }
		//store bones in a list for easier access, everything except Hip_Center will be one
		//higher than the corresponding Kinect2.NuiSkeletonPositionIndex (because of the hip_override)
		_bones = new GameObject[(int)Kinect2.JointType.ThumbRight + 1] {
			null, SpineMid, SpineShoulder, Neck,
			CollarLeft, ShoulderLeft, ElbowLeft, WristLeft,
			CollarRight, ShoulderRight, ElbowRight, WristRight,
			HipOverride, HipLeft, KneeLeft, AnkleLeft,
			null, HipRight, KneeRight, AnkleRight,
			Head, HandLeft, HandRight, FootLeft, FootRight};
			//SpineShoulder, HandTipLeft, ThumbLeft, HandTipRight, ThumbRight, FootLeft, FootRight};

		_vecbones = new Vector3[(int)Kinect2.JointType.ThumbRight + 1];
		_vecbones2 = new Vector3[(int)Kinect2.JointType.ThumbRight + 1];
		_qbones = new Quaternion[(int)Kinect2.JointType.ThumbRight + 1];
		_qbones2 = new Quaternion[(int)Kinect2.JointType.ThumbRight + 1];

		//determine which bones are not available
		for(int ii = 0; ii < _bones.Length; ii++)
		{
			if(_bones[ii] == null)
			{
				_nullMask |= (uint)(1 << ii);
			}
		}
		
		//store the base rotations and bone directions (in bone-local space)
		_baseRotation = new Quaternion[(int)Kinect2.JointType.ThumbRight + 1];
		_boneDir = new Vector3[(int)Kinect2.JointType.ThumbRight + 1];
		
		//first save the special rotations for the hip and spine
		_hipRight = HipRight.transform.position - HipLeft.transform.position;
		_hipRight = HipOverride.transform.InverseTransformDirection(_hipRight);
		
		_chestRight = ShoulderRight.transform.position - ShoulderLeft.transform.position;
		_chestRight = SpineMid.transform.InverseTransformDirection(_chestRight);
		
		//get direction of all other bones
		for( int ii = 0; ii < (int)Kinect2.JointType.ThumbRight- 4; ii++)
		{
			if((_nullMask & (uint)(1 << ii)) <= 0)
			{
				//if the bone is the end of a limb, get direction from this bone to one of the extras (hand or foot).
				if(ii % 4 == 3 && ((_nullMask & (uint)(1 << (ii/4) + (int)Kinect2.JointType.ThumbRight - 4)) <= 0))
				{
					_boneDir[ii] = _bones[(ii/4) + (int)Kinect2.JointType.ThumbRight - 4].transform.position - _bones[ii].transform.position;
				}
				//if the bone is the hip_override (at boneindex Hip_Left, get direction from average of left and right hips
				else if(ii == (int)Kinect2.JointType.HipLeft && HipLeft != null && HipRight != null)
				{
					_boneDir[ii] = ((HipRight.transform.position + HipLeft.transform.position) / 2.0f) - HipOverride.transform.position;
				}
				//otherwise, get the vector from this bone to the next.
				else if((_nullMask & (uint)(1 << ii+1)) <= 0)
				{
					_boneDir[ii] = _bones[ii+1].transform.position - _bones[ii].transform.position;
				}
				else
				{
					continue;
				}
				//Since the spine of the kinect data is ~40 degrees back from the hip,
				//check what angle the spine is at and rotate the saved direction back to match the data
				if(ii == (int)Kinect2.JointType.SpineMid)
				{
					float angle = Vector3.Angle(transform.up,_boneDir[ii]);
					_boneDir[ii] = Quaternion.AngleAxis(angle,transform.right) * _boneDir[ii];
				}
				//transform the direction into local space.
				_boneDir[ii] = _bones[ii].transform.InverseTransformDirection(_boneDir[ii]);
			}
		}
		//make _chestRight orthogonal to the direction of the spine.
		_chestRight -= Vector3.Project(_chestRight, _boneDir[(int)Kinect2.JointType.SpineMid]);
		//make _hipRight orthogonal to the direction of the hip override
		Vector3.OrthoNormalize(ref _boneDir[(int)Kinect2.JointType.HipLeft],ref _hipRight);
		// Root
		Root.transform.localRotation = Quaternion.Euler(fRotRootX, 0.0f, 0.0f);
	}
예제 #51
0
        // Use this for initialization
        private void Start()
        {
            // check
            if (string.IsNullOrEmpty(m_VGBDatabaseFilename))
            {
                Debug.LogError("The VGBDatabaseFilename is null or empty.");
                return;
            }

            // 获得kinect设备对象
            m_Sensor = KinectSensor.GetDefault();

            //
            if (m_Sensor == null)
            {
                Debug.LogError("There is not Kinect Device.");
                return;
            }

            int nBodyCount = m_Sensor.BodyFrameSource.BodyCount;

            for (int i = 0; i < nBodyCount; ++i)
            {
                GestureDetector detector = new GestureDetector(m_Sensor, m_VGBDatabaseFilename);
                detector.OnGesture += this.OnGestureInLocal;
                m_GestureDetectorList.Add(detector);
            }

            // 加载手势特征库
            var databasePath = Path.Combine(Application.streamingAssetsPath, m_VGBDatabaseFilename);
            using (VisualGestureBuilderDatabase database = VisualGestureBuilderDatabase.Create( databasePath ))
            {
                List<string> names = new List<string>();
                foreach (Gesture gesture in database.AvailableGestures)
                {
                    names.Add(gesture.Name);
                }
                m_GestureNames = names.ToArray();
            }

            //
            m_bInit = true;
        }
예제 #52
0
    private Vector3 _chestRight;        //right vectory of the chest

    // Use this for initialization
    void Start()
    {
        /*
         * if (sFBXExporterForUnity != null)
         * {
         *  sFBXExporterForUnity.bOutAnimation = false;
         *  sFBXExporterForUnity.bOutAnimationCustomFrame = true;
         * }
         */
        _Sensor = Kinect2.KinectSensor.GetDefault();
        if (_Sensor != null)
        {
            if (!_Sensor.IsOpen)
            {
                if (bDebugLog)
                {
                    Debug.Log("[Kinect2] KinectSensor Open");
                }
                _Sensor.Open();
                _Reader = _Sensor.OpenMultiSourceFrameReader(/*Kinect2.FrameSourceTypes.Color |
                                                              *              Kinect2.FrameSourceTypes.Depth |
                                                              *              Kinect2.FrameSourceTypes.Infrared |
                                                              */
                    Kinect2.FrameSourceTypes.Body);
                _Reader.MultiSourceFrameArrived += Reader_MultiSourceFrameArrived;
            }
            else
            {
                if (bDebugLog)
                {
                    Debug.Log("[Kinect2] KinectSensor Opened");
                }
                _Reader = _Sensor.OpenMultiSourceFrameReader(/*Kinect2.FrameSourceTypes.Color |
                                                              *              Kinect2.FrameSourceTypes.Depth |
                                                              *              Kinect2.FrameSourceTypes.Infrared |
                                                              */
                    Kinect2.FrameSourceTypes.Body);
                _Reader.MultiSourceFrameArrived += Reader_MultiSourceFrameArrived;
            }
        }
        //store bones in a list for easier access, everything except Hip_Center will be one
        //higher than the corresponding Kinect2.NuiSkeletonPositionIndex (because of the hip_override)

        /*削除 _bones = new GameObject[(int)Kinect2.JointType.ThumbRight + 1] {
         *               null, SpineMid, SpineShoulder, Neck,
         *               CollarLeft, ShoulderLeft, ElbowLeft, WristLeft,
         *               CollarRight, ShoulderRight, ElbowRight, WristRight,
         *               HipOverride, HipLeft, KneeLeft, AnkleLeft,
         *               null, HipRight, KneeRight, AnkleRight,
         *               Head, HandLeft, HandRight, FootLeft, FootRight};*/
        //SpineShoulder, HandTipLeft, ThumbLeft, HandTipRight, ThumbRight, FootLeft, FootRight};
        _bones = new GameObject[5] {
            Head, HandLeft, HandRight, KneeLeft, KneeRight
        };

        _vecbones  = new Vector3[(int)Kinect2.JointType.ThumbRight + 1];
        _vecbones2 = new Vector3[(int)Kinect2.JointType.ThumbRight + 1];
        _qbones    = new Quaternion[(int)Kinect2.JointType.ThumbRight + 1];
        _qbones2   = new Quaternion[(int)Kinect2.JointType.ThumbRight + 1];

        //determine which bones are not available
        for (int ii = 0; ii < _bones.Length; ii++)
        {
            if (_bones[ii] == null)
            {
                _nullMask |= (uint)(1 << ii);
            }
        }

        //store the base rotations and bone directions (in bone-local space)
        _baseRotation = new Quaternion[(int)Kinect2.JointType.ThumbRight + 1];
        _boneDir      = new Vector3[(int)Kinect2.JointType.ThumbRight + 1];

        //first save the special rotations for the hip and spine

        /*_hipRight = HipRight.transform.position - HipLeft.transform.position;
         * _hipRight = HipOverride.transform.InverseTransformDirection(_hipRight);
         *
         * _chestRight = ShoulderRight.transform.position - ShoulderLeft.transform.position;
         * _chestRight = SpineMid.transform.InverseTransformDirection(_chestRight);*/

        //get direction of all other bones

        /*for (int ii = 0; ii < (int)Kinect2.JointType.ThumbRight - 4; ii++)
         * {
         *  if ((_nullMask & (uint)(1 << ii)) <= 0)
         *  {
         *      //if the bone is the end of a limb, get direction from this bone to one of the extras (hand or foot).
         *      if (ii % 4 == 3 && ((_nullMask & (uint)(1 << (ii / 4) + (int)Kinect2.JointType.ThumbRight - 4)) <= 0))
         *      {
         *          _boneDir[ii] = _bones[(ii / 4) + (int)Kinect2.JointType.ThumbRight - 4].transform.position - _bones[ii].transform.position;
         *      }
         *      //if the bone is the hip_override (at boneindex Hip_Left, get direction from average of left and right hips
         *      else if (ii == (int)Kinect2.JointType.HipLeft && HipLeft != null && HipRight != null)
         *      {
         *          _boneDir[ii] = ((HipRight.transform.position + HipLeft.transform.position) / 2.0f) - HipOverride.transform.position;
         *      }
         *      //otherwise, get the vector from this bone to the next.
         *      else if ((_nullMask & (uint)(1 << ii + 1)) <= 0)
         *      {
         *          _boneDir[ii] = _bones[ii + 1].transform.position - _bones[ii].transform.position;
         *      }
         *      else
         *      {
         *          continue;
         *      }
         *      //Since the spine of the kinect data is ~40 degrees back from the hip,
         *      //check what angle the spine is at and rotate the saved direction back to match the data
         *      if (ii == (int)Kinect2.JointType.SpineMid)
         *      {
         *          float angle = Vector3.Angle(transform.up, _boneDir[ii]);
         *          _boneDir[ii] = Quaternion.AngleAxis(angle, transform.right) * _boneDir[ii];
         *      }
         *      //transform the direction into local space.
         *      _boneDir[ii] = _bones[ii].transform.InverseTransformDirection(_boneDir[ii]);
         *  }
         * }
         * //make _chestRight orthogonal to the direction of the spine.
         * _chestRight -= Vector3.Project(_chestRight, _boneDir[(int)Kinect2.JointType.SpineMid]);
         * //make _hipRight orthogonal to the direction of the hip override
         * Vector3.OrthoNormalize(ref _boneDir[(int)Kinect2.JointType.HipLeft], ref _hipRight);
         * // Root
         * Root.transform.localRotation = Quaternion.Euler(fRotRootX, 0.0f, 0.0f);*/
    }
예제 #53
0
        //
        private void OnApplicationQuit()
        {
            if (m_Reader != null)
            {
                m_Reader.Dispose();
                m_Reader = null;
            }

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

                m_Sensor = null;
            }
        }