예제 #1
0
        // ジェスチャーが選択されたときに呼ばれるイベント
        private void ComboGesture_SelectionChanged(object sender,
                                                   SelectionChangedEventArgs e)
        {
            var index = ComboGesture.SelectedIndex;

            if (index == -1)
            {
                return;
            }

            // 選択されたインデックスのジェスチャー名を取得する
            string gestureName;
            var    sts = handConfig.QueryGestureNameByIndex(index, out gestureName);

            if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                return;
            }

            // 一度すべてのジェスチャーを切り、選択されたジェスチャーを有効にする
            handConfig.DisableAllGestures();
            handConfig.EnableGesture(gestureName, true);

            handConfig.ApplyChanges();

            // ジェスチャーの検出数を初期化する
            leftGestureCount = rightGestureCount = 0;
        }
예제 #2
0
        // 手の検出の初期化
        private void InitializeHandTracking()
        {
            // 手の検出器を取得する
            handAnalyzer = senseManager.QueryHand();
            if (handAnalyzer == null)
            {
                throw new Exception("手の検出器の取得に失敗しました");
            }

            // 手のデータを作成する
            handData = handAnalyzer.CreateOutput();
            if (handData == null)
            {
                throw new Exception("手の検出器の作成に失敗しました");
            }

            // RealSense カメラであれば、プロパティを設定する
            var device = senseManager.QueryCaptureManager().QueryDevice();

            PXCMCapture.DeviceInfo dinfo;
            device.QueryDeviceInfo(out dinfo);
            if (dinfo.model == PXCMCapture.DeviceModel.DEVICE_MODEL_IVCAM)
            {
                device.SetDepthConfidenceThreshold(1);
                //device.SetMirrorMode( PXCMCapture.Device.MirrorMode.MIRROR_MODE_DISABLED );
                device.SetIVCAMFilterOption(6);
            }

            // 手の検出の設定
            handConfig = handAnalyzer.CreateActiveConfiguration();

            // 登録されているジェスチャーを列挙する
            var num = handConfig.QueryGesturesTotalNumber();

            for (int i = 0; i < num; i++)
            {
                string gestureName;
                var    sts = handConfig.QueryGestureNameByIndex(i, out gestureName);
                if (sts == pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    ComboGesture.Items.Add(gestureName);
                }
            }

            handConfig.ApplyChanges();
            handConfig.Update();
        }
