Beispiel #1
0
        public static void start(IoT_RealSense_Surfing frm)
        {
            keepLooping = true;
            iot_form = frm;
            InitializeMqqtClient();
            PXCMSession session = PXCMSession.CreateInstance();
            // Querying the SDK version
            Console.WriteLine(frm.comboTarget.SelectedText);
            if (session != null)
            {
                // Optional steps to send feedback to Intel Corporation to understand how often each SDK sample is used.
                PXCMMetadata md = session.QueryInstance<PXCMMetadata>();
                if (md != null)
                {
                    string sample_name = "Emotion Viewer CS";
                    md.AttachBuffer(1297303632, System.Text.Encoding.Unicode.GetBytes(sample_name));
                }
                //Application.Run(new MainForm(session));
                //session.Dispose();
            }
            //PXCMSession.ImplVersion version = session.QueryVersion();
            //Console.WriteLine("RealSense SDK Version {0}.{1}", version.major, version.minor);

            session.CreateImpl<PXCMRotation>(out rotationHelper);

            // Creating the SenseManager
            PXCMSenseManager senseManager = session.CreateSenseManager();
            if (senseManager == null)
            {
                Console.WriteLine("Failed to create the SenseManager object.");
                return;
            }

            // Enabling Emotion Module
            pxcmStatus enablingModuleStatus = senseManager.EnableEmotion();
            if (enablingModuleStatus != pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                Console.WriteLine("Failed to enable the Emotion Module");
                return;
            }

            // Getting the instance of the Emotion Module
            PXCMEmotion emotionModule = senseManager.QueryEmotion();
            if (emotionModule == null)
            {
                Console.WriteLine("Failed to query the emotion module");
                return;
            }

            // Initializing the camera
            if (senseManager.Init() < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                Console.WriteLine("Failed to initialize the SenseManager");
                return;
            }

            // Enabling the Hand module
            pxcmStatus enablingModuleStatus1 = senseManager.EnableHand("Hand Module");
            if (enablingModuleStatus1 != pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                Console.WriteLine("Failed to enable the Hand Module");
                return;
            }

            // Getting the instance of the Hand Module
            PXCMHandModule handModule = senseManager.QueryHand();
            if (handModule == null)
            {
                Console.WriteLine("Failed to get the HandModule object.");
                return;
            }

            // Creating an active configuration
            PXCMHandConfiguration handConfiguration = handModule.CreateActiveConfiguration();
            if (handConfiguration == null)
            {
                Console.WriteLine("Failed to create the HandConfiguration object.");
                return;
            }

            // Listing the available gestures
            int supportedGesturesCount = handConfiguration.QueryGesturesTotalNumber();
            if (supportedGesturesCount > 0)
            {
                Console.WriteLine("Supported gestures:");
                for (int i = 0; i < supportedGesturesCount; i++)
                {
                    string gestureName = string.Empty;

                    if (handConfiguration.QueryGestureNameByIndex(i, out gestureName) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        Console.WriteLine("\t" + gestureName);
                    }
                }
            }

            // Enabling some gestures
            String[] enabledGestures = { GESTURE_CLICK, GESTURE_VSIGN, GESTURE_FIST, GESTURE_SPREADFINGERS };
            foreach (String gesture in enabledGestures)
            {
                if (!handConfiguration.IsGestureEnabled(gesture))
                {
                    handConfiguration.EnableGesture(gesture);
                }
            }
            handConfiguration.ApplyChanges();

            // Creating a data output object
            PXCMHandData handData = handModule.CreateOutput();
            if (handData == null)
            {
                Console.WriteLine("Failed to create the HandData object.");
                return;
            }

            // Initializing the SenseManager
            if (senseManager.Init() != pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                Console.WriteLine(senseManager.Init());
                return;
            }

            // Looping to query the hands information
            while (keepLooping)
            {
                // Acquiring a frame
                if (senseManager.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    break;
                }

                // Updating the hand data
                if (handData != null)
                {
                    handData.Update();
                }
                //ProcessHands(handData);
                ProcessGestures(handData);
                ProcessEmotions(emotionModule);
                // Releasing the acquired frame
                senseManager.ReleaseFrame();

                /* using another frame to process different stuff? may be...
                // Acquiring a frame
                if (senseManager.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    break;
                }

                // Processing Emotions
                ProcessEmotions(emotionModule);

                // Releasing the acquired frame
                senseManager.ReleaseFrame();*/

            }

            // Releasing resources
            if (handData != null) handData.Dispose();
            if (handConfiguration != null) handConfiguration.Dispose();
            rotationHelper.Dispose();

            senseManager.Close();
            senseManager.Dispose();
            session.Dispose();
            client.Disconnect();
        }
