1 Reply Latest reply on Feb 2, 2017 4:49 AM by MartyG

    [SR300] Can't reconize the gestures


      This is an Unity program that aim to send a debug message when thumb up is detected.


      This is my code: the problem is that QueryFiredGesturesNumber() is igual to 0 all the time.


          void Start () {
              /* Initialize a PXCMSenseManager instance */
              psm = PXCMSenseManager.CreateInstance();
              if (psm == null)
                  Debug.LogError("SenseManager Initialization Failed");
              sts = psm.EnableHand();
              if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR) Debug.LogError("PXCSenseManager.EnableHand: " + sts);
              /* Retrieve an instance of hand to configure */
              handAnalyzer = psm.QueryHand();
              if (handAnalyzer == null) Debug.LogError("PXCSenseManager.QueryHand");
              /* Initialize the execution pipeline */
              sts = psm.Init();
              if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
                  Debug.LogError("PXCMSenseManager.Init Failed");
                  OnDisable(); // Clean-up
          private void OnDisable()
              if (psm == null)
        void Update () {
              if (psm == null) return;
              /* Wait until any frame data is available true(aligned) false(unaligned) */
              if (psm.AcquireFrame(false, 0) != pxcmStatus.PXCM_STATUS_NO_ERROR) return;
              /* Retrieve am instance of hand tracking Module */
              handAnalyzer = psm.QueryHand();
              if (handAnalyzer != null)
                  /* Retrieve an instance of hand tracking Data */
                  PXCMHandData _outputData = handAnalyzer.CreateOutput();
                  if (_outputData != null)
                      PXCMHandData.GestureData _gestureData;
                      //Debug.Log("Hand:" + _outputData.QueryNumberOfHands() + " " + _outputData.QueryFiredGesturesNumber());
                      for (int i = 0; i < _outputData.QueryFiredGesturesNumber(); i++)
                          if (_outputData.QueryFiredGestureData(i, out _gestureData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                              if (_outputData.IsGestureFired("thumb_up", out _gestureData))
              /* Realease the frame to process the next frame */
        • 1. Re: [SR300] Can't reconize the gestures

          Using this script is a complicated way to provide a feature that the SDK already makes easy in Unity via a script packaged in its Unity Toolkit application called SendMessageAction.


          Edit: this is only going to work if you are using the RealSense SDK '2016 R2', as the Unity Toolkit currently does not work in the newest R3 SDK.


          STEP ONE


          Once the Toolkit's files have been imported to your project, if you open the folder RSUnityToolkit > Actions then you will see a set of pre-made SDK scripts, including SendMessageAction.



          STEP TWO


          Drag and drop the SendMessageAction script into an object in your project.



          STEP THREE


          Left-click on 'Add Triger' (their spelling, not mine!) and select the 'Event Source' option.



          STEP FOUR


          A new section called Event Source is added to the component.  Left-click on the little arrow beside it to expand it open, and select the 'Gesture Detected' option from the drop-down menu.



          STEP FIVE


          Expand open the 'Gesture Detected' option and select 'Thumb Up' from the drop-down menu.



          STEP SIX


          Place your gesture script in the same object that the SendMessageAction component is in,  Un-tick the script so that it is dormant by default, as it does not need to be active in order for SendMessageAction to trigger it.


          STEP SEVEN


          Delete almost everything in the script and simply use the following script.


          public void LateUpdate() {


          // Print the message "thumb up" in the debug console.




          // Ensure that the script returns to a dormant state after the debug.log message has been triggered.


          this.enabled = false;




          STEP EIGHT


          Finally, put the name of the function containing the Debug.Log instruction into the 'Function Name' section of the SendMessageAction to tell it which function in your script it should jump to when the thumb-up gesture is detected.  Do not put the function brackets - () - after the name.





          BTW, you may be wondering why I used a LateUpdate type function instead of Update.  It is because SendMessageAction is unusual in that it does not look for a particular script name, but rather any script that has the name specified in Function Name in it.  So if you use LateUpdate, it ensures that SendMessageAction finds the correct script if you have other scripts inside that object that use the Update function.