예제 #1
0
파일: TrayIcon.cs 프로젝트: GEMISIS/Hermes
        private void startCamera()
        {
            session = PXCMSession.CreateInstance();
            manager = session.CreateSenseManager();

            if (manager == null)
            {
                Console.WriteLine("Failed");
            }
            manager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 1920, 1080, 30);
            manager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 640, 480, 60);
            manager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_IR, 640, 480, 60);
            manager.EnableHand();

            PXCMHandConfiguration config = manager.QueryHand().CreateActiveConfiguration();

            config.EnableAllAlerts();
            config.EnableSegmentationImage(true);
            config.EnableTrackedJoints(true);
            config.LoadGesturePack("navigation");
            config.EnableAllGestures(true);

            config.ApplyChanges();
            config.Dispose();

            manager.Init();

            thread = new Thread(new ThreadStart(updateThread));
            thread.Start();
        }
예제 #2
0
 void SetHandConfig()
 {
     config = handAnalyzer.CreateActiveConfiguration();
     config.EnableAllGestures();
     config.EnableAllAlerts();
     config.ApplyChanges();
     config.Dispose();
 }
예제 #3
0
    void Start()
    {
        // Initialise a PXCMSenseManager instance
        psm = PXCMSenseManager.CreateInstance();
        if (psm == null)
        {
            Debug.LogError("SenseManager Init Failed");
            return;
        }

        // Enable the depth and colour streams
        psm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 640, 480);
        psm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 480);

        // Enable hand analysis
        pxcmStatus sts = psm.EnableHand();

        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("SenseManager Hand Init Failed");
            OnDisable();
            return;
        }
        handModule = psm.QueryHand();

        // Initialise the execution pipeline
        sts = psm.Init();
        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("SenseManager Pipeline Init Failed");
            OnDisable();
            return;
        }

        handData = handModule.CreateOutput();

        handConfig = handModule.CreateActiveConfiguration();
        handConfig.EnableAllGestures();
        handConfig.ApplyChanges();

        foreach (CapsuleCollider capsule in GetComponentsInChildren <CapsuleCollider>())
        {
            hands.Add(capsule.gameObject);
        }

        mainCamera = GetComponentInChildren <Camera>();
    }
예제 #4
0
    private Hashtable handList;                            //keep track of bodyside and hands for GUItext

    // Use this for initialization
    void Start()
    {
        handList = new Hashtable();

        /* Initialize a PXCMSenseManager instance */
        sm = PXCMSenseManager.CreateInstance();
        if (sm == null)
        {
            Debug.LogError("SenseManager Initialization Failed");
        }

        /* Enable hand tracking and retrieve an hand module instance to configure */
        sts          = sm.EnableHand();
        handAnalyzer = sm.QueryHand();
        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("PXCSenseManager.EnableHand: " + sts);
        }

        /* Initialize the execution pipeline */
        sts = sm.Init();
        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("PXCSenseManager.Init: " + sts);
        }

        /* Retrieve the the DataSmoothing instance */
        sm.QuerySession().CreateImpl <PXCMSmoother>(out smoother);

        /* Create a 3D Weighted algorithm */
        smoother3D = new PXCMSmoother.Smoother3D[MaxHands][];

        /* Configure a hand - Enable Gestures and Alerts */
        PXCMHandConfiguration hcfg = handAnalyzer.CreateActiveConfiguration();

        if (hcfg != null)
        {
            hcfg.EnableAllGestures();
            hcfg.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_NOT_DETECTED);
            hcfg.ApplyChanges();
            hcfg.Dispose();
        }

        InitializeGameobjects();
    }
