public override bool OnNewFrame() { PXCMGesture gesture = QueryGesture(); PXCMGesture.GeoNode ndata; pxcmStatus sts = gesture.QueryNodeData(0, PXCMGesture.GeoNode.Label.LABEL_BODY_HAND_PRIMARY, out ndata); uint sx; uint sy; QueryImageSize(PXCMImage.ImageType.IMAGE_TYPE_DEPTH, out sx, out sy); xx = sx; yy = sy; if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) { Console.WriteLine("HAND_MIDDLE:" + ndata.positionImage.x.ToString() + "," + ndata.positionImage.y.ToString() + " Openess:" + ndata.openness.ToString()); } float x = ndata.positionImage.x; float y = ndata.positionImage.y; z = ndata.positionWorld.z; position = new Vector2(MyGraphics.screenRect.Width / 2 - (x / xx - 0.5f) * MyGraphics.screenRect.Width * 1.5f, MyGraphics.screenRect.Height / 2 + (y / yy - 0.5f) * MyGraphics.screenRect.Height * 1.5f); opennes = ndata.openness; openState = ndata.opennessState; //return (++nframes < 50000); return(start); }
void _tracker_OnOpenClose(PXCMGesture.GeoNode.Openness opennessState, uint openness) { //AddLog("[OpenState: " + opennessState + "]"); //if (_boardControl == null) return; //if (Constants.ControlGesture == BallControlGesture.ThumbUp) return; if (opennessState == PXCMGesture.GeoNode.Openness.LABEL_CLOSE) { if (_boardControl != null) { ActivateCurrentPebble(); } else { this.Dispatcher.Invoke(new Action(() => { LevelSelect.Instance.CheckLevelUnderXY(_boardX + Constants.IndexFingerMargin.X, _boardY + Constants.IndexFingerMargin.Y, true); })); } } }
public void Start() { //create session PXCMSession session; pxcmStatus status = PXCMSession.CreateInstance(out session); if (IsError(status)) { OnError(CamEvent.FAILED_TO_CREATE_SDK_SESSION); return; } //create gesture-module PXCMBase gestureBase; status = session.CreateImpl(PXCMGesture.CUID, out gestureBase); if (IsError(status)) { OnError(CamEvent.FAILED_TO_LOAD_GESTURE_RECOGNITION); session.Dispose(); return; } //create gesture-profile PXCMGesture gesture = (PXCMGesture)gestureBase; PXCMGesture.ProfileInfo profileInfo; status = gesture.QueryProfile(0, out profileInfo); profileInfo.activationDistance = 70; //setup gesture-capture UtilMCapture capture = new UtilMCapture(session); status = capture.LocateStreams(ref profileInfo.inputs); if (IsError(status)) { OnError(CamEvent.FAILED_TO_LOCATE_CAPTURE_MODULE); gesture.Dispose(); capture.Dispose(); session.Dispose(); return; } status = gesture.SetProfile(ref profileInfo); status = gesture.SubscribeAlert(this.OnAlertHandler); status = gesture.SubscribeGesture(100, this.OnGesureHandler); //start capture of frames bool device_lost = false; PXCMImage[] images = new PXCMImage[PXCMCapture.VideoStream.STREAM_LIMIT]; PXCMScheduler.SyncPoint[] syncPoints = new PXCMScheduler.SyncPoint[2]; while (_tracking) { status = capture.ReadStreamAsync(images, out syncPoints[0]); if (IsError(status)) { if (status == pxcmStatus.PXCM_STATUS_DEVICE_LOST) { if (!device_lost) { OnError(CamEvent.DEVICE_DISCONNECTED); } device_lost = true; continue; } OnError(CamEvent.DEVICE_FAILED); break; } if (device_lost) { OnNotify(CamEvent.DEVICE_RECONNECTED); device_lost = false; } status = gesture.ProcessImageAsync(images, out syncPoints[1]); if (IsError(status)) { break; } PXCMScheduler.SyncPoint.SynchronizeEx(syncPoints); if (syncPoints[0].Synchronize(0) >= pxcmStatus.PXCM_STATUS_NO_ERROR) { PXCMGesture.GeoNode data; status = gesture.QueryNodeData(0, PXCMGesture.GeoNode.Label.LABEL_BODY_HAND_PRIMARY, out data); if (!IsError(status)) { if (ShapeHelper.IsPointInsideRect(data.positionImage.x, data.positionImage.y, Constants.FoVWindow)) { //adjust the point to field-of-view window Point cameraPoint = new Point(data.positionImage.x - Constants.FoVWindow.X, data.positionImage.y - Constants.FoVWindow.Y); //cameraPoint = ShapeHelper.RotatePoint(cameraPoint, Constants.FoVCenter, Constants.RotationAngle); OnMovement(cameraPoint); if (data.opennessState != _previousOpenness) { OnOpenClose(data.opennessState, data.openness); _previousOpenness = data.opennessState; } } else { OnNotify(CamEvent.HOVERING_OUTSIDE); } } } foreach (PXCMScheduler.SyncPoint p in syncPoints) { if (p != null) { p.Dispose(); } } foreach (PXCMImage img in images) { if (img != null) { img.Dispose(); } } } if (gesture != null) { gesture.Dispose(); } if (capture != null) { capture.Dispose(); } if (session != null) { session.Dispose(); } }
public void ClearOpenness() { _previousOpenness = PXCMGesture.GeoNode.Openness.LABEL_OPENNESS_ANY; }