public MainWindow() { InitializeComponent(); try { // ContextとImageGeneratorの作成 ScriptNode node; context = Context.CreateFromXmlFile( "../../SamplesConfig.xml", out node ); context.GlobalMirror = true; image = context.FindExistingNode( NodeType.Image ) as ImageGenerator; depth = context.FindExistingNode( NodeType.Depth ) as DepthGenerator; depth.AlternativeViewpointCapability.SetViewpoint( image ); // ユーザーの作成 user = context.FindExistingNode( NodeType.User ) as UserGenerator; // ユーザー認識のコールバックを登録 user.NewUser += new EventHandler<NewUserEventArgs>( user_NewUser ); //キャリブレーションにポーズが必要か確認 if ( user.SkeletonCapability.DoesNeedPoseForCalibration ) { // ポーズ検出のサポートチェック if ( !user.IsCapabilitySupported( "User::PoseDetection" ) ) { throw new Exception( "ポーズ検出をサポートしていません" ); } // ポーズ検出のコールバックを登録 user.PoseDetectionCapability.PoseDetected += new EventHandler<PoseDetectedEventArgs>( poseDetect_PoseDetected ); } // スケルトン検出機能をサポートしているか確認 if ( !user.IsCapabilitySupported( "User::Skeleton" ) ) { throw new Exception( "ユーザー検出をサポートしていません" ); } // キャリブレーションのコールバックを登録 user.SkeletonCapability.CalibrationEnd += new EventHandler<CalibrationEndEventArgs>( skelton_CalibrationEnd ); // すべてをトラッキングする user.SkeletonCapability.SetSkeletonProfile( SkeletonProfile.HeadAndHands ); // ジェスチャーの検出開始 context.StartGeneratingAll(); // 画像更新のためのスレッドを作成 shouldRun = true; readerThread = new Thread( new ThreadStart( ReaderThread ) ); readerThread.Start(); } catch ( Exception ex ) { MessageBox.Show( ex.Message ); } }
// 初期化 private void xnInitialize() { // コンテキストの初期化 ScriptNode scriptNode; context = Context.CreateFromXmlFile( CONFIG_XML_PATH, out scriptNode ); // イメージジェネレータの作成 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); }
// 初期化 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(); }
// 初期化 private void xnInitialize() { // コンテキストの初期化 ScriptNode scriptNode; context = Context.CreateFromXmlFile( CONFIG_XML_PATH, out scriptNode ); // イメージジェネレータの作成 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("ユーザー検出をサポートしていません"); } // 背景イメージを作成 MapOutputMode mapMode = image.MapOutputMode; background = new Bitmap((int)mapMode.XRes, (int)mapMode.YRes, System.Drawing.Imaging.PixelFormat.Format24bppRgb); }