예제 #5
0
        void OnEnable()
        {
            Initialized = false;

            /* Create a SenseManager instance */
            SenseManager = PXCMSenseManager.CreateInstance();

            if (SenseManager == null)
            {
                print("Unable to create the pipeline instance");
                return;
            }

            if (_speechCommandsRef.Count != 0)
            {
                SetSenseOption(SenseOption.SenseOptionID.Speech);
            }

            int numberOfEnabledModalities = 0;

            //Set mode according to RunMode - play from file / record / live stream
            if (RunMode == MCTTypes.RunModes.PlayFromFile)
            {
                //CHECK IF FILE EXISTS
                if (!System.IO.File.Exists(FilePath))
                {
                    Debug.LogWarning("No Filepath Set Or File Doesn't Exist, Run Mode Will Be Changed to Live Stream");
                    RunMode = MCTTypes.RunModes.LiveStream;
                }
                else
                {
                    PXCMCaptureManager cManager = SenseManager.QueryCaptureManager();
                    cManager.SetFileName(FilePath, false);
                    Debug.Log("SenseToolkitManager: Playing from file: " + FilePath);
                }
            }

            if (RunMode == MCTTypes.RunModes.RecordToFile)
            {
                //CHECK IF PATH
                string PathOnly = FilePath;
                while (!PathOnly[PathOnly.Length - 1].Equals('\\'))
                {
                    PathOnly = PathOnly.Remove(PathOnly.Length - 1, 1);
                }

                if (!System.IO.Directory.Exists(PathOnly))
                {
                    Debug.LogWarning("No Filepath Set Or Path Doesn't Exist, Run Mode Will Be Changed to Live Stream");
                    RunMode = MCTTypes.RunModes.LiveStream;
                }
                else
                {
                    PXCMCaptureManager cManager = SenseManager.QueryCaptureManager();
                    cManager.SetFileName(FilePath, true);
                    Debug.Log("SenseToolkitManager: Recording to file: " + FilePath);
                }
            }

            /* Enable modalities according to the set options*/
            if (IsSenseOptionSet(SenseOption.SenseOptionID.Face, true))
            {
                SenseManager.EnableFace();
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Face).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Face).Enabled     = true;
                SetSenseOption(SenseOption.SenseOptionID.VideoColorStream);
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Hand, true))
            {
                _sts = SenseManager.EnableHand();
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Hand).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Hand).Enabled     = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Blob, true))
            {
                _sts = SenseManager.EnableBlob();
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Blob).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Blob).Enabled     = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Object, true))
            {
                _sts = SenseManager.EnableTracker();
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Object).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Object).Enabled     = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Speech, true))
            {
                if (!SpeechManager.IsInitialized)
                {
                    if (SpeechManager.InitalizeSpeech())
                    {
                        _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Speech).Initialized = true;
                        _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Speech).Enabled     = true;
                        numberOfEnabledModalities++;
                    }
                    else
                    {
                        UnsetSenseOption(SenseOption.SenseOptionID.Speech);
                    }
                }
                else
                {
                    _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Speech).Initialized = true;
                    _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Speech).Enabled     = true;
                    numberOfEnabledModalities++;
                }
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.VideoDepthStream, true) ||
                IsSenseOptionSet(SenseOption.SenseOptionID.PointCloud, true))
            {
                SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 0, 0, 0);
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoDepthStream).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoDepthStream).Enabled     = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.VideoIRStream, true))
            {
                SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_IR, 0, 0, 0);
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoIRStream).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoIRStream).Enabled     = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.VideoColorStream, true))
            {
                if (ColorImageQuality == MCTTypes.RGBQuality.FullHD)
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 1920, 1080, 0);
                }
                else if (ColorImageQuality == MCTTypes.RGBQuality.HD)
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 1280, 720, 0);
                }
                else if (ColorImageQuality == MCTTypes.RGBQuality.HalfHD)
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 960, 540, 0);
                }
                else
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 480, 0);
                }
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoColorStream).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoColorStream).Enabled     = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.VideoSegmentation, true))
            {
                if (ColorImageQuality == MCTTypes.RGBQuality.FullHD)
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 1920, 1080, 0);
                }
                else if (ColorImageQuality == MCTTypes.RGBQuality.HD)
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 1280, 720, 0);
                }
                else if (ColorImageQuality == MCTTypes.RGBQuality.HalfHD)
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 960, 540, 0);
                }
                else
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 480, 0);
                }
                SenseManager.Enable3DSeg();
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoSegmentation).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoSegmentation).Enabled     = true;
                numberOfEnabledModalities++;
            }

            /* Initialize the execution */
            _sts = SenseManager.Init();
            if (_sts < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                return;
            }

            //Set different configurations:

            // Face
            if (IsSenseOptionSet(SenseOption.SenseOptionID.Face, true))
            {
                var faceModule = SenseManager.QueryFace();
                if (faceModule == null)
                {
                    throw new UnityException("QueryFace returned null");
                }

                var faceConfiguration = faceModule.CreateActiveConfiguration();
                if (faceConfiguration == null)
                {
                    throw new UnityException("CreateActiveConfiguration returned null");
                }

                faceConfiguration.Update();

                faceConfiguration.detection.isEnabled      = true;
                faceConfiguration.detection.smoothingLevel = PXCMFaceConfiguration.SmoothingLevelType.SMOOTHING_DISABLED;

                faceConfiguration.landmarks.isEnabled      = true;
                faceConfiguration.landmarks.smoothingLevel = PXCMFaceConfiguration.SmoothingLevelType.SMOOTHING_DISABLED;

                faceConfiguration.pose.isEnabled      = true;
                faceConfiguration.pose.smoothingLevel = PXCMFaceConfiguration.SmoothingLevelType.SMOOTHING_DISABLED;

                faceConfiguration.DisableAllAlerts();

                faceConfiguration.strategy = PXCMFaceConfiguration.TrackingStrategyType.STRATEGY_APPEARANCE_TIME;

                if ((NumberOfDetectedFaces < 1) || (NumberOfDetectedFaces > 15))
                {
                    Debug.Log("Ilegal value for Number Of Detected Faces, value is set to 1");
                    NumberOfDetectedFaces = 1;
                }

                faceConfiguration.detection.maxTrackedFaces = NumberOfDetectedFaces;
                faceConfiguration.landmarks.maxTrackedFaces = NumberOfDetectedFaces;
                faceConfiguration.pose.maxTrackedFaces      = NumberOfDetectedFaces;

                PXCMFaceConfiguration.ExpressionsConfiguration expressionConfig = faceConfiguration.QueryExpressions();
                if (expressionConfig == null)
                {
                    throw new UnityException("QueryExpressions returned null");
                }

                expressionConfig.Enable();
                expressionConfig.EnableAllExpressions();


                faceConfiguration.ApplyChanges();
                faceConfiguration.Dispose();

                FaceModuleOutput = faceModule.CreateOutput();

                UnsetSenseOption(SenseOption.SenseOptionID.VideoColorStream);
            }

            // Hand
            if (IsSenseOptionSet(SenseOption.SenseOptionID.Hand, true))
            {
                PXCMHandModule handAnalysis = SenseManager.QueryHand();
                if (handAnalysis == null)
                {
                    throw new UnityException("QueryHand returned null");
                }

                PXCMHandConfiguration handConfiguration = handAnalysis.CreateActiveConfiguration();
                if (handConfiguration == null)
                {
                    throw new UnityException("CreateActiveConfiguration returned null");
                }

                handConfiguration.Update();
                handConfiguration.EnableAllGestures();
                handConfiguration.EnableStabilizer(true);
                handConfiguration.DisableAllAlerts();
                handConfiguration.EnableSegmentationImage(false);
                handConfiguration.ApplyChanges();
                handConfiguration.Dispose();

                HandDataOutput = handAnalysis.CreateOutput();
            }

            // Blob
            if (IsSenseOptionSet(SenseOption.SenseOptionID.Blob, true))
            {
                PXCMBlobModule blobAnalysis = SenseManager.QueryBlob();
                if (blobAnalysis == null)
                {
                    throw new UnityException("QueryBlob returned null");
                }

                PXCMBlobConfiguration blobConfiguration = blobAnalysis.CreateActiveConfiguration();
                if (blobConfiguration == null)
                {
                    throw new UnityException("CreateActiveConfiguration returned null");
                }

                blobConfiguration.Update();
                blobConfiguration.EnableContourExtraction(true);
                blobConfiguration.EnableSegmentationImage(true);
                blobConfiguration.EnableStabilizer(true);
                blobConfiguration.SetMaxDistance(50 * 10);
                blobConfiguration.ApplyChanges();
                blobConfiguration.Dispose();

                BlobDataOutput = blobAnalysis.CreateOutput();
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Object, true))
            {
                if (_senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Object).Enabled != true)
                {
                    _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Object).Enabled = true;
                    OnDisable();
                    OnEnable();
                }
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Speech, true))
            {
                UpdateSpeechCommands();
                SpeechManager.Start();
            }

            // Create an instance for the projection & blob extractor

            if (Projection == null)
            {
                Projection = SenseManager.QueryCaptureManager().QueryDevice().CreateProjection();
            }

            /* GZ
             *          if (BlobExtractor == null)
             *          {
             *                  SenseManager.session.CreateImpl<PXCMBlobExtractor>(out BlobExtractor);
             *          }*/

            // Set initialization flag
            Initialized = true;
        }
