// ジェスチャーが選択されたときに呼ばれるイベント 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; }
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(); }
/* 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"); } }