Beispiel #2
0
        public static void start(IoT_RealSense_Surfing frm)
        {
            keepLooping = true;
            iot_form    = frm;
            InitializeMqqtClient();
            PXCMSession session = PXCMSession.CreateInstance();

            // Querying the SDK version
            Console.WriteLine(frm.comboTarget.SelectedText);
            if (session != null)
            {
                // Optional steps to send feedback to Intel Corporation to understand how often each SDK sample is used.
                PXCMMetadata md = session.QueryInstance <PXCMMetadata>();
                if (md != null)
                {
                    string sample_name = "Emotion Viewer CS";
                    md.AttachBuffer(1297303632, System.Text.Encoding.Unicode.GetBytes(sample_name));
                }
                //Application.Run(new MainForm(session));
                //session.Dispose();
            }
            //PXCMSession.ImplVersion version = session.QueryVersion();
            //Console.WriteLine("RealSense SDK Version {0}.{1}", version.major, version.minor);

            session.CreateImpl <PXCMRotation>(out rotationHelper);

            // Creating the SenseManager
            PXCMSenseManager senseManager = session.CreateSenseManager();

            if (senseManager == null)
            {
                Console.WriteLine("Failed to create the SenseManager object.");
                return;
            }

            // Enabling Emotion Module
            pxcmStatus enablingModuleStatus = senseManager.EnableEmotion();

            if (enablingModuleStatus != pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                Console.WriteLine("Failed to enable the Emotion Module");
                return;
            }

            // Getting the instance of the Emotion Module
            PXCMEmotion emotionModule = senseManager.QueryEmotion();

            if (emotionModule == null)
            {
                Console.WriteLine("Failed to query the emotion module");
                return;
            }

            // Initializing the camera
            if (senseManager.Init() < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                Console.WriteLine("Failed to initialize the SenseManager");
                return;
            }

            // Enabling the Hand module
            pxcmStatus enablingModuleStatus1 = senseManager.EnableHand("Hand Module");

            if (enablingModuleStatus1 != pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                Console.WriteLine("Failed to enable the Hand Module");
                return;
            }

            // Getting the instance of the Hand Module
            PXCMHandModule handModule = senseManager.QueryHand();

            if (handModule == null)
            {
                Console.WriteLine("Failed to get the HandModule object.");
                return;
            }

            // Creating an active configuration
            PXCMHandConfiguration handConfiguration = handModule.CreateActiveConfiguration();

            if (handConfiguration == null)
            {
                Console.WriteLine("Failed to create the HandConfiguration object.");
                return;
            }

            // Listing the available gestures
            int supportedGesturesCount = handConfiguration.QueryGesturesTotalNumber();

            if (supportedGesturesCount > 0)
            {
                Console.WriteLine("Supported gestures:");
                for (int i = 0; i < supportedGesturesCount; i++)
                {
                    string gestureName = string.Empty;

                    if (handConfiguration.QueryGestureNameByIndex(i, out gestureName) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        Console.WriteLine("\t" + gestureName);
                    }
                }
            }

            // Enabling some gestures
            String[] enabledGestures = { GESTURE_CLICK, GESTURE_VSIGN, GESTURE_FIST, GESTURE_SPREADFINGERS };
            foreach (String gesture in enabledGestures)
            {
                if (!handConfiguration.IsGestureEnabled(gesture))
                {
                    handConfiguration.EnableGesture(gesture);
                }
            }
            handConfiguration.ApplyChanges();

            // Creating a data output object
            PXCMHandData handData = handModule.CreateOutput();

            if (handData == null)
            {
                Console.WriteLine("Failed to create the HandData object.");
                return;
            }

            // Initializing the SenseManager
            if (senseManager.Init() != pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                Console.WriteLine(senseManager.Init());
                return;
            }

            // Looping to query the hands information
            while (keepLooping)
            {
                // Acquiring a frame
                if (senseManager.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    break;
                }

                // Updating the hand data
                if (handData != null)
                {
                    handData.Update();
                }
                //ProcessHands(handData);
                ProcessGestures(handData);
                ProcessEmotions(emotionModule);
                // Releasing the acquired frame
                senseManager.ReleaseFrame();

                /* using another frame to process different stuff? may be...
                 * // Acquiring a frame
                 * if (senseManager.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                 * {
                 *  break;
                 * }
                 *
                 * // Processing Emotions
                 * ProcessEmotions(emotionModule);
                 *
                 * // Releasing the acquired frame
                 * senseManager.ReleaseFrame();*/
            }


            // Releasing resources
            if (handData != null)
            {
                handData.Dispose();
            }
            if (handConfiguration != null)
            {
                handConfiguration.Dispose();
            }
            rotationHelper.Dispose();

            senseManager.Close();
            senseManager.Dispose();
            session.Dispose();
            client.Disconnect();
        }