/* * private int distanciaAnt=0; * private int escalaAnt=0; */ void Start() { Debug.Log("START APP"); this.context = Context.CreateFromXmlFile(XML_CONFIG, out scriptNode); this.depth = this.context.FindExistingNode(NodeType.Depth) as DepthGenerator; if (depth == null) { throw new Exception("Nodo de Profundidad no encontrado"); } //User Tracking this.userGenerator = new UserGenerator(this.context); this.skeletonCapability = this.userGenerator.SkeletonCapability; this.poseDetectionCapability = this.userGenerator.PoseDetectionCapability; this.calibPose = this.skeletonCapability.CalibrationPose; this.userGenerator.NewUser += userGenerator_NewUser; this.userGenerator.LostUser += userGenerator_LostUser; this.poseDetectionCapability.PoseDetected += poseDetectionCapability_PoseDetected; this.skeletonCapability.CalibrationComplete += skeletonCapability_CalibrationComplete; this.skeletonCapability.SetSkeletonProfile(SkeletonProfile.All); this.userGenerator.StartGenerating(); this.joints = new Dictionary <int, Dictionary <SkeletonJoint, SkeletonJointPosition> >(); // }
void Initialize() { this.context = new Context("SamplesConfig.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.skeletonCapbility = new SkeletonCapability(this.userGenerator); this.poseDetectionCapability = new PoseDetectionCapability(this.userGenerator); this.calibPose = this.skeletonCapbility.GetCalibrationPose(); this.userGenerator.NewUser += new UserGenerator.NewUserHandler(userGenerator_NewUser); this.userGenerator.LostUser += new UserGenerator.LostUserHandler(userGenerator_LostUser); this.poseDetectionCapability.PoseDetected += new PoseDetectionCapability.PoseDetectedHandler(poseDetectionCapability_PoseDetected); this.skeletonCapbility.CalibrationEnd += new SkeletonCapability.CalibrationEndHandler(skeletonCapbility_CalibrationEnd); this.skeletonCapbility.SetSkeletonProfile(SkeletonProfile.All); this.userGenerator.StartGenerating(); App.ViewModel.Status = "Waiting to acquire user"; this.ShouldRun = true; this.readerThread = new Thread(ReaderThread); this.readerThread.Start(); }
void Start() { this.context = new Context(SAMPLE_XML_FILE); 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.skeletonCapbility = new SkeletonCapability(this.userGenerator); this.poseDetectionCapability = new PoseDetectionCapability(this.userGenerator); this.calibPose = this.skeletonCapbility.GetCalibrationPose(); this.userGenerator.NewUser += new UserGenerator.NewUserHandler(userGenerator_NewUser); this.userGenerator.LostUser += new UserGenerator.LostUserHandler(userGenerator_LostUser); this.poseDetectionCapability.PoseDetected += new PoseDetectionCapability.PoseDetectedHandler(poseDetectionCapability_PoseDetected); this.skeletonCapbility.CalibrationEnd += new SkeletonCapability.CalibrationEndHandler(skeletonCapbility_CalibrationEnd); this.skeletonCapbility.SetSkeletonProfile(SkeletonProfile.All); this.userGenerator.StartGenerating(); MapOutputMode mapMode = this.depth.GetMapOutputMode(); this.shouldRun = true; }
/// <summary> /// Instancia um objeto da classe UserManager a partir de context. /// </summary> public UserManager(Context context) { userGenerator = new UserGenerator(context); poseDetectionCapability = userGenerator.PoseDetectionCapability; skeletonCapability = userGenerator.SkeletonCapability; skeletonCapability.SetSkeletonProfile(SkeletonProfile.All); skeletonCapability.SetSmoothing(0.5f); skeleton = new Skeleton(skeletonCapability); users = new Dictionary <int, User>(); userGenerator.NewUser += NewUser; poseDetectionCapability.PoseDetected += PoseDetected; poseDetectionCapability.OutOfPose += OutOfPose; skeletonCapability.CalibrationStart += CalibrationStart; skeletonCapability.CalibrationComplete += CalibrationComplete; userGenerator.LostUser += LostUser; focus = new Dictionary <string, IFocus>(); focus.Add("Closest", new FocusClosest()); focus.Add("Farthest", new FocusFarthest()); focus.Add("Oldest", new FocusOldest()); focus.Add("Newest", new FocusNewest()); focus.Add("None", new FocusNone()); currentFocus = focus["None"]; }
// Use this for initialization void Start() { this.context = Context.CreateFromXmlFile(XML_CONFIG, out scriptNode); //Al Ejecutar esta linea al salir de probar el nodo sigue trabajando para eso ocupamos el onApplicationQuit this.depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator; if (depth == null) { throw new Exception("Nodo de Profundidad no encontrado"); } this.userGenerator = new UserGenerator(this.context); this.skeletonCapability = this.userGenerator.SkeletonCapability; this.poseDetectionCapability = this.userGenerator.PoseDetectionCapability; this.calibPose = this.skeletonCapability.CalibrationPose; //Agregas los handlers this.userGenerator.NewUser += userGenerator_NewUser; this.userGenerator.LostUser += userGenerator_LostUser; this.poseDetectionCapability.PoseDetected += poseDetectionCapability_PoseDetected; this.skeletonCapability.CalibrationComplete += skeletonCapability_CalibrationComplete; //Activar los joints depende del profile //http://openni.org/docs2/Reference/_xn_types_8h_a294999eabe6eeab319a61d3d0093b174.html#a294999eabe6eeab319a61d3d0093b174 this.skeletonCapability.SetSkeletonProfile(SkeletonProfile.All); this.joints = new Dictionary <int, Dictionary <SkeletonJoint, SkeletonJointPosition> >(); this.userGenerator.StartGenerating(); this.shouldRun = true; }
void Start() { /*really unity? * * do you do that for real? * */ InitializeCharacter(); this.context = new Context(SAMPLE_XML_FILE); 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.skeletonCapbility = new SkeletonCapability(this.userGenerator); this.poseDetectionCapability = new PoseDetectionCapability(this.userGenerator); this.calibPose = this.skeletonCapbility.GetCalibrationPose(); this.userGenerator.NewUser += new UserGenerator.NewUserHandler(userGenerator_NewUser); this.userGenerator.LostUser += new UserGenerator.LostUserHandler(userGenerator_LostUser); this.poseDetectionCapability.PoseDetected += new PoseDetectionCapability.PoseDetectedHandler(poseDetectionCapability_PoseDetected); this.skeletonCapbility.CalibrationEnd += new SkeletonCapability.CalibrationEndHandler(skeletonCapbility_CalibrationEnd); this.skeletonCapbility.SetSkeletonProfile(SkeletonProfile.All); this.joints = new Dictionary <uint, Dictionary <SkeletonJoint, SkeletonJointPosition> >(); this.userGenerator.StartGenerating(); this.histogram = new int[this.depth.GetDeviceMaxDepth()]; MapOutputMode mapMode = this.depth.GetMapOutputMode(); // this.bitmap = new Bitmap((int)mapMode.nXRes, (int)mapMode.nYRes/*, System.Drawing.Imaging.PixelFormat.Format24bppRgb*/); usersLblTex = new Texture2D((int)mapMode.nXRes, (int)mapMode.nYRes); Debug.Log("usersLblTex = w: " + usersLblTex.width + " h: " + usersLblTex.height); usersMapSize = mapMode.nXRes * mapMode.nYRes; usersMapColors = new Color[usersMapSize]; usersMapRect = new Rect(Screen.width - usersLblTex.width / 2, Screen.height - usersLblTex.height / 2, usersLblTex.width / 2, usersLblTex.height / 2); usersLabelMap = new short[usersMapSize]; usersDepthMap = new short[usersMapSize]; usersHistogramMap = new float[5000]; //DepthMetaData depthMD = new DepthMetaData(); this.shouldRun = true; //this.readerThread = new Thread(ReaderThread); // this.readerThread.Start(); }
public MainWindow() { InitializeComponent(); console = new Console(); console.Show(); console.Top = 0; console.Left = 0; Console.Write("TrackingNI by Richard Pianka and Ramsey Abouzahra"); context = new Context(CONFIG_FILE); imageGenerator = new ImageGenerator(context); depthGenerator = new DepthGenerator(context); userGenerator = new UserGenerator(context); poseDetectionCapability = userGenerator.PoseDetectionCapability; skeletonCapability = userGenerator.SkeletonCapability; MapOutputMode mapMode = depthGenerator.MapOutputMode; int width = (int)mapMode.XRes; int height = (int)mapMode.YRes; imageBitmap = new WriteableBitmap(width, height, DPI_X, DPI_Y, PixelFormats.Rgb24, null); depthBitmap = new WriteableBitmap(width, height, DPI_X, DPI_Y, PixelFormats.Rgb24, null); depthBitmapCorrected = new WriteableBitmap(width, height, DPI_X, DPI_Y, PixelFormats.Rgb24, null); imageData = new ImageMetaData(); depthData = new DepthMetaData(); skeletonDraw = new SkeletonDraw(); Histogram = new int[depthGenerator.DeviceMaxDepth]; reader = new Thread(new ThreadStart(Reader)); reader.IsBackground = true; worker = new BackgroundWorker(); stop = false; CompositionTarget.Rendering += new EventHandler(Worker); Closing += new System.ComponentModel.CancelEventHandler(MainWindow_Closing); userGenerator.NewUser += new EventHandler <NewUserEventArgs>(NewUser); userGenerator.LostUser += new EventHandler <UserLostEventArgs>(LostUser); skeletonCapability.CalibrationStart += new EventHandler <CalibrationStartEventArgs>(CalibrationStart); skeletonCapability.CalibrationEnd += new EventHandler <CalibrationEndEventArgs>(CalibrationEnd); skeletonCapability.SetSkeletonProfile(SkeletonProfile.All); poseDetectionCapability.PoseDetected += new EventHandler <PoseDetectedEventArgs>(PoseDetected); poseDetectionCapability.PoseEnded += new EventHandler <PoseEndedEventArgs>(PoseEnded); reader.Start(); worker.DoWork += new DoWorkEventHandler(WorkerTick); }
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); }
/// @brief Tells us if a pose is supported /// /// @param pose The name of the pose we want to know if supported /// @return true if the pose is supported and false if not (or there is an error). public bool IsPoseSupported(string pose) { if (!Valid) { return(false); } PoseDetectionCapability cap = UserNode.PoseDetectionCapability; if (cap == null) { return(false); } return(cap.IsPoseSupported(pose)); }
// methods to encompass the pose detection capability /// @brief Gets a string array of supported poses /// /// @return An array of supported poses, null if invalid or no supported poses public string[] GetAllAvailablePoses() { if (!Valid) { return(null); } PoseDetectionCapability cap = UserNode.PoseDetectionCapability; if (cap == null) { return(null); } return(cap.GetAllAvailablePoses()); }
/// @brief Gets the current pose status. /// /// @param userID The openNI user id whose status we seek /// @param poseName The name of the pose we want status on /// @param status a reference to the status we want to fill. /// @return true on success and false on failure. public bool GetPoseStatus(int userID, string poseName, ref NIPoseDetectionStateStatus status) { if (!Valid) { return(false); } PoseDetectionCapability cap = UserNode.PoseDetectionCapability; if (cap == null) { return(false); } PoseDetectionStateStatus openNIStatus; try { openNIStatus = cap.GetPoseStatus(userID, poseName); } catch (System.Exception ex) { Log("Failed to get pose status for userID " + userID + " pose " + poseName + " with message " + ex.Message, NIEventLogger.Categories.Misc, NIEventLogger.Sources.BaseObjects, NIEventLogger.VerboseLevel.Errors); return(false); } status.m_eState = openNIStatus.m_eState; status.m_eStatus = openNIStatus.m_eStatus; if (openNIStatus.m_poseTime <= 0 || openNIStatus.m_eState == PoseDetectionState.OutOfPose) { status.m_timePoseHeld = -1.0f; } else { long userGeneratorTime = m_userGenerator.Timestamp; if (userGeneratorTime <= openNIStatus.m_poseTime) { status.m_timePoseHeld = -1.0f; } else { userGeneratorTime -= openNIStatus.m_poseTime; status.m_timePoseHeld = (float)userGeneratorTime; status.m_timePoseHeld /= 1000000.0f; // to transform from microseconds to seconds status.m_timePoseHeld *= Time.timeScale; // to convert the coodrinates based on Time scale } } return(true); }
void Start() { calibratedUsers = new List <int>(); calibratingUsers = new List <int>(); allUsers = new List <int>(); this.userGenerator = OpenNIContext.OpenNode(NodeType.User) as UserGenerator; //new UserGenerator(this.Context.context); this.skeletonCapbility = this.userGenerator.SkeletonCapability; this.poseDetectionCapability = this.userGenerator.PoseDetectionCapability; this.calibPose = this.skeletonCapbility.CalibrationPose; this.skeletonCapbility.SetSkeletonProfile(SkeletonProfile.All); this.userGenerator.NewUser += new EventHandler <NewUserEventArgs>(userGenerator_NewUser); this.userGenerator.LostUser += new EventHandler <UserLostEventArgs>(userGenerator_LostUser); this.poseDetectionCapability.PoseDetected += new EventHandler <PoseDetectedEventArgs>(poseDetectionCapability_PoseDetected); this.skeletonCapbility.CalibrationEnd += new EventHandler <CalibrationEndEventArgs>(skeletonCapbility_CalibrationEnd); }
public KinectManager(InputProvider inputProvider) { this.inputProvider = inputProvider; //get configuration String OpenNiconfigPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\" + CONFIG_XML_FILE; this.context = Context.CreateFromXmlFile(OpenNiconfigPath, out scriptNode); this.depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator; if (this.depth == null) { throw new Exception("Viewer must have a depth node!"); } this.maxDepth = this.depth.DeviceMaxDepth; this.userGenerator = new UserGenerator(this.context); this.skeletonCapbility = this.userGenerator.SkeletonCapability; this.poseDetectionCapability = this.userGenerator.PoseDetectionCapability; this.calibPose = this.skeletonCapbility.CalibrationPose; this.userGenerator.NewUser += userGenerator_NewUser; this.userGenerator.LostUser += userGenerator_LostUser; this.poseDetectionCapability.PoseDetected += poseDetectionCapability_PoseDetected; this.skeletonCapbility.CalibrationComplete += skeletonCapbility_CalibrationComplete; this.skeletonCapbility.SetSkeletonProfile(SkeletonProfile.Upper); this.users = new Dictionary <int, User>(); this.userGenerator.StartGenerating(); this.mapMode = this.depth.MapOutputMode; //load settings updateSettings(); //start threads this.shouldRun = true; this.readerThread = new Thread(ReaderThread); this.readerThread.Start(); this.settingsUpdateThread = new Thread(runUpdateSettings); this.settingsUpdateThread.Start(); Console.WriteLine("Device initialized"); }
private KinectManager() { this.context = Context.CreateFromXmlFile("SamplesConfig.xml", out this.scriptNode); this.depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator; this.userGenerator = new UserGenerator(context); this.userGenerator.NewUser += UserGenerator_NewUser; this.userGenerator.UserExit += UserGenerator_UserExit; this.skeletonCapability = this.userGenerator.SkeletonCapability; this.poseDetectionCapability = this.userGenerator.PoseDetectionCapability; this.poseDetectionCapability.PoseDetected += PoseDetectionCapability_PoseDetected; this.skeletonCapability.CalibrationComplete += SkeletonCapability_CalibrationComplete; this.skeletonCapability.SetSkeletonProfile(SkeletonProfile.All); this.calibPose = this.skeletonCapability.CalibrationPose; this.poseDetectionCapability.PoseDetected += poseCap_PoseDetected; // this.userGenerator.StartGenerating(); // this.context.StartGeneratingAll(); }
/// <summary> /// Creates a new control instance with a live device as data /// source. The current image data can be obtained by the /// <see cref="Image"/>-property. The /// <see cref="NewImageDataAvailable"/> event informs about when the /// data is updated, the <see cref="ErrorOccured"/>-event about /// errors. /// Start the generation-process by calling /// <see cref="StartGenerating"/> and stop it by calling /// <see cref="StopGenerating"/>. /// </summary> /// <exception cref="System.Exception">Thrown if the device could not /// be initialized properly.</exception> public OpenNILiveStreamController() { // Create a new context and the data-generating nodes. context = new Context(); context.GlobalMirror = false; // Image imageGenerator = new ImageGenerator(context); MapOutputMode mapMode = new MapOutputMode(); mapMode.FPS = 30; mapMode.XRes = VIDEO_WIDTH; mapMode.YRes = VIDEO_HEIGHT; imageGenerator.MapOutputMode = mapMode; imageGenerator.PixelFormat = OpenNI.PixelFormat.RGB24; // Depth depthGenerator = new DepthGenerator(context); depthGenerator.AlternativeViewpointCapability.SetViewpoint(imageGenerator); histogram = new int[depthGenerator.DeviceMaxDepth]; if (depthGenerator == null || imageGenerator == null) { throw new Exception("Could not initialize kinect device."); } // User generator userGenerator = new UserGenerator(context); skeletonCapability = userGenerator.SkeletonCapability; poseDetectionCapability = userGenerator.PoseDetectionCapability; calibPose = skeletonCapability.CalibrationPose; userGenerator.NewUser += userGenerator_NewUser; userGenerator.LostUser += userGenerator_LostUser; poseDetectionCapability.PoseDetected += poseDetectionCapability_PoseDetected; skeletonCapability.CalibrationEnd += skeletonCapability_CalibrationEnd; skeletonCapability.SetSkeletonProfile(SkeletonProfile.All); // Error handling context.ErrorStateChanged += context_ErrorStateChanged; }
/// @brief Initialize the user and skeleton information /// /// This method initializes the user and skeleton information. It assumes the /// context is already valid (otherwise we fail). /// @note - Since we use a singleton pattern, multiple initializations will simply delete /// the old information and create new one! /// @note - It is the responsibility of the initializer to call @ref Dispose. /// @param context the context used /// @param logger the logger object we will enter logs into /// @return true on success, false on failure. public bool Init(NIEventLogger logger, NIContext context) { NIOpenNICheckVersion.Instance.ValidatePrerequisite(); Dispose(); // to make sure we are not initialized if (InitWithContext(logger, context) == false) { return(false); } m_userGenerator = context.CreateNode(NodeType.User) as UserGenerator; if (m_userGenerator == null || m_userGenerator.SkeletonCapability == null) { Log("Failed to create proper user generator.", NIEventLogger.Categories.Initialization, NIEventLogger.Sources.Skeleton, NIEventLogger.VerboseLevel.Errors); // we either don't have a user generator or the user generator we received does not have a skeleton Dispose(); return(false); } // skeleton heuristics tries to handle the skeleton when the confidence is low. It can // have two values: 0 (no heuristics) or 255 (use heuristics). m_userGenerator.SetIntProperty("SkeletonHeuristics", 255); // makes sure we use all joints m_userGenerator.SkeletonCapability.SetSkeletonProfile(SkeletonProfile.All); PoseDetectionCapability cap = UserNode.PoseDetectionCapability; if (cap != null) { m_legalPoses = cap.GetAllAvailablePoses(); } else { m_legalPoses = null; } m_poseDetectionCounter = new List <poseDetectionReferenceCounter>(); m_userGenerator.LostUser += new EventHandler <UserLostEventArgs>(LostUserCallback); return(true); }
void Start() { // Make sure we have a valid OpenNIContext Context = OpenNIContext.Instance; if (null == Context) { print("OpenNI not inited"); return; } calibratedUsers = new List <int>(); calibratingUsers = new List <int>(); allUsers = new List <int>(); this.userGenerator = new UserGenerator(this.Context.context); this.skeletonCapbility = this.userGenerator.SkeletonCapability; this.poseDetectionCapability = this.userGenerator.PoseDetectionCapability; this.calibPose = this.skeletonCapbility.CalibrationPose; this.skeletonCapbility.SetSkeletonProfile(SkeletonProfile.All); this.userGenerator.NewUser += new EventHandler <NewUserEventArgs>(userGenerator_NewUser); this.userGenerator.LostUser += new EventHandler <UserLostEventArgs>(userGenerator_LostUser); // this.poseDetectionCapability.PoseDetected += new EventHandler<PoseDetectedEventArgs>(poseDetectionCapability_PoseDetected); this.skeletonCapbility.CalibrationEnd += new EventHandler <CalibrationEndEventArgs>(skeletonCapbility_CalibrationEnd); }
//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 { FUserGenerator = new UserGenerator(FContextIn[0]); FSkeletonCapability = FUserGenerator.SkeletonCapability; FPoseDetectionCapability = FUserGenerator.PoseDetectionCapability; FCalibPose = FSkeletonCapability.CalibrationPose; FUserGenerator.NewUser += userGenerator_NewUser; FUserGenerator.LostUser += userGenerator_LostUser; FPoseDetectionCapability.PoseDetected += poseDetectionCapability_PoseDetected; FSkeletonCapability.CalibrationComplete += skeletonCapbility_CalibrationComplete; FSkeletonCapability.SetSkeletonProfile(FSkeletonProfileIn[0]); FJoints = new Dictionary <int, Dictionary <SkeletonJoint, SkeletonJointTransformation> >(); FUserGenerator.StartGenerating(); FContextChanged = false; } catch (Exception ex) { FLogger.Log(ex); } } } else { CleanUp(); FContextChanged = false; } } if (FUserGenerator != null) { if (FEnabledIn.IsChanged) { if (FEnabledIn[0]) { FUserGenerator.StartGenerating(); } else { FUserGenerator.StopGenerating(); } } if (FUserGenerator.IsDataNew) { if (FSkeletonProfileIn.IsChanged) { FSkeletonCapability.SetSkeletonProfile(FSkeletonProfileIn[0]); } if (FSmoothingIn.IsChanged) { FSkeletonCapability.SetSmoothing(FSmoothingIn[0]); } FUserIdOut.SliceCount = FUserGenerator.NumberOfUsers; FStatusOut.SliceCount = FUserGenerator.NumberOfUsers; FJointPositionOut.SliceCount = FUserGenerator.NumberOfUsers; FJointOrientationXOut.SliceCount = FUserGenerator.NumberOfUsers; FJointOrientationYOut.SliceCount = FUserGenerator.NumberOfUsers; FJointOrientationZOut.SliceCount = FUserGenerator.NumberOfUsers; if (FUserGenerator.NumberOfUsers > 0) { //get all Users and sort them int[] users = FUserGenerator.GetUsers(); Array.Sort(users); int slice = 0; foreach (int user in users) { FUserIdOut[slice] = user; if (FSkeletonCapability.IsTracking(user)) { FStatusOut[slice] = "Tracking user " + user; int u = user - 1; int binSize = FJointIn[u].SliceCount; FJointPositionOut[u].SliceCount = binSize; FJointOrientationXOut[u].SliceCount = FJointOrientationYOut[u].SliceCount = FJointOrientationZOut[u].SliceCount = binSize; for (int i = 0; i < binSize; i++) { var j = GetJoint(user, FJointIn[u][i]); var p = j.Position.Position; if (j.Position.Confidence > 0.5) { FJointPositionOut[u][i] = new Vector3D(p.X, p.Y, p.Z) / 1000; } var o = j.Orientation; if (o.Confidence > FConfidenceIn[slice]) { FJointOrientationXOut[u][i] = new Vector3D(o.X1, o.Y1, o.Z1); FJointOrientationYOut[u][i] = new Vector3D(o.X2, o.Y2, o.Z2); FJointOrientationZOut[u][i] = new Vector3D(o.X3, o.Y3, o.Z3); } } } else if (FSkeletonCapability.IsCalibrating(user)) { FStatusOut[slice] = "Calibrating user " + user; } else { FStatusOut[slice] = "Looking for pose on user " + user; } slice++; } } } } else { FUserIdOut.SliceCount = 0; FStatusOut.SliceCount = 0; FJointPositionOut.SliceCount = 0; FJointOrientationXOut.SliceCount = 0; FJointOrientationYOut.SliceCount = 0; FJointOrientationZOut.SliceCount = 0; } }
// 初期化 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); // ユーザージェネレータの作成 user = context.FindExistingNode(NodeType.User) as UserGenerator; if (depth == null) { throw new Exception(context.GlobalErrorState); } // ユーザー検出機能をサポートしているか確認 if (!user.IsCapabilitySupported("User::Skeleton")) { throw new Exception("ユーザー検出をサポートしていません"); } // ユーザー認識のコールバックを登録 user.NewUser += new EventHandler <NewUserEventArgs>(user_NewUser); user.LostUser += new EventHandler <UserLostEventArgs>(user_LostUser); //キャリブレーションにポーズが必要か確認 skelton = user.SkeletonCapability; if (skelton.DoesNeedPoseForCalibration) { // ポーズ検出のサポートチェック if (!user.IsCapabilitySupported("User::PoseDetection")) { throw new Exception("ユーザー検出をサポートしていません"); } // キャリブレーションポーズの取得 pose = skelton.CalibrationPose; // ポーズ検出のコールバックを登録 PoseDetectionCapability poseDetect = user.PoseDetectionCapability; poseDetect.PoseDetected += new EventHandler <PoseDetectedEventArgs>(poseDetect_PoseDetected); poseDetect.PoseEnded += new EventHandler <PoseEndedEventArgs>(poseDetect_PoseEnded); } // キャリブレーションのコールバックを登録 skelton.CalibrationStart += new EventHandler <CalibrationStartEventArgs>(skelton_CalibrationStart); skelton.CalibrationEnd += new EventHandler <CalibrationEndEventArgs>(skelton_CalibrationEnd); // すべてをトラッキングする skelton.SetSkeletonProfile(SkeletonProfile.All); // ジェスチャーの検出開始 context.StartGeneratingAll(); }
public MainWindow() { InitializeComponent(); trackingUser = false; trackingUserId = 0; stop = false; console = new Console(); console.Show(); console.Top = 10; console.Left = 10; prompt = new UserPrompt(); prompt.Show(); prompt.Top = 10; prompt.Left = 550; this.Top = 250; this.Left = 550; context = new Context(CONFIG_FILE); imageGenerator = new ImageGenerator(context); userGenerator = new UserGenerator(context); if (DRAW_SKELETON) { depthGenerator = new DepthGenerator(context); depthBitmap = new WriteableBitmap(640, 480, DPI_X, DPI_Y, PixelFormats.Rgb24, null); depthData = new DepthMetaData(); Histogram = new int[depthGenerator.DeviceMaxDepth]; skeletonDraw = new SkeletonDraw(); } poseDetectionCapability = userGenerator.PoseDetectionCapability; skeletonCapability = userGenerator.SkeletonCapability; imageBitmap = new WriteableBitmap(640, 480, DPI_X, DPI_Y, PixelFormats.Rgb24, null); imageData = new ImageMetaData(); Device.SetUp(); if (File.Exists(SpatialController.CALIBRATION_DATA_FILE)) { spatialController = new SpatialController(ControllerStartup.FromFile, userGenerator); } else { spatialController = new SpatialController(ControllerStartup.Calibrate, userGenerator); } spatialController.RecalibrateCommand += new RecalibrateEventHandler(RecalibrateCommand); userGenerator.NewUser += NewUser; userGenerator.LostUser += LostUser; skeletonCapability.CalibrationStart += CalibrationStart; skeletonCapability.CalibrationEnd += CalibrationEnd; skeletonCapability.SetSkeletonProfile(SkeletonProfile.All); poseDetectionCapability.PoseDetected += PoseDetected; poseDetectionCapability.PoseEnded += PoseEnded; kinectDataThread = new Thread(new ThreadStart(ReadKinectData)); kinectDataThread.IsBackground = true; checkGesturesThread = new Thread(new ThreadStart(CheckGestures)); checkGesturesThread.IsBackground = true; imageTimer = new DispatcherTimer(); imageTimer.Tick += new EventHandler(ImageTick); imageTimer.Interval = new TimeSpan(0, 0, 0, 0, 100); kinectDataThread.Start(); checkGesturesThread.Start(); imageTimer.Start(); UserPrompt.Write("Finished loading window."); Console.Write("Finished loading window"); UserPrompt.Write("Please assume the Psi pose and hold it until you see a skeleton overlaid" + " on the streaming video."); }