예제 #3
0
        public void HandPipeLine()
        {
            PXCMSenseManager pp = m_form.Session.CreateSenseManager();

            if (pp == null)
            {
                throw new Exception("PXCMSenseManager null");
            }

            pp.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 360);

            //手 初始化
            PXCMHandModule handAnalysis;

            PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler();
            handler.onModuleProcessedFrame = new PXCMSenseManager.Handler.OnModuleProcessedFrameDelegate(OnNewFrame);
            PXCMHandConfiguration handConfiguration = null;
            PXCMHandData          handData          = null;


            pxcmStatus status = pp.EnableHand();

            handAnalysis = pp.QueryHand();

            if (status != pxcmStatus.PXCM_STATUS_NO_ERROR || handAnalysis == null)
            {
                Console.WriteLine("hand module load failed");
                return;
            }
            handConfiguration = handAnalysis.CreateActiveConfiguration();
            if (handConfiguration == null)
            {
                Console.WriteLine("Failed Create Configuration");
                return;
            }
            handData = handAnalysis.CreateOutput();
            if (handData == null)
            {
                Console.WriteLine("Failed Create Output");
                return;
            }

            if (pp.Init(handler) != pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                Console.WriteLine("init failed");
                return;
            }

            if (handConfiguration != null)
            {
                PXCMHandData.TrackingModeType trackingMode = PXCMHandData.TrackingModeType.TRACKING_MODE_FULL_HAND;

                // 配置收的Tracking Mode
                trackingMode = PXCMHandData.TrackingModeType.TRACKING_MODE_FULL_HAND;

                handConfiguration.SetTrackingMode(trackingMode);

                handConfiguration.EnableAllAlerts();
                handConfiguration.EnableSegmentationImage(true);
                bool isEnabled = handConfiguration.IsSegmentationImageEnabled();

                handConfiguration.ApplyChanges();

                int totalNumOfGestures = handConfiguration.QueryGesturesTotalNumber();

                if (totalNumOfGestures > 0)
                {
                    for (int i = 0; i < totalNumOfGestures; i++)
                    {
                        string gestureName = string.Empty;
                        if (handConfiguration.QueryGestureNameByIndex(i, out gestureName) ==
                            pxcmStatus.PXCM_STATUS_NO_ERROR)
                        {
                            Console.WriteLine(gestureName);
                        }
                    }
                }
            }


            int frameCounter = 0;
            int frameNumber  = 0;

            while (!m_form.Stopped)
            {
                string gestureName = "fist";
                if (handConfiguration != null)
                {
                    if (string.IsNullOrEmpty(gestureName) == false)
                    {
                        if (handConfiguration.IsGestureEnabled(gestureName) == false)
                        {
                            handConfiguration.DisableAllGestures();
                            handConfiguration.EnableGesture(gestureName, true);
                            handConfiguration.ApplyChanges();
                        }
                    }
                    else
                    {
                        handConfiguration.DisableAllGestures();
                        handConfiguration.ApplyChanges();
                    }
                }

                if (pp.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    break;
                }

                frameCounter++;

                if (pp.IsConnected())
                {
                    PXCMCapture.Sample sample;
                    sample = pp.QueryHandSample();
                    if (sample != null && sample.depth != null)
                    {
                        // frameNumber = liveCamera ? frameCounter : instance.captureManager.QueryFrameIndex();
                        frameNumber = frameCounter;
                    }
                    //bool b=(sample.ir==null);
                    //b = (sample.color== null);
                    //b = (sample.left == null);
                    //b = (sample.right == null);
                    DisplayPicture(sample.depth);

                    if (handData != null)
                    {
                        handData.Update();

                        SaveHandData(handData);
                    }
                    m_form.UpdatePic();
                }
                pp.ReleaseFrame();
            }

            if (handData != null)
            {
                handData.Dispose();
            }
            if (handConfiguration != null)
            {
                handConfiguration.Dispose();
            }

            pp.Close();
            pp.Dispose();
        }
