void Start() { Debug.Log("Start(): Initializing nodes."); this.context = new Context(SAMPLE_XML_FILE); this.depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator; if (this.depth == null) { Debug.LogError("Viewer must have a depth node!"); } this.hands = context.FindExistingNode(NodeType.Hands) as HandsGenerator; if (this.hands == null) { Debug.LogError("Viewer must have a hands node!"); } this.gestures = context.FindExistingNode(NodeType.Gesture) as GestureGenerator; if (this.gestures == null) { Debug.LogError("Viewer must have a gestures node!"); } this.hands.HandCreate += new HandsGenerator.HandCreateHandler(hands_HandCreate); this.hands.HandUpdate += new HandsGenerator.HandUpdateHandler(hands_HandUpdate); this.hands.HandDestroy += new HandsGenerator.HandDestroyHandler(hands_HandDestroy); this.gestures.AddGesture("Wave"); this.gestures.AddGesture("RaiseHand"); this.gestures.GestureRecognized += new GestureGenerator.GestureRecognizedHandler(gestures_GestureRecognized); this.gestures.StartGenerating(); }
public bool initializeSensor(String xmlPath) { try { pbuffer = new Point[6]; openpalm = new OpenPalm(); scrHeight = SystemInformation.PrimaryMonitorSize.Height; scrWidth = SystemInformation.PrimaryMonitorSize.Width; mouseSpeed = SystemInformation.MouseSpeed * 0.15; pointCollections = new PointCollection(); /*OpenNI objects - Context, DepthGenerator and DepthMetaData are initialized here*/ cxt = new Context(xmlPath); depthGen = cxt.FindExistingNode(NodeType.Depth) as DepthGenerator; gsHandsGenerator = cxt.FindExistingNode(NodeType.Hands) as HandsGenerator; gsHandsGenerator.SetSmoothing(0.1f); depthMeta = new DepthMetaData(); if (depthGen == null) { return(false); } xRes = depthGen.MapOutputMode.XRes; yRes = depthGen.MapOutputMode.YRes; /*NITE objects - Session manager, PointControl is initialized here*/ sessionMgr = new SessionManager(cxt, "Wave", "RaiseHand"); pointCtrl = new PointControl("PointTracker"); steadydetector = new SteadyDetector(); flrouter = new FlowRouter(); brodcaster = new Broadcaster(); steadydetector.DetectionDuration = 200; steadydetector.Steady += new EventHandler <SteadyEventArgs>(steadydetector_Steady); steadydetector.NotSteady += new EventHandler <SteadyEventArgs>(steadydetector_NotSteady); /* pointCtrl.PrimaryPointCreate += new EventHandler<HandFocusEventArgs>(pointCtrl_PrimaryPointCreate); * pointCtrl.PrimaryPointUpdate += new EventHandler<HandEventArgs>(pointCtrl_PrimaryPointUpdate); * pointCtrl.PrimaryPointDestroy += new EventHandler<IdEventArgs>(pointCtrl_PrimaryPointDestroy);*/ pointCtrl.PointCreate += new EventHandler <HandEventArgs>(pointCtrl_PointCreate); pointCtrl.PointUpdate += new EventHandler <HandEventArgs>(pointCtrl_PointUpdate); pointCtrl.PointDestroy += new EventHandler <IdEventArgs>(pointCtrl_PointDestroy); sessionMgr.AddListener(steadydetector); sessionMgr.AddListener(pointCtrl); //make the session manager listen to the point control isActive = false; //set lifecycle flag to false //fill the handpoint coordinates with invalid values //initialize the clipping matrix HandPointBuffer = new ArrayList(); } catch (Exception e) { return(false); } return(true); }
/// <summary> /// Save hands in context. /// </summary> public IReadOnlyList <Hand> SaveHands(int countHands, int countPlayers, RoomType room) { var hands = HandsGenerator.CreateCollectionHands(countHands, countPlayers, room); HandsHistoryManager.SaveHands(hands); return(hands); }
// 初期化 private void xnInitialize() { // コンテキストの初期化 ScriptNode scriptNode; context = Context.CreateFromXmlFile(CONFIG_XML_PATH, out scriptNode); // 鏡モード(反転)にしない context.GlobalMirror = false; // イメージジェネレータの作成 image = context.FindExistingNode(NodeType.Image) as ImageGenerator; if (image == null) { throw new Exception(context.GlobalErrorState); } // デプスジェネレータの作成 depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator; if (depth == null) { throw new Exception(context.GlobalErrorState); } // デプスの座標をイメージに合わせる depth.AlternativeViewpointCapability.SetViewpoint(image); // ジェスチャージェネレータの作成 gesture = context.FindExistingNode(NodeType.Gesture) as GestureGenerator; if (depth == null) { throw new Exception(context.GlobalErrorState); } // ジェスチャーの登録 gesture.AddGesture("RaiseHand"); // ジェスチャー用のコールバックを登録 gesture.GestureRecognized += new EventHandler <GestureRecognizedEventArgs>(gesture_GestureRecognized); gesture.GestureProgress += new EventHandler <GestureProgressEventArgs>(gesture_GestureProgress); // ハンドジェネレータの作成 hands = context.FindExistingNode(NodeType.Hands) as HandsGenerator; if (depth == null) { throw new Exception(context.GlobalErrorState); } // ハンドトラッキング用のコールバックを登録する hands.HandCreate += new EventHandler <HandCreateEventArgs>(hands_HandCreate); hands.HandUpdate += new EventHandler <HandUpdateEventArgs>(hands_HandUpdate); hands.HandDestroy += new EventHandler <HandDestroyEventArgs>(hands_HandDestroy); // ジェスチャーの検出開始 context.StartGeneratingAll(); }
public bool SetConfig(XmlElement xmlconfig) { // TO-DO: add some configuration parameters if of any use this.context = new Context("NiteKinectConfig.xml"); this.depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator; if (this.depth == null) { throw new Exception("Viewer must have a depth node!"); } this.userGenerator = new UserGenerator(this.context); this.userGenerator.NewUser += userGenerator_NewUser; this.userGenerator.LostUser += userGenerator_LostUser; // this.skeletonCapbility = this.userGenerator.SkeletonCapability; this.skeletonCapbility.SetSkeletonProfile(SkeletonProfile.All); this.skeletonCapbility.CalibrationEnd += skeletonCapbility_CalibrationEnd; // this.poseDetectionCapability = this.userGenerator.PoseDetectionCapability; this.calibPose = this.skeletonCapbility.CalibrationPose; this.poseDetectionCapability.PoseDetected += poseDetectionCapability_PoseDetected; // this.handsGenerator = new HandsGenerator(this.context); this.handsGenerator.HandCreate += handsGenerator_HandCreate; this.handsGenerator.HandDestroy += handsGenerator_HandDestroy; this.handsGenerator.HandUpdate += handsGenerator_HandUpdate; // this.gestureGenerator = new GestureGenerator(this.context); this.gestureGenerator.AddGesture("Wave"); this.gestureGenerator.AddGesture("Click"); this.gestureGenerator.AddGesture("RaiseHand"); this.gestureGenerator.GestureRecognized += gestureGenerator_GestureRecognized; // this.joints = new Dictionary <int, Dictionary <SkeletonJoint, SkeletonJointPosition> >(); // this.userGenerator.StartGenerating(); this.handsGenerator.StartGenerating(); this.gestureGenerator.StartGenerating(); // this.histogram = new int[this.depth.DeviceMaxDepth]; MapOutputMode mapMode = this.depth.MapOutputMode; // this.bitmap = new Bitmap((int)mapMode.XRes, (int)mapMode.YRes); this.shouldRun = true; this.readerThread = new Thread(ReaderThread); this.readerThread.Priority = ThreadPriority.Lowest; this.readerThread.Start(); // return(true); }
private void CleanUp() { if (FHandGenerator != null) { FHandGenerator.HandCreate -= FHands_HandCreate; FHandGenerator.HandDestroy -= FHands_HandDestroy; FHandGenerator.HandUpdate -= FHands_HandUpdate; FHandGenerator.Dispose(); FHandGenerator = null; } FTrackedStartPositions.Clear(); FTrackedHands.Clear(); }
private void CloseContext() { if (FUpdater != null && FUpdater.IsAlive) { //wait for threadloop to exit FRunning = false; FUpdater.Join(); } if (FContext != null) { //FContext.WaitAndUpdateAll(); FContext.StopGeneratingAll(); FContext.ErrorStateChanged -= FContext_ErrorStateChanged; if (FHandGenerator != null) { FHandGenerator.HandCreate -= FHands_HandCreate; FHandGenerator.HandDestroy -= FHands_HandDestroy; FHandGenerator.HandUpdate -= FHands_HandUpdate; FHandGenerator.Dispose(); FHandGenerator = null; } if (FDepthGenerator != null) { FDepthGenerator.Dispose(); } if (FImageGenerator != null) { FImageGenerator.Dispose(); } FTrackedStartPositions.Clear(); FTrackedHands.Clear(); FContext.Release(); FContext = null; } Marshal.FreeCoTaskMem(FBufferedImage); }
private void OpenContext() { //try to open Kinect Context try { FContext = new Context(); FContext.ErrorStateChanged += FContext_ErrorStateChanged; // FImageGenerator = (ImageGenerator) FContext.CreateAnyProductionTree(OpenNI.NodeType.Image, null); FDepthGenerator = (DepthGenerator)FContext.CreateAnyProductionTree(OpenNI.NodeType.Depth, null); // FDepthGenerator.AlternativeViewpointCapability.SetViewpoint(FImageGenerator); // Create and Hands generator FHandGenerator = new HandsGenerator(FContext); FHandGenerator.HandCreate += FHands_HandCreate; FHandGenerator.HandDestroy += FHands_HandDestroy; FHandGenerator.HandUpdate += FHands_HandUpdate; FHistogram = new int[FDepthGenerator.DeviceMaxDepth]; //Set the resolution of the texture var mapMode = FDepthGenerator.MapOutputMode; FTexWidth = mapMode.XRes; FTexHeight = mapMode.YRes; //allocate data for the Depth Image FBufferedImage = Marshal.AllocCoTaskMem(FTexWidth * FTexHeight * 2); //Reinitalie the vvvv texture Reinitialize(); FContext.StartGeneratingAll(); FUpdater = new Thread(ReadImageData); FRunning = true; FUpdater.Start(); } catch (Exception e) { FLogger.Log(e); } }
//called when data for any output pin is requested public void Evaluate(int SpreadMax) { if (FContextChanged) { if (FContextIn.PluginIO.IsConnected) { if (FContextIn[0] != null) { try { // Create and Hands generator FHandGenerator = new HandsGenerator(FContextIn[0]); FHandGenerator.HandCreate += FHands_HandCreate; FHandGenerator.HandDestroy += FHands_HandDestroy; FHandGenerator.HandUpdate += FHands_HandUpdate; FHandGenerator.StartGenerating(); FContextChanged = false; } catch (Exception ex) { FLogger.Log(ex); } } } else { CleanUp(); FContextChanged = false; } } if (FHandGenerator != null) { if (FDoTrackStartPosition.IsChanged) { bool enable = false; for (int i = 0; i < FDoTrackStartPosition.SliceCount; i++) { enable |= FDoTrackStartPosition[i]; } //enable if any slice is 1 if (enable) { FHandGenerator.StartGenerating(); } else { FHandGenerator.StopGenerating(); } } if (FHandGenerator.IsDataNew) { FIsTrackedOut.SliceCount = FHandIdOut.SliceCount = FHandPositionOut.SliceCount = FStartPositionIn.SliceCount; //for every given StartPosition check if it is currently tracked for (int i = 0; i < FStartPositionIn.SliceCount; i++) { if (FDoTrackStartPosition[i]) { //find userID in FTrackedStartPositions int userID = -1; foreach (var tracker in FTrackedStartPositions) { var p = new Point3D((float)(FStartPositionIn[i].x * 1000), (float)(FStartPositionIn[i].y * 1000), (float)(FStartPositionIn[i].z * 1000)); if (tracker.Value.Equals(p)) { userID = tracker.Key; break; } } //if present return tracking info if (userID > -1) { FIsTrackedOut[i] = true; FHandIdOut[i] = userID; var p = FTrackedHands[userID]; FHandPositionOut[i] = new Vector3D(p.X / 1000, p.Y / 1000, p.Z / 1000); } //else start tracking else { FIsTrackedOut[i] = false; FHandIdOut[i] = -1; FHandPositionOut[i] = FStartPositionIn[i]; var p = new Point3D((float)(FStartPositionIn[i].x * 1000), (float)(FStartPositionIn[i].y * 1000), (float)(FStartPositionIn[i].z * 1000)); FHandGenerator.StartTracking(p); } } else { //find the handID corresponding to the StartPosition //and stop tracking it int userID = -1; foreach (var tracker in FTrackedStartPositions) { var p = new Point3D((float)(FStartPositionIn[i].x * 1000), (float)(FStartPositionIn[i].y * 1000), (float)(FStartPositionIn[i].z * 1000)); if (tracker.Value.Equals(p)) { userID = tracker.Key; break; } } if (userID > -1) { FHandGenerator.StopTracking(userID); } FIsTrackedOut[i] = false; FHandIdOut[i] = -1; FHandPositionOut[i] = FStartPositionIn[i]; } } } } else { FIsTrackedOut.SliceCount = FHandIdOut.SliceCount = FHandPositionOut.SliceCount = 0; } }