public MainWindow() { InitializeComponent(); this.context = Context.CreateFromXmlFile(SAMPLE_XML_FILE, out scriptNode); 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 = 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.All); this.joints = new Dictionary<int,Dictionary<SkeletonJoint,SkeletonJointPosition>>(); this.userGenerator.StartGenerating(); this.histogram = new int[this.depth.DeviceMaxDepth]; MapOutputMode mapMode = this.depth.MapOutputMode; this.bitmap = new Bitmap((int)mapMode.XRes, (int)mapMode.YRes/*, System.Drawing.Imaging.PixelFormat.Format24bppRgb*/); this.shouldRun = true; this.readerThread = new Thread(ReaderThread); this.readerThread.Start(); }
public UserGenerator(Context context, IntPtr nodeHandle, bool addRef) : base(context, nodeHandle, addRef) { this.internalNewUser = new SafeNativeMethods.XnUserHandler(this.InternalNewUser); this.internalLostUser = new SafeNativeMethods.XnUserHandler(this.InternalLostUser); this.internalUserExit = new SafeNativeMethods.XnUserHandler(this.InternalUserExit); this.internalUserReEnter = new SafeNativeMethods.XnUserHandler(this.InternalUserReEnter); if (IsCapabilitySupported(Capabilities.Skeleton)) m_skeletonCapability = new SkeletonCapability(this); else m_skeletonCapability = null; if (IsCapabilitySupported(Capabilities.PoseDetection)) m_poseDetectionCapability = new PoseDetectionCapability(this); else m_poseDetectionCapability = null; }
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() { try { _context = new Context(@"..\..\Data\openniconfig.xml"); _depth_generator = _context.FindExistingNode(NodeType.Depth) as DepthGenerator; if (_depth_generator == null) throw new Exception(@"Error in Data\openniconfig.xml - No depth node found."); _user_generator = new UserGenerator(_context); _skeleton_caps = _user_generator.SkeletonCapability; _pose_detect_caps = _user_generator.PoseDetectionCapability; _calibration_pose = _skeleton_caps.CalibrationPose; // event handler for detection _user_generator.NewUser += (_user_generator_NewUser); _user_generator.LostUser += (_user_generator_LostUser); _pose_detect_caps.PoseDetected += (_pose_detect_caps_PoseDetected); _skeleton_caps.CalibrationEnd += (_skeleton_caps_CalibrationEnd); _skeleton_caps.SetSkeletonProfile(SkeletonProfile.All); // initialize joints _joints = new Dictionary<int, Dictionary<SkeletonJoint, SkeletonJointPosition>>(); _joint_orientation = new Dictionary<int, Dictionary<SkeletonJoint, SkeletonJointOrientation>>(); // start generating data _user_generator.StartGenerating(); }catch(Exception ex) { Console.WriteLine("Error initializing OpenNi."); Console.WriteLine(ex.Message); } // update timer for the depth image DispatcherTimer dispatcher_timer = new DispatcherTimer(); dispatcher_timer.Tick += new EventHandler(dispatcher_timer_Tick); dispatcher_timer.Interval = new TimeSpan(0, 0, 0, 0, 10); // update every 10 ms dispatcher_timer.Start(); Console.WriteLine("Finished loading"); }
public UserController(Context context, string calibrationPath) { this.Context = context; this.CalibrationPath = calibrationPath; this.Users = new Dictionary<int, KinectUser>(); _UserLock = new object(); _SkeletonLock = new object(); _UserGenerator = new UserGenerator(Context); _SkeletonCapability = _UserGenerator.SkeletonCapability; _PoseDetectionCapability = _UserGenerator.PoseDetectionCapability; _CalibrationPose = _SkeletonCapability.CalibrationPose; _UserGenerator.NewUser += new EventHandler<NewUserEventArgs>(_UserGenerator_NewUser); _UserGenerator.LostUser += new EventHandler<UserLostEventArgs>(_UserGenerator_LostUser); _PoseDetectionCapability.PoseDetected += new EventHandler<PoseDetectedEventArgs>(PoseDetectionCapability_PoseDetected); _SkeletonCapability.CalibrationComplete += new EventHandler<CalibrationProgressEventArgs>(_SkeletonCapability_CalibrationComplete); _SkeletonCapability.SetSkeletonProfile(SkeletonProfile.All); _UserGenerator.StartGenerating(); }
public UserGenerator(Context context, IntPtr nodeHandle, bool addRef) : base(context, nodeHandle, addRef) { this.internalNewUser = new SafeNativeMethods.XnUserHandler(this.InternalNewUser); this.internalLostUser = new SafeNativeMethods.XnUserHandler(this.InternalLostUser); this.internalUserExit = new SafeNativeMethods.XnUserHandler(this.InternalUserExit); this.internalUserReEnter = new SafeNativeMethods.XnUserHandler(this.InternalUserReEnter); if (IsCapabilitySupported(Capabilities.Skeleton)) { m_skeletonCapability = new SkeletonCapability(this); } else { m_skeletonCapability = null; } if (IsCapabilitySupported(Capabilities.PoseDetection)) { m_poseDetectionCapability = new PoseDetectionCapability(this); } else { m_poseDetectionCapability = null; } }
/// <summary> /// Loads all 3D joint positions for a specific user. /// </summary> /// <exception cref="ArgumentException">Thrown if the target dictionary /// does not contain 3d data.</exception> protected void GetJoints3D(SkeletonCapability source, int user, JointDictionary target) { if (!target.Is3DData) throw new ArgumentException("Trying to load 3d data to a non 3D JointDictionary."); for (int i = 0; i < JointDictionary.JointTranslationList.Count; i++) { GetJoint3D(source, user, JointDictionary.JointTranslationList[i].joint_type, target); } }
/// <summary> /// Loads all 2D joint positions for a specific user. /// </summary> protected void GetJoints(SkeletonCapability source, int user, Dictionary<SkeletonJoint, SkeletonJointPosition> target) { for (int i = 0; i < JointDictionary.JointTranslationList.Count; i++) { GetJoint(source, user, JointDictionary.JointTranslationList[i].joint_type, target); } }
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"); }
// 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; }
private void VerifyInit() { if (context != null) { return; } string initFile = @"data/openni.xml"; bool isInit = false; while (!isInit) { try { context = new Context(initFile); isInit = true; } catch (StatusException ex) { Trace.WriteLine("OpenNI StatusException: " + ex.ToString()); isInit = false; Thread.Sleep(1000); } catch (GeneralException ex) { Trace.WriteLine("GeneralException: " + ex.ToString()); isInit = false; IsGeneratorThreadRunning = false; return; } } this.joints = new Dictionary<int, Dictionary<SkeletonJoint, SkeletonJointPosition>>(); this.userGenerator = new UserGenerator(this.context); this.skeletonCapability = userGenerator.SkeletonCapability; this.poseDetectionCapability = userGenerator.PoseDetectionCapability; this.calibPose = this.skeletonCapability.CalibrationPose; 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.skeletonCapability.CalibrationEnd += new EventHandler<CalibrationEndEventArgs>(skeletonCapability_CalibrationEnd); this.skeletonCapability.SetSkeletonProfile(SkeletonProfile.Upper); this.userGenerator.StartGenerating(); depthGenerator = context.FindExistingNode(NodeType.Depth) as DepthGenerator; depthGenerator.NewDataAvailable += new EventHandler(depthGenerator_NewDataAvailable); this.histogram = new int[depthGenerator.DeviceMaxDepth]; depthGenerator.StartGenerating(); }
/// @todo this is a temporary solution for capability not being disposed by anyone external public override void Dispose() { if (m_skeletonCapability != null) { m_skeletonCapability.InternalDispose(); m_skeletonCapability = null; } if (m_poseDetectionCapability != null) { m_poseDetectionCapability.InternalDispose(); m_poseDetectionCapability = null; } base.Dispose(); }
void Start() { InitializeCharacter (); context = new Context (XML_SETUP_FILE); sessionManager = new SessionManager(context, "Wave", "RaiseHand"); depthGenerator = context.FindExistingNode(NodeType.Depth) as DepthGenerator; handsGenerator = context.FindExistingNode(NodeType.Hands) as HandsGenerator; //image = context.FindExistingNode(NodeType.Image) as ImageGenerator; //gesture = context.FindExistingNode(NodeType.Gesture) as GestureGenerator; if (depthGenerator == null) throw new Exception("Viewer must have a depth node!"); //if (gesture == null) throw new Exception("Viewer must have a gesture node!"); //if (image == null) throw new Exception("Viewer must have a image node!"); userGenerator = new UserGenerator (context); skeletonCapability = userGenerator.SkeletonCapability; poseDetectionCapability = userGenerator.PoseDetectionCapability; calibPose = skeletonCapability.CalibrationPose; //gestureGenerator = new GestureGenerator(context); foreach (String s in poseDetectionCapability.GetAllAvailablePoses()) Debug.LogWarning("available pose found: " +s); //foreach (String s in gestureGenerator.EnumerateAllGestures()) // Debug.LogWarning("available gesture found: " + s); //gestureGenerator.GestureRecognized += HandleGestureGestureRecognized; //gesture.AddGesture("Click"); //gestureGenerator.AddGesture("RaiseHand"); //seems buggy //gestureGenerator.AddGesture("Wave"); swipeDetector = new SwipeDetector(); //steadyDetector = new SteadyDetector();//(3, 1f); //swipeDetector.SwipeLeft += HandleSwipeDetectorSwipeLeft; //Session Managment sessionManager.SessionStart += HandleSessionManagerSessionStart; sessionManager.SessionEnd += HandleSessionManagerSessionEnd; //User Generator userGenerator.NewUser += HandleUserGeneratorNewUser; userGenerator.LostUser += HandleUserGeneratorLostUser; poseDetectionCapability.PoseDetected += HandlePoseDetectionCapabilityPoseDetected; skeletonCapability.CalibrationEnd += HandleSkeletonCapabilityCalibrationEnd; skeletonCapability.SetSkeletonProfile (SkeletonProfile.All); skeletonCapability.SetSmoothing(.5f); // give us some smooothing //Start generating userGenerator.StartGenerating(); //handsGenerator.MirrorCapability.SetMirror(true); // TODO: should this be true? handsGenerator.StartGenerating(); //gestureGenerator.StartGenerating(); //slider selector //selectableSlider2D = new SelectableSlider2D(Screen.width, Screen.height); //selectableSlider2D.ValueChange += HandleSelectableSlider2DValueChange; //selectableSlider2D.ItemHover += HandleSelectableSlider2DItemHover; //selectableSlider2D.ItemSelect += HandleSelectableSlider2DItemSelect; pointDenoiser = new PointDenoiser(); pointDenoiser.AddListener(swipeDetector); //pointDenoiser.AddListener(steadyDetector); //pointDenoiser.AddListener(selectableSlider2D); //flowRouter = new FlowRouter(); //flowRouter.ActiveListener = pointDenoiser; sessionManager.AddListener(pointDenoiser); MapOutputMode mapMode = depthGenerator.MapOutputMode; // Init depth & label map related stuff usersMapSize = mapMode.XRes * mapMode.YRes; //usersLabelTexture = new Texture2D(mapMode.XRes, mapMode.YRes); //nonPOT slow usersLabelTexture = new Texture2D(1024,512); //speed up by using power of two and then setpixel() with blockwidth (640) and blockheight (480) usersMapColors = new Color[usersMapSize]; usersMapRect = new Rect(Screen.width - usersLabelTexture.width / 2, Screen.height - usersLabelTexture.height / 2, usersLabelTexture.width / 2, usersLabelTexture.height / 2); usersLabelMap = new short[usersMapSize]; usersDepthMap = new short[usersMapSize]; usersHistogramMap = new float[5000]; this.shouldRun = true; if (NiteInitializingEvent != null) //notify others that we're done initializing NiteInitializingEvent(this, EventArgs.Empty); }
private void Initialize() { ScriptNode scriptNode; this.context = Context.CreateFromXmlFile(SAMPLE_XML_FILE, out scriptNode); 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 = this.userGenerator.SkeletonCapability; this.userGenerator.NewUser += this.OnUserGeneratorNewUser; this.userGenerator.LostUser += this.OnUserGeneratorLostUser; this.skeletonCapbility.CalibrationComplete += this.OnSkeletonCapbilityCalibrationComplete; this.skeletonCapbility.SetSkeletonProfile(SkeletonProfile.All); this.joints = new Dictionary<int, Dictionary<SkeletonJoint, SkeletonJointPosition>>(); this.userGenerator.StartGenerating(); }
/// <summary> /// Creates a new instance of SensorData with the specified configuration file. /// </summary> /// <param name="configuration">Configuration file path.</param> public SensorData(string configuration) { InitializeCamera(configuration); InitializeBitmaps(); InitializeThread(); //New flow router this.flowRouter = new NITE.FlowRouter(); this.boxes = new MyBox("Box1"); this.boxes.Leave += new MyBox.LeaveHandler(boxes_Leave); this.boxes.Update += new MyBox.UpdateHandler(boxes_Update); this.sessionManager.AddListener(this.flowRouter); this.sessionManager.SessionStart += new EventHandler<NITE.PositionEventArgs>(sessionManager_SessionStart); Console.WriteLine("Initialized Sensor Data"); this.DepthGenerator.AlternativeViewpointCapability.SetViewpoint(this.ImageGenerator); this.userGenerator = new UserGenerator(this.Context); this.skeletonCapbility = this.userGenerator.SkeletonCapability; this.poseDetectionCapability = this.userGenerator.PoseDetectionCapability; this.calibPose = this.skeletonCapbility.CalibrationPose; this.poseDetectionCapability.PoseDetected += poseDetectionCapability_PoseDetected; this.skeletonCapbility.CalibrationComplete += skeletonCapbility_CalibrationComplete; this.skeletonCapbility.SetSkeletonProfile(SkeletonProfile.All); this.joints = new Dictionary<int, Dictionary<SkeletonJoint, SkeletonJointPosition>>(); this.userGenerator.NewUser += userGenerator_NewUser; this.userGenerator.LostUser += userGenerator_LostUser; this.userGenerator.StartGenerating(); }
// 初期化 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.OutOfPose += new EventHandler<OutOfPoseEventArgs>( poseDetect_OutOfPose ); } // キャリブレーションのコールバックを登録 skelton.CalibrationStart += new EventHandler<CalibrationStartEventArgs>(skelton_CalibrationStart); skelton.CalibrationComplete += new EventHandler<CalibrationProgressEventArgs>( skelton_CalibrationComplete ); // すべてをトラッキングする skelton.SetSkeletonProfile(SkeletonProfile.All); // ジェスチャーの検出開始 context.StartGeneratingAll(); }
//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) && (FUserIdIn != 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 = 0; FStatusOut.SliceCount = 0; FJointPositionOut.SliceCount = 0; FJointOrientationXOut.SliceCount = 0; FJointOrientationYOut.SliceCount = 0; FJointOrientationZOut.SliceCount = 0; if (FUserGenerator.NumberOfUsers > 0) { //get all Users and sort them int[] users = FUserGenerator.GetUsers(); FUserIdOut.SliceCount = users.Length; FStatusOut.SliceCount = users.Length; Array.Sort(users); for (int i = 0; i<users.Length; i++) { int userId = users[i]; bool userIsTracked = FSkeletonCapability.IsTracking(userId); bool userIsCalibrated = FSkeletonCapability.IsCalibrated(userId); bool userIsCalibrating = FSkeletonCapability.IsCalibrating(userId); if(userIsTracked) FStatusOut[i] = "Tracking user "; else if(userIsCalibrating) FStatusOut[i] = "Calibrating user "; else FStatusOut[i] = "Looking for pose on user "; FStatusOut[i] += userId.ToString(); FUserIdOut[i] = userId; //if((userId != FUserIdIn[0]) && (!userIsTracked)) FSkeletonCapability.StopTracking(userId); if(FUserIdIn.IsChanged && (userId != FUserIdIn[0])) { //if(!userIsTracked) FSkeletonCapability.StartTracking(userId); } } //for if(FSkeletonCapability.IsTracking(FUserIdIn[0])) { int binSize = FJointIn.SliceCount; FJointPositionOut.SliceCount = binSize; FJointOrientationXOut.SliceCount = FJointOrientationYOut.SliceCount = FJointOrientationZOut.SliceCount = binSize; for (int i = 0; i < binSize; i++) { var j = GetJoint(FUserIdIn[0], FJointIn[i]); var p = j.Position.Position; if (j.Position.Confidence >= FConfidenceIn[0]) FJointPositionOut[i] = new Vector3D(p.X, p.Y, p.Z) / 1000; var o = j.Orientation; if (o.Confidence > FConfidenceIn[0]) { FJointOrientationXOut[i] = new Vector3D(o.X1, o.Y1, o.Z1); FJointOrientationYOut[i] = new Vector3D(o.X2, o.Y2, o.Z2); FJointOrientationZOut[i] = new Vector3D(o.X3, o.Y3, o.Z3); } } } } } } else { FUserIdOut.SliceCount = 0; FStatusOut.SliceCount = 0; FJointPositionOut.SliceCount = 0; FJointOrientationXOut.SliceCount = 0; FJointOrientationYOut.SliceCount = 0; FJointOrientationZOut.SliceCount = 0; } }
private void Window_Initialized(object sender, EventArgs e) { string configPath = Properties.Settings.Default.ONIConfig; Title += " - " + configPath; try { if (!File.Exists(configPath)) throw new ApplicationException("Config file '" + configPath + "' does not exist."); _labelDataBrush = Resources["labelData"] as ImageBrush; _skeletonDrawer = new SkeletonDrawer(depthGrid); _skeleton = new Dictionary<int, Dictionary<SkeletonJoint, SkeletonJointPosition>>(); _sensor = new Sensor(configPath); Console.WriteLine("Sensor initialized successfully."); _skeletonCapability = _sensor.UserGenerator.SkeletonCapability; _skeletonCapability.SetSkeletonProfile(SkeletonProfile.All); _skeletonCapability.SetSmoothing(Properties.Settings.Default.SkeletonSmoothing); _sensor.GeneratorUpdate += delegate(object s, EventArgs args) { Action action = () => { _labelDataBrush.ImageSource = _sensor.LabelBitmap; depthImage.Source = _sensor.DepthBitmap; rgbImage.Source = _sensor.RGBBitmap; if (Properties.Settings.Default.DisplaySkeleton && _skeleton.Count > 0) { var users = _skeleton.Keys; Func<int, SkeletonJoint, SkeletonJointPosition> jointPosition = (int user, SkeletonJoint joint) => { SkeletonJointPosition position = _skeletonCapability.GetSkeletonJointPosition(user, joint); if (position.Position.Z == 0) position.Confidence = 0; else position.Position = _sensor.DepthGenerator.ConvertRealWorldToProjective(position.Position); return position; }; foreach (int user in users) { _skeleton[user][SkeletonJoint.Head] = jointPosition(user, SkeletonJoint.Head); _skeleton[user][SkeletonJoint.Neck] = jointPosition(user, SkeletonJoint.Neck); _skeleton[user][SkeletonJoint.Torso] = jointPosition(user, SkeletonJoint.Torso); _skeleton[user][SkeletonJoint.LeftShoulder] = jointPosition(user, SkeletonJoint.LeftShoulder); _skeleton[user][SkeletonJoint.LeftElbow] = jointPosition(user, SkeletonJoint.LeftElbow); _skeleton[user][SkeletonJoint.LeftHand] = jointPosition(user, SkeletonJoint.LeftHand); _skeleton[user][SkeletonJoint.RightShoulder] = jointPosition(user, SkeletonJoint.RightShoulder); _skeleton[user][SkeletonJoint.RightElbow] = jointPosition(user, SkeletonJoint.RightElbow); _skeleton[user][SkeletonJoint.RightHand] = jointPosition(user, SkeletonJoint.RightHand); _skeleton[user][SkeletonJoint.LeftHip] = jointPosition(user, SkeletonJoint.LeftHip); _skeleton[user][SkeletonJoint.LeftKnee] = jointPosition(user, SkeletonJoint.LeftKnee); _skeleton[user][SkeletonJoint.LeftFoot] = jointPosition(user, SkeletonJoint.LeftFoot); _skeleton[user][SkeletonJoint.RightHip] = jointPosition(user, SkeletonJoint.RightHip); _skeleton[user][SkeletonJoint.RightKnee] = jointPosition(user, SkeletonJoint.RightKnee); _skeleton[user][SkeletonJoint.RightFoot] = jointPosition(user, SkeletonJoint.RightFoot); } _skeletonDrawer.Draw(_skeleton); } }; Dispatcher.Invoke(action); }; _sensor.NewUser += delegate(object s, NewUserEventArgs args) { Console.WriteLine("[" + args.ID + "] Found"); if(Properties.Settings.Default.DisplaySkeleton) _skeletonCapability.RequestCalibration(args.ID, true); }; _sensor.LostUser += delegate(object s, UserLostEventArgs args) { Console.WriteLine("[" + args.ID + "] Lost"); _skeleton.Remove(args.ID); Action action = () => { _skeletonDrawer.UserLost(args.ID); }; Dispatcher.Invoke(action); }; _skeletonCapability.CalibrationComplete += delegate(object s, CalibrationProgressEventArgs args) { Console.WriteLine("[" + args.ID + "] Calibration status: " + args.Status); if (args.Status == CalibrationStatus.OK) { _skeletonCapability.StartTracking(args.ID); Dictionary<SkeletonJoint, SkeletonJointPosition> jointPositions = new Dictionary<SkeletonJoint, SkeletonJointPosition>(); jointPositions.Add(SkeletonJoint.Head, new SkeletonJointPosition()); jointPositions.Add(SkeletonJoint.Neck, new SkeletonJointPosition()); jointPositions.Add(SkeletonJoint.Torso, new SkeletonJointPosition()); jointPositions.Add(SkeletonJoint.LeftShoulder, new SkeletonJointPosition()); jointPositions.Add(SkeletonJoint.LeftElbow, new SkeletonJointPosition()); jointPositions.Add(SkeletonJoint.LeftHand, new SkeletonJointPosition()); jointPositions.Add(SkeletonJoint.RightShoulder, new SkeletonJointPosition()); jointPositions.Add(SkeletonJoint.RightElbow, new SkeletonJointPosition()); jointPositions.Add(SkeletonJoint.RightHand, new SkeletonJointPosition()); jointPositions.Add(SkeletonJoint.LeftHip, new SkeletonJointPosition()); jointPositions.Add(SkeletonJoint.LeftKnee, new SkeletonJointPosition()); jointPositions.Add(SkeletonJoint.LeftFoot, new SkeletonJointPosition()); jointPositions.Add(SkeletonJoint.RightHip, new SkeletonJointPosition()); jointPositions.Add(SkeletonJoint.RightKnee, new SkeletonJointPosition()); jointPositions.Add(SkeletonJoint.RightFoot, new SkeletonJointPosition()); _skeleton.Add(args.ID, jointPositions); } else if (args.Status != CalibrationStatus.ManualAbort) _skeletonCapability.RequestCalibration(args.ID, true); }; } catch (Exception ex) { Console.Error.WriteLine(ex); MessageBox.Show(ex.Message, "Error while initializing OpenNI", MessageBoxButton.OK, MessageBoxImage.Error); Application.Current.Shutdown(); } }
/// <summary> /// Loads the 3D data for a specific skeleton joint. /// </summary> private void GetJoint3D(SkeletonCapability source, int user, SkeletonJoint joint, JointDictionary target) { SkeletonJointPosition pos; if (joint == SkeletonJoint.Waist) { // Calculate the joint position as arithmetic mean of right // and left hip joints, as it is not possible to poll it // directly. pos = new SkeletonJointPosition(); SkeletonJointPosition posLeft = source.GetSkeletonJointPosition(user, SkeletonJoint.LeftHip); SkeletonJointPosition posRight = source.GetSkeletonJointPosition(user, SkeletonJoint.RightHip); if (posLeft.Position.Z == 0 || posRight.Position.Z == 0) { pos.Confidence = 0; pos.Position = new Point3D( (posLeft.Position.X + posRight.Position.X) / 2, (posLeft.Position.Y + posRight.Position.Y) / 2, 0); } else { pos.Confidence = Math.Min(posLeft.Confidence, posRight.Confidence); pos.Position = new Point3D( (posLeft.Position.X + posRight.Position.X) / 2, (posLeft.Position.Y + posRight.Position.Y) / 2, (posLeft.Position.Z + posRight.Position.Z) / 2); } } else { pos = source.GetSkeletonJointPosition(user, joint); if (pos.Position.Z == 0) { pos.Confidence = 0; } } target[joint] = pos; }
/* 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>>(); // }
// Use this for initialization void Start() { Debug.Log("Start"); //Inicializar variables para kinect this.context=Context.CreateFromXmlFile(XML_CONFIG,out scriptNode); 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; //inicializando variables de characterController controller=GetComponent<CharacterController>(); //asignando handlers this.userGenerator.NewUser+=userGenerator_NewUser; this.userGenerator.LostUser+=userGenerator_LostUser; this.poseDetectionCapability.PoseDetected+=poseDetectionCapability_PoseDetected; this.skeletonCapability.CalibrationComplete+=skeletonCapability_CalibrationComplete; //inicializando el user generator this.skeletonCapability.SetSkeletonProfile(SkeletonProfile.All); this.userGenerator.StartGenerating(); this.shouldRun=true; }
/// <summary> /// Creates a new instance of SensorData with the specified configuration file. /// </summary> /// <param name="configuration">Configuration file path.</param> public HandTracker(string configuration) { InitializeCamera(configuration); InitializeBitmaps(); InitializeThread(); this.DepthGenerator.AlternativeViewpointCapability.SetViewpoint(this.ImageGenerator); this.userGenerator = new UserGenerator(this.Context); this.skeletonCapbility = this.userGenerator.SkeletonCapability; this.poseDetectionCapability = this.userGenerator.PoseDetectionCapability; this.calibPose = this.skeletonCapbility.CalibrationPose; this.poseDetectionCapability.PoseDetected += poseDetectionCapability_PoseDetected; this.skeletonCapbility.CalibrationComplete += skeletonCapbility_CalibrationComplete; this.skeletonCapbility.SetSkeletonProfile(SkeletonProfile.All); this.joints = new Dictionary<int, Dictionary<SkeletonJoint, SkeletonJointPosition>>(); this.sessionManager = new NITE.SessionManager(this.Context, "Wave,Click", "RaiseHand"); _handsGenerator = new HandsGenerator(Context); _handsGenerator.SetSmoothing(0.1f); _gestureGenerator = new GestureGenerator(Context); this.Context.StartGeneratingAll(); Console.WriteLine("Start Generating All"); pointControl = new PointControl("PointTracker"); pointControl.PointCreate += new EventHandler<HandEventArgs>(pointControl_PointCreate); pointControl.PointUpdate += new EventHandler<HandEventArgs>(pointControl_PointUpdate); pointControl.PointDestroy += new EventHandler<IdEventArgs>(pointControl_PointDestroy); sessionManager.AddListener(pointControl); this.userGenerator.NewUser += userGenerator_NewUser; this.userGenerator.LostUser += userGenerator_LostUser; this.userGenerator.StartGenerating(); }
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."); }