예제 #4
0
        /* Using PXCMSenseManager to handle data */
        public void SimplePipeline()
        {
            form.UpdateInfo(String.Empty, Color.Black);
            bool liveCamera = false;

            bool             flag     = true;
            PXCMSenseManager instance = null;

            _disconnected = false;
            instance      = form.g_session.CreateSenseManager();
            if (instance == null)
            {
                form.UpdateStatus("Failed creating SenseManager");
                return;
            }

            if (form.GetRecordState())
            {
                instance.captureManager.SetFileName(form.GetFileName(), true);
                PXCMCapture.DeviceInfo info;
                if (form.Devices.TryGetValue(form.GetCheckedDevice(), out info))
                {
                    instance.captureManager.FilterByDeviceInfo(info);
                }
            }
            else if (form.GetPlaybackState())
            {
                instance.captureManager.SetFileName(form.GetFileName(), false);
                instance.captureManager.SetRealtime(false);
            }
            else
            {
                PXCMCapture.DeviceInfo info;
                if (String.IsNullOrEmpty(form.GetCheckedDevice()))
                {
                    form.UpdateStatus("Device Failure");
                    return;
                }

                if (form.Devices.TryGetValue(form.GetCheckedDevice(), out info))
                {
                    instance.captureManager.FilterByDeviceInfo(info);
                }

                liveCamera = true;
            }
            /* Set Module */
            pxcmStatus     status       = instance.EnableHand(form.GetCheckedModule());
            PXCMHandModule handAnalysis = instance.QueryHand();

            if (status != pxcmStatus.PXCM_STATUS_NO_ERROR || handAnalysis == null)
            {
                form.UpdateStatus("Failed Loading Module");
                return;
            }

            PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler();
            handler.onModuleProcessedFrame = new PXCMSenseManager.Handler.OnModuleProcessedFrameDelegate(OnNewFrame);


            PXCMHandConfiguration handConfiguration = handAnalysis.CreateActiveConfiguration();
            PXCMHandData          handData          = handAnalysis.CreateOutput();

            if (handConfiguration == null)
            {
                form.UpdateStatus("Failed Create Configuration");
                return;
            }
            if (handData == null)
            {
                form.UpdateStatus("Failed Create Output");
                return;
            }

            if (form.getInitGesturesFirstTime() == false)
            {
                int totalNumOfGestures = handConfiguration.QueryGesturesTotalNumber();
                if (totalNumOfGestures > 0)
                {
                    this.form.UpdateGesturesToList("", 0);
                    for (int i = 0; i < totalNumOfGestures; i++)
                    {
                        string gestureName = string.Empty;
                        if (handConfiguration.QueryGestureNameByIndex(i, out gestureName) ==
                            pxcmStatus.PXCM_STATUS_NO_ERROR)
                        {
                            this.form.UpdateGesturesToList(gestureName, i + 1);
                        }
                    }
                    form.setInitGesturesFirstTime(true);
                    form.UpdateGesturesListSize();
                }
            }


            FPSTimer timer = new FPSTimer(form);

            form.UpdateStatus("Init Started");
            if (handAnalysis != null && instance.Init(handler) == pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                PXCMCapture.DeviceInfo dinfo;

                PXCMCapture.Device device = instance.captureManager.device;
                if (device != null)
                {
                    pxcmStatus result = device.QueryDeviceInfo(out dinfo);
                    if (result == pxcmStatus.PXCM_STATUS_NO_ERROR && dinfo != null && dinfo.model == PXCMCapture.DeviceModel.DEVICE_MODEL_IVCAM)
                    {
                        device.SetDepthConfidenceThreshold(1);
                        device.SetMirrorMode(PXCMCapture.Device.MirrorMode.MIRROR_MODE_DISABLED);
                        device.SetIVCAMFilterOption(6);
                    }

                    _maxRange = device.QueryDepthSensorRange().max;
                }


                if (handConfiguration != null)
                {
                    handConfiguration.EnableAllAlerts();
                    handConfiguration.EnableSegmentationImage(true);

                    handConfiguration.ApplyChanges();
                    handConfiguration.Update();
                }

                form.UpdateStatus("Streaming");
                int    frameCounter = 0;
                int    frameNumber = 0;
                string nextPageGesture, previousPageGesture, firstPageGesture, endPageGesture;
                HandsRecognition.Hand nextHand, previousHand, firstHand, endHand;

                while (!form.stop)
                {
                    form.GetHandType(out nextHand, out previousHand, out firstHand, out endHand);
                    form.GetGestureName(out nextPageGesture, out previousPageGesture, out firstPageGesture, out endPageGesture);
                    handConfiguration.DisableAllGestures();
                    if (string.IsNullOrEmpty(nextPageGesture) == false && handConfiguration.IsGestureEnabled(nextPageGesture) == false)
                    {
                        handConfiguration.EnableGesture(nextPageGesture, true);
                        NextPageGesture.Gesture  = nextPageGesture;
                        NextPageGesture.handler  = form.NextPage;
                        NextPageGesture.HandType = nextHand;
                    }
                    if (string.IsNullOrEmpty(previousPageGesture) == false && handConfiguration.IsGestureEnabled(previousPageGesture) == false)
                    {
                        handConfiguration.EnableGesture(previousPageGesture, true);
                        PreviousPageGesture.Gesture  = previousPageGesture;
                        PreviousPageGesture.handler  = form.PreviousPage;
                        PreviousPageGesture.HandType = previousHand;
                    }
                    if (string.IsNullOrEmpty(firstPageGesture) == false && handConfiguration.IsGestureEnabled(firstPageGesture) == false)
                    {
                        handConfiguration.EnableGesture(firstPageGesture, true);
                        FirstPageGesture.Gesture  = firstPageGesture;
                        FirstPageGesture.handler  = form.FirstPage;
                        FirstPageGesture.HandType = firstHand;
                    }
                    if (string.IsNullOrEmpty(endPageGesture) == false && handConfiguration.IsGestureEnabled(endPageGesture) == false)
                    {
                        handConfiguration.EnableGesture(endPageGesture, true);
                        EndPageGesture.Gesture  = endPageGesture;
                        EndPageGesture.handler  = form.EndPage;
                        EndPageGesture.HandType = endHand;
                    }
                    handConfiguration.ApplyChanges();
                    if (instance.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        break;
                    }

                    frameCounter++;

                    if (!DisplayDeviceConnection(!instance.IsConnected()))
                    {
                        if (handData != null)
                        {
                            handData.Update();
                        }

                        PXCMCapture.Sample sample = instance.QueryHandSample();
                        if (sample != null && sample.depth != null)
                        {
                            DisplayPicture(sample.depth, handData);

                            if (handData != null)
                            {
                                frameNumber = liveCamera ? frameCounter : instance.captureManager.QueryFrameIndex();

                                DisplayJoints(handData);
                                DisplayGesture(handData, frameNumber);
                                DisplayAlerts(handData, frameNumber);
                            }
                            form.UpdatePanel();
                        }
                        timer.Tick();
                    }
                    instance.ReleaseFrame();
                }

                // Clean Up
                if (handData != null)
                {
                    handData.Dispose();
                }
                if (handConfiguration != null)
                {
                    handConfiguration.Dispose();
                }
            }
            else
            {
                form.UpdateStatus("Init Failed");
                flag = false;
            }
            foreach (PXCMImage pxcmImage in m_images)
            {
                pxcmImage.Dispose();
            }



            instance.Close();
            instance.Dispose();
            if (flag)
            {
                form.UpdateStatus("Stopped");
            }
        }
        // 手の検出の初期化
        private void InitializeHandTracking()
        {
            // 手の検出器を取得する
            handAnalyzer = senseManager.QueryHand();
            if ( handAnalyzer == null ) {
                throw new Exception( "手の検出器の取得に失敗しました" );
            }

            // 手のデータを作成する
            handData = handAnalyzer.CreateOutput();
            if ( handData == null ) {
                throw new Exception( "手の検出器の作成に失敗しました" );
            }

            // RealSense カメラであれば、プロパティを設定する
            var device = senseManager.QueryCaptureManager().QueryDevice();
            PXCMCapture.DeviceInfo dinfo;
            device.QueryDeviceInfo( out dinfo );
            if ( dinfo.model == PXCMCapture.DeviceModel.DEVICE_MODEL_IVCAM ) {
                device.SetDepthConfidenceThreshold( 1 );
                //device.SetMirrorMode( PXCMCapture.Device.MirrorMode.MIRROR_MODE_DISABLED );
                device.SetIVCAMFilterOption( 6 );
            }

            // 手の検出の設定
            handConfig = handAnalyzer.CreateActiveConfiguration();

            // 登録されているジェスチャーを列挙する
            var num = handConfig.QueryGesturesTotalNumber();
            for ( int i = 0; i < num; i++ ){
                string gestureName;
                var sts = handConfig.QueryGestureNameByIndex( i, out gestureName );
                if ( sts == pxcmStatus.PXCM_STATUS_NO_ERROR ){
                    ComboGesture.Items.Add( gestureName  );
                }
            }

            handConfig.ApplyChanges();
            handConfig.Update();
        }
예제 #6
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();
        }