예제 #6
0
    void Start()
    {
        if (CursorObject != null)
        {
            mCursor0 = (GameObject)Instantiate(CursorObject, Vector3.zero, Quaternion.identity);
            mCursor0.transform.SetParent(Camera.main.transform);
            mCursor0.transform.localScale = new Vector3(CursorSize, CursorSize, CursorSize);
            mCursor0Active = false;
            mCursor1       = (GameObject)Instantiate(CursorObject, Vector3.zero, Quaternion.identity);
            mCursor1.transform.SetParent(Camera.main.transform);
            mCursor1.transform.localScale = new Vector3(CursorSize, CursorSize, CursorSize);
            mCursor1Active = false;
        }

        mRS = PXCMSenseManager.CreateInstance();
        var stat = pxcmStatus.PXCM_STATUS_NO_ERROR;

        if (mRS != null)
        {
            stat = mRS.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 640, 480);
            if (stat >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                stat = mRS.EnableHand();
                if (stat >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    stat = mRS.Init();
                    Debug.Log("Sense Manager Started");
                }
            }

            else
            {
                Debug.Log("Unable to start Sense Manager");
            }
            if (stat >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                PXCMHandConfiguration cfg = mRS.QueryHand().CreateActiveConfiguration();
                if (cfg != null)
                {
                    stat = cfg.SetTrackingMode(PXCMHandData.TrackingModeType.TRACKING_MODE_CURSOR);
                    if (stat >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        Debug.Log("Set Cursor Mode 1st Pass");
                        if (stat >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                        {
                            stat = cfg.EnableAllGestures(false);
                            if (stat >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                            {
                                stat = cfg.ApplyChanges();
                                if (stat >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                                {
                                    stat = cfg.Update();
                                }
                            }
                        }
                        else
                        {
                            Debug.Log("Unable to enable gestures");
                        }
                    }
                    else
                    {
                        Debug.Log("Unable to set Cursor Mode");
                    }
                    cfg.Dispose();
                }
            }

            else
            {
                Debug.Log("Unable to create hand config");
            }

            mHand = mRS.QueryHand().CreateOutput();
            if (mHand != null)
            {
                Debug.Log("Created Hand Data");
                var tracking = mRS.QueryHand().CreateActiveConfiguration().QueryTrackingMode();
                if (tracking == PXCMHandData.TrackingModeType.TRACKING_MODE_CURSOR)
                {
                    Debug.Log("Cursor Mode Enabled");
                }
            }
        }
        else
        {
            Debug.Log("Unable to configure hand module");
        }
        Application.targetFrameRate = 60;

        ResetHead.SetRoomRotation();
    }
예제 #7
0
    /* Constructor */
    public HandsData(int MaxHands, int MaxJoints)
    {
        NumOfHands  = MaxHands;
        NumOfJoints = MaxJoints;
        JointData   = new PXCMHandData.JointData[NumOfHands][]; // Joint coordinates
        Coordinates = new Main.HandCoord[NumOfHands];

        /* Declaration of the array for the hand data*/
        for (int i = 0; i < NumOfHands; i++)
        {
            JointData[i]   = new PXCMHandData.JointData[NumOfJoints];
            Coordinates[i] = new Main.HandCoord(6, NumOfJoints);
            for (int j = 0; j < NumOfJoints; j++)
            {
                JointData[i][j] = new PXCMHandData.JointData();
            }
        }

        /* Initialization of SenseManager */
        SenseManager = PXCMSenseManager.CreateInstance();
        if (SenseManager == null)
        {
            Debug.LogError("Initialization of the SenseManager has failed");
        }

        /* Enable hand tracking and get an instance of an hand module */
        Status     = SenseManager.EnableHand();
        HandModule = SenseManager.QueryHand();
        if (Status != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("SenseManager --> EnableHand " + Status);
        }

        /* Create the connection to the Intel RealSense camera */
        Status = SenseManager.Init();
        if (Status != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("Initialization of SenseManager: " + Status);
        }



        /* Settings for the hand module */
        PXCMHandConfiguration HandConfig = HandModule.CreateActiveConfiguration();

        if (HandConfig != null)
        {
            HandConfig.EnableAllGestures();
            HandConfig.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_NOT_DETECTED);

            PXCMHandData.JointType st = PXCMHandData.JointType.JOINT_WRIST;
            for (int i = 0; i < NumOfJoints; i++)
            {
                HandConfig.EnableJointSpeed(st, PXCMHandData.JointSpeedType.JOINT_SPEED_AVERAGE, 1000 / 10);
                st++;
            }

            //HandConfig.EnableJointSpeed(PXCMHandData.JointType.JOINT_WRIST, PXCMHandData.JointSpeedType.JOINT_SPEED_ABSOLUTE,1000/20);
            HandConfig.ApplyChanges();
            HandConfig.Dispose();
        }
    }
예제 #8
0
    private Hashtable handList;                            //keep track of bodyside and hands for GUItext

    // Use this for initialization
    void Start()
    {
        handList = new Hashtable();

        /* Initialize a PXCMSenseManager instance */
        sm = PXCMSenseManager.CreateInstance();
        if (sm == null)
        {
            Debug.LogError("SenseManager Initialization Failed");
        }

        /* Enable hand tracking and retrieve an hand module instance to configure */
        sts          = sm.EnableHand();
        handAnalyzer = sm.QueryHand();
        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("PXCSenseManager.EnableHand: " + sts);
        }

        /* Initialize the execution pipeline */
        sts = sm.Init();
        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("PXCSenseManager.Init: " + sts);
        }

        /* Retrieve the the DataSmoothing instance */
        sm.QuerySession().CreateImpl <PXCMSmoother>(out smoother);

        /* Create a 3D Weighted algorithm */
        smoother3D = new PXCMSmoother.Smoother3D[MaxHands, MaxJoints];

        /* Configure a hand - Enable Gestures and Alerts */
        PXCMHandConfiguration hcfg = handAnalyzer.CreateActiveConfiguration();

        if (hcfg != null)
        {
            hcfg.EnableAllGestures();
            hcfg.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_NOT_DETECTED);
            hcfg.ApplyChanges();
            hcfg.Dispose();
        }

        myJoints = new Joint[MaxHands, MaxJoints];

        Joint[] joints;
        if (RightHand != null)
        {
            HandMapping RightMapping = RightHand.GetComponent <HandMapping>();
            joints = RightMapping.GetJoints();
            for (int j = 0; j < MaxJoints; j++)
            {
                myJoints[0, j] = joints[j];
            }
        }

        if (LeftHand != null)
        {
            HandMapping LeftMapping = LeftHand.GetComponent <HandMapping>();
            joints = LeftMapping.GetJoints();
            for (int j = 0; j < MaxJoints; j++)
            {
                myJoints[1, j] = joints[j];
            }
        }

        jointData = new PXCMHandData.JointData[MaxHands, MaxJoints];

        for (int i = 0; i < MaxHands; i++)
        {
            for (int j = 0; j < MaxJoints; j++)
            {
                Joint joint = myJoints[i, j];
                if (joint != null)
                {
                    joint.originalPosition = joint.transform.position;
                    joint.originalRotation = joint.transform.rotation;

                    //Calculate orientation
                    Vector3 v          = Vector3.zero;
                    Vector3 parent     = joint.transform.position;
                    int     childcount = 0;

                    foreach (Joint.Neighbour n in joint.neighbours)
                    {
                        if (n.index < j)
                        {
                            parent = n.joint.transform.position;
                        }
                        else
                        {
                            v += n.joint.transform.position;
                            childcount++;
                        }
                    }
                    Vector3 direction = v - parent * childcount;
                    joint.originalOrientation = direction + parent - joint.transform.position;

                    //Joint extensions
                    foreach (Joint e in joint.extensions)
                    {
                        e.originalPosition    = e.transform.position;
                        e.originalRotation    = e.transform.rotation;
                        e.originalOrientation = joint.transform.position - e.transform.position;
                    }
                }

                smoother3D[i, j] = smoother.Create3DWeighted(smoothing);
                jointData[i, j]  = new PXCMHandData.JointData();

                //Test output to check Hand Mapping
                if (myJoints[i, j] == null)
                {
                    Debug.Log("null");
                }
                else
                {
                    Debug.Log(myJoints[i, j].transform.name);
                }
            }
        }
    }
