Software Archive
Read-only legacy content
17061 Discussions

Console Application / Depth data

Yiannis_C_
Beginner
554 Views

Hello, 

really fresh to c# and realsense. Basically what i am trying to do is just print to console the number of hands detected by the depth camera stream, but apparently i am understanding something wrongly from the documentation.  Any insight as to why the code below always returns 0 hands in the output?

thnx!

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{

    class Program
    {
        static void Main(string[] args)
        {
            // Create a PXCMSenseManager instance
            PXCMSenseManager sm = PXCMSenseManager.CreateInstance();

            // Enable a video stream
            sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 640, 480, 0);

            // Initialize the processing pipeline
            sm.Init();

            //Acquire one frame
            pxcmStatus frame = sm.AcquireFrame(true);

            PXCMCapture.Sample test = sm.QuerySample();

            // Enable hand tracking/analysis
            sm.EnableHand();

            // Get the hand module instance
            PXCMHandModule handModule = sm.QueryHand();

            // Create the hand data instance
            PXCMHandData handData = handModule.CreateOutput();

            while (sm.AcquireFrame(true) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                handData.Update();
                PXCMHandData.IHand ihand;
                handData.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_ID, 2, out ihand);
                int no_of_hands = handData.QueryNumberOfHands();
                Console.WriteLine(no_of_hands.ToString());
            }

            sm.Close();
            sm.Dispose();
        }
    }
}

 

0 Kudos
2 Replies
MartyG
Honored Contributor III
554 Views

Initial disclaimer: my experience is based around using RealSense's library files with the Unity game engine rather than a C# editor program.  Hopefully the same principles should still apply though.

The first thing I would suggest is to make sure that both of your hands are held up to the camera with the palms facing towards it.  The camera cannot detect the hands when they are not held up (e.g if you have them on your lap or on top of the keyboard).  Once the camera sees the palms then its 'Hands Detected' condition is triggered.

Secondly, RealSense does not label the hands as 1 and 2.  Rather unusually, it calls them 0 and 1 instead.  So if your console is saying there are '0' hands, it could actually mean it has detected the hand tha tis labeled '0'.  :)

Finally, reading through your script, I see that it uses the detection type 'Access Order By ID'.  This is not ideal for detecting both hands at the same time, as it tends to ignore one of the hands unless you move it further forward so that it is in front of the other hand.  'Access Order Fixed', in my personal experience, works better for tracking both hands simultaneously.

Good luck!

0 Kudos
Yiannis_C_
Beginner
554 Views

Thank you for the reply, 
apparently what was missing was just a release frame in the while loop.

 

cheers o/

0 Kudos
Reply