예제 #9
0
        void OnEnable()
        {
            Initialized = false;

            /* Create a SenseManager instance */
            SenseManager = PXCMSenseManager.CreateInstance();

            if (SenseManager == null)
            {
                print("Unable to create the pipeline instance");
                return;
            }

            if (_speechCommandsRef.Count != 0)
            {
                SetSenseOption(SenseOption.SenseOptionID.Speech);
            }

            int numberOfEnabledModalities = 0;

            //Set mode according to RunMode - play from file / record / live stream
            if (RunMode == MCTTypes.RunModes.PlayFromFile)
            {
                //CHECK IF FILE EXISTS
                if (!System.IO.File.Exists(FilePath))
                {
                    Debug.LogWarning("No Filepath Set Or File Doesn't Exist, Run Mode Will Be Changed to Live Stream");
                    RunMode = MCTTypes.RunModes.LiveStream;
                }
                else
                {
                    PXCMCaptureManager cManager = SenseManager.QueryCaptureManager();
                    cManager.SetFileName(FilePath, false);
                    Debug.Log("SenseToolkitManager: Playing from file: " + FilePath);
                }
            }

            if (RunMode == MCTTypes.RunModes.RecordToFile)
            {
                //CHECK IF PATH
                string PathOnly = FilePath;
                while (!PathOnly[PathOnly.Length - 1].Equals('\\'))
                {
                    PathOnly = PathOnly.Remove(PathOnly.Length - 1, 1);
                }

                if (!System.IO.Directory.Exists(PathOnly))
                {
                    Debug.LogWarning("No Filepath Set Or Path Doesn't Exist, Run Mode Will Be Changed to Live Stream");
                    RunMode = MCTTypes.RunModes.LiveStream;
                }
                else
                {
                    PXCMCaptureManager cManager = SenseManager.QueryCaptureManager();
                    cManager.SetFileName(FilePath, true);
                    Debug.Log("SenseToolkitManager: Recording to file: " + FilePath);
                }
            }

            /* Enable modalities according to the set options*/
            if (IsSenseOptionSet(SenseOption.SenseOptionID.Face, true))
            {
                SenseManager.EnableFace();
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Face).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Face).Enabled     = true;
                SetSenseOption(SenseOption.SenseOptionID.VideoColorStream);
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Hand, true))
            {
                _sts = SenseManager.EnableHand();
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Hand).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Hand).Enabled     = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Object, true))
            {
                _sts = SenseManager.EnableTracker();
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Object).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Object).Enabled     = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Speech, true))
            {
                if (!SpeechManager.IsInitialized)
                {
                    if (SpeechManager.InitalizeSpeech())
                    {
                        _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Speech).Initialized = true;
                        _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Speech).Enabled     = true;
                        numberOfEnabledModalities++;
                    }
                    else
                    {
                        UnsetSenseOption(SenseOption.SenseOptionID.Speech);
                    }
                }
                else
                {
                    _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Speech).Initialized = true;
                    _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Speech).Enabled     = true;
                    numberOfEnabledModalities++;
                }
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.VideoDepthStream, true))
            {
                SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 0, 0, 0);
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoDepthStream).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoDepthStream).Enabled     = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.VideoIRStream, true))
            {
                SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_IR, 0, 0, 0);
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoIRStream).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoIRStream).Enabled     = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.VideoColorStream, true))
            {
                //SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 960, 540, 0);
                SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 480, 0);
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoColorStream).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoColorStream).Enabled     = true;
                numberOfEnabledModalities++;
            }


            /* Initialize the execution */
            _sts = SenseManager.Init();
            if (_sts < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                if (numberOfEnabledModalities > 0)
                {
                    print("Unable to initialize all modalities");
                }
                return;
            }
            //Set different configurations:

            //SenseManager.QueryCaptureManager().device.SetMirrorMode(PXCMCapture.Device.MirrorMode.MIRROR_MODE_DISABLED);

            // Face
            if (IsSenseOptionSet(SenseOption.SenseOptionID.Face, true))
            {
                var faceModule        = SenseManager.QueryFace();
                var faceConfiguration = faceModule.CreateActiveConfiguration();
                if (faceConfiguration == null)
                {
                    throw new UnityException("CreateActiveConfiguration returned null");
                }

                faceConfiguration.Update();

                faceConfiguration.detection.isEnabled      = true;
                faceConfiguration.detection.smoothingLevel = PXCMFaceConfiguration.SmoothingLevelType.SMOOTHING_DISABLED;

                faceConfiguration.landmarks.isEnabled      = true;
                faceConfiguration.landmarks.smoothingLevel = PXCMFaceConfiguration.SmoothingLevelType.SMOOTHING_DISABLED;

                faceConfiguration.pose.isEnabled      = true;
                faceConfiguration.pose.smoothingLevel = PXCMFaceConfiguration.SmoothingLevelType.SMOOTHING_DISABLED;

                faceConfiguration.DisableAllAlerts();

                faceConfiguration.strategy = PXCMFaceConfiguration.TrackingStrategyType.STRATEGY_APPEARANCE_TIME;

                faceConfiguration.detection.maxTrackedFaces = NumberOfDetectedFaces;
                faceConfiguration.landmarks.maxTrackedFaces = NumberOfDetectedFaces;
                faceConfiguration.pose.maxTrackedFaces      = NumberOfDetectedFaces;

                PXCMFaceConfiguration.ExpressionsConfiguration expressionConfig = faceConfiguration.QueryExpressions();
                expressionConfig.Enable();
                expressionConfig.EnableAllExpressions();


                faceConfiguration.ApplyChanges();
                faceConfiguration.Dispose();

                FaceModuleOutput = faceModule.CreateOutput();

                UnsetSenseOption(SenseOption.SenseOptionID.VideoColorStream);
            }

            // Hand
            if (IsSenseOptionSet(SenseOption.SenseOptionID.Hand, true))
            {
                PXCMHandModule handAnalysis = SenseManager.QueryHand();

                PXCMHandConfiguration handConfiguration = handAnalysis.CreateActiveConfiguration();
                if (handConfiguration == null)
                {
                    throw new UnityException("CreateActiveConfiguration returned null");
                }

                handConfiguration.Update();
                handConfiguration.EnableAllGestures();
                handConfiguration.EnableAllAlerts();
                handConfiguration.EnableSegmentationImage(true);
                handConfiguration.ApplyChanges();
                handConfiguration.Dispose();

                HandDataOutput = handAnalysis.CreateOutput();
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Object, true))
            {
                if (_senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Object).Enabled != true)
                {
                    _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Object).Enabled = true;
                    OnDisable();
                    OnEnable();
                    Start();
                }
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Speech, true))
            {
                UpdateSpeechCommands();
                SpeechManager.Start();
            }

            // Create an instance for the projection
            if (_projection == null)
            {
                _projection = SenseManager.QueryCaptureManager().QueryDevice().CreateProjection();
            }

            // Set initialization flag
            Initialized = true;
        }