// 初期化 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); // レコーダーの作成と記録対象の追加 recoder = new OpenNI.Recorder(context); recoder.SetDestination(RecordMedium.File, RECORD_PATH); recoder.AddNodeToRecording(image); recoder.AddNodeToRecording(depth); recoder.Record(); }
// 初期化 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("ユーザー検出をサポートしていません"); } }
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 ); } }
public MainWindow() { InitializeComponent(); try { // ContextとImageGeneratorの作成 ScriptNode node; context = Context.CreateFromXmlFile( "../../SamplesConfig.xml", out node ); context.GlobalMirror = false; image = context.FindExistingNode( NodeType.Image ) as ImageGenerator; // ユーザーの作成 user = new UserGenerator( context ); context.StartGeneratingAll(); // 画像更新のためのスレッドを作成 shouldRun = true; readerThread = new Thread( new ThreadStart( ReaderThread ) ); readerThread.Start(); } catch ( Exception ex ) { MessageBox.Show( ex.Message ); } }
private void InitOpenNI() { // ContextとImageGeneratorの作成 ScriptNode node; context = Context.CreateFromXmlFile( "SamplesConfig.xml", out node ); context.GlobalMirror = false; image = context.FindExistingNode( NodeType.Image ) as ImageGenerator; // 画像更新のためのスレッドを作成 shouldRun = true; readerThread = new Thread( new ThreadStart( () => { while ( shouldRun ) { context.WaitAndUpdateAll(); ImageMetaData imageMD = image.GetMetaData(); // ImageMetaDataをBitmapSourceに変換する(unsafeにしなくてもOK!!) this.Dispatcher.BeginInvoke( DispatcherPriority.Background, new Action( () => { imageOpenNI.Source = BitmapSource.Create( imageMD.XRes, imageMD.YRes, 96, 96, PixelFormats.Rgb24, null, imageMD.ImageMapPtr, imageMD.DataSize, imageMD.XRes * imageMD.BytesPerPixel ); } ) ); } } ) ); readerThread.Start(); }
static void Run() { string SAMPLE_XML_FILE = @"../../../../Data/SamplesConfig.xml"; Context context = new Context(SAMPLE_XML_FILE); DepthGenerator depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator; if (depth == null) { Console.WriteLine("Sample must have a depth generator!"); return; } MapOutputMode mapMode = depth.MapOutputMode; DepthMetaData depthMD = new DepthMetaData(); Console.WriteLine("Press any key to stop..."); while (!Console.KeyAvailable) { context.WaitOneUpdateAll(depth); depth.GetMetaData(depthMD); Console.WriteLine("Frame {0} Middle point is: {1}.", depthMD.FrameID, depthMD[(int)mapMode.XRes/2, (int)mapMode.YRes/2]); } }
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 HandSensor(Context context) { this.context = context; gestureGenerator = context.FindExistingNode(NodeType.Gesture) as GestureGenerator; handsGenerator = context.FindExistingNode(NodeType.Hands) as HandsGenerator; gestureGenerator.GestureRecognized += new EventHandler<GestureRecognizedEventArgs>(gestureGenerator_GestureRecognized); handsGenerator.HandCreate += new EventHandler<HandCreateEventArgs>(handsGenerator_HandCreate); handsGenerator.HandDestroy += new EventHandler<HandDestroyEventArgs>(handsGenerator_HandDestroy); handsGenerator.HandUpdate += new EventHandler<HandUpdateEventArgs>(handsGenerator_HandUpdate); handsGenerator.StartGenerating(); gestureGenerator.AddGesture("Wave"); string[] s = gestureGenerator.EnumerateAllGestures(); Trace.WriteLine("HandSensor initialized"); }
// 初期化 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); } }
public MainWindow() { InitializeComponent(); try { // ContextとImageGeneratorの作成 ScriptNode node; context = Context.CreateFromXmlFile( "../../SamplesConfig.xml", out node ); context.GlobalMirror = false; image = context.FindExistingNode( NodeType.Image ) as ImageGenerator; audio = context.FindExistingNode( NodeType.Audio ) as AudioGenerator; wavePlayer = new StreamingWavePlayer( audio.WaveOutputMode.SampleRate, audio.WaveOutputMode.BitsPerSample, audio.WaveOutputMode.Channels, 100 ); // 画像更新のためのスレッドを作成 shouldRun = true; readerThread = new Thread( new ThreadStart( () => { while ( shouldRun ) { context.WaitAndUpdateAll(); ImageMetaData imageMD = image.GetMetaData(); // WAVEデータの出力 wavePlayer.Output( audio.AudioBufferPtr, audio.DataSize ); // ImageMetaDataをBitmapSourceに変換する(unsafeにしなくてもOK!!) this.Dispatcher.BeginInvoke( DispatcherPriority.Background, new Action( () => { image1.Source = BitmapSource.Create( imageMD.XRes, imageMD.YRes, 96, 96, PixelFormats.Rgb24, null, imageMD.ImageMapPtr, imageMD.DataSize, imageMD.XRes * imageMD.BytesPerPixel ); } ) ); } } ) ); readerThread.Start(); } catch ( Exception ex ) { MessageBox.Show( ex.Message ); } }
public MainWindow() { InitializeComponent(); try { // OpenNIの初期化 ScriptNode node; context = Context.CreateFromXmlFile("../../SamplesConfig.xml", out node); context.GlobalMirror = false; // depthの作成 depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator; // ユーザーの作成 user = new UserGenerator(context); // ポーズが必要な場合は、最新版を入れてもらう if (user.SkeletonCapability.DoesNeedPoseForCalibration) { throw new Exception("最新のOpenNIをインストールしてください"); } // ユーザー検出、キャリブレーション完了のイベントを登録する user.NewUser += new EventHandler<NewUserEventArgs>(user_NewUser); user.SkeletonCapability.CalibrationComplete += new EventHandler<CalibrationProgressEventArgs>(SkeletonCapability_CalibrationComplete); // すべての骨格を追跡する user.SkeletonCapability.SetSkeletonProfile(SkeletonProfile.All); // 動作を開始する context.StartGeneratingAll(); // 画像更新のためのスレッドを作成 shouldRun = true; readerThread = new Thread(new ThreadStart(ReaderThread)); readerThread.Start(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//Constructor Method //Starts up necessary files to take data Kinect() { //Sets locations of XML File string SAMPLE_XML_FILE = @"C:\Users\CenSISS\Documents\Kinect Project\SamplesConfig.xml"; //Declares object of ScriptNode and defines context ScriptNode scriptNode; context = Context.CreateFromXmlFile(SAMPLE_XML_FILE, out scriptNode); //Declares the depth generator DepthGenerator depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator; //If the depth generator does not exist returns error messag if (depth == null) { Console.WriteLine("Sample must have a depth generator!"); Console.ReadLine(); return; } }
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 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.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(); }
// 初期化 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); throw new Exception("イメージジェネレータの作成に失敗"); } cropping.Enabled= false; cropping.XOffset = 0; cropping.YOffset = 0; cropping.XSize = 500; cropping.YSize = 450; }
public MainWindow() { InitializeComponent(); try { // ContextとImageGeneratorの作成 ScriptNode node; context = Context.CreateFromXmlFile( "SamplesConfig.xml", out node ); context.GlobalMirror = false; depth = context.FindExistingNode( NodeType.Depth ) as DepthGenerator; // 画像更新のためのスレッドを作成 shouldRun = true; readerThread = new Thread( new ThreadStart( () => { while ( shouldRun ) { context.WaitAndUpdateAll(); DepthMetaData depthMD = depth.GetMetaData(); // ImageMetaDataをBitmapSourceに変換する(unsafeにしなくてもOK!!) this.Dispatcher.BeginInvoke( DispatcherPriority.Background, new Action( () => { Int16[] depthArray = new Int16[depthMD.XRes * depthMD.YRes]; Marshal.Copy( depthMD.DepthMapPtr, depthArray, 0, depthArray.Length ); for ( int i = 0; i < depthArray.Length; i++ ) { depthArray[i] = (Int16)(0xffff - (0xffff * depthArray[i] / depth.DeviceMaxDepth)); } image1.Source = BitmapSource.Create( depthMD.XRes, depthMD.YRes, 96, 96, PixelFormats.Gray16, null, depthArray, depthMD.XRes * depthMD.BytesPerPixel ); } ) ); } } ) ); readerThread.Start(); } catch ( Exception ex ) { MessageBox.Show( ex.Message ); } }
//Starts up necessary files to take data //Must run before TakeData() Kinect() { //Sets locations of XML File string SAMPLE_XML_FILE = @"..\\..\\..\\SamplesConfig.xml"; //Declares object of ScriptNode and defines context ScriptNode scriptNode; context = Context.CreateFromXmlFile(SAMPLE_XML_FILE, out scriptNode); //Declares the depth generator depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator; //If the depth generator does not exist returns error messag if (depth == null) { Console.WriteLine("Sample must have a depth generator!"); Console.ReadLine(); return; } //Declares necessary variables and classes to take depth //DepthGenerator depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator; mapMode = depth.MapOutputMode; depthMD = new DepthMetaData(); }
// 初期化 private void xnInitialize() { // コンテキストの初期化 context = new Context(); // OpenFileRecordingExを使うように促されるが、使用するとアクセスバイオレーションになる context.OpenFileRecording(RECORD_PATH); // プレーヤーの作成 player = context.FindExistingNode(NodeType.Player) as OpenNI.Player; if (player == null) { throw new Exception(context.GlobalErrorState); } // 終端に達したら通知するコールバックを登録する player.EndOfFileReached += new EventHandler(player_EndOfFileReached); // イメージジェネレータの作成 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); } // ヒストグラムバッファの作成 histogram = new int[depth.DeviceMaxDepth]; }
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(); }
// 初期化 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); } // ビューポイントが変更されたことを通知するコールバックを登録する AlternativeViewpointCapability Viewpoint = depth.AlternativeViewpointCapability; Viewpoint.ViewpointChanged += new EventHandler(Viewpoint_ViewpointChanged); // ビューポイントのサポート状態を確認する if (!Viewpoint.IsViewpointSupported(image)) { throw new Exception("ビューポイントをサポートしていません"); } // 現在の状態を取得する isViewpoint = Viewpoint.IsViewpointAs(image); // ヒストグラムバッファの作成 histogram = new int[depth.DeviceMaxDepth]; }
// 初期化 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); // ジェスチャージェネレータの作成 gesture = context.FindExistingNode(NodeType.Gesture) as GestureGenerator; if (depth == null) { throw new Exception(context.GlobalErrorState); } // ジェスチャーの作成と登録 gestures = gesture.EnumerateAllGestures(); gesture.AddGesture(gestures[gestureIndex]); string[] activeGestures = gesture.GetAllActiveGestures(); // ジェスチャーの機能確認 foreach (string name in gestures) { Trace.WriteLine(name + ":" + "Available:" + gesture.IsGestureAvailable(name) + " ProgressSupported:" + gesture.IsGestureProgressSupported(name)); } // ジェスチャー用のコールバックを登録 gesture.GestureRecognized += new EventHandler<GestureRecognizedEventArgs>(gesture_GestureRecognized); gesture.GestureProgress += new EventHandler<GestureProgressEventArgs>(gesture_GestureProgress); gesture.GestureChanged += new EventHandler(gesture_GestureChanged); // ジェスチャーの検出開始 context.StartGeneratingAll(); }
// 初期化 private void xnInitialize() { // コンテキストの初期化 context = new Context(CONFIG_XML_PATH); // イメージジェネレータの作成 image = context.FindExistingNode(NodeType.Image) as ImageGenerator; if (image == null) { throw new Exception(context.GlobalErrorState); } // NITEのためのセッションマネージャを作成 sessionManager = new SessionManager(context, "Wave,Click", "RaiseHand"); // セッションの開始と終了を通知するコールバックを登録する sessionManager.SessionStart += new EventHandler<PositionEventArgs>(sessionManager_SessionStart); sessionManager.SessionEnd += new EventHandler(sessionManager_SessionEnd); sessionManager.SessionFocusProgress += new EventHandler<SessionProgressEventArgs>(sessionManager_SessionFocusProgress); // Push(前後運動の検出器) pushDetector = new NITE.PushDetector(); pushDetector.Push += new EventHandler<VelocityAngleEventArgs>(pushDetector_Push); // リスナーに追加する sessionManager.AddListener(pushDetector); // ジェネレータの動作を開始する context.StartGeneratingAll(); }
public void SetupScanner(string Config) { lock (this) { try { this.context = Context.CreateFromXmlFile(Config, out scriptNode); this.GDepth = context.FindExistingNode(NodeType.Depth) as DepthGenerator; this.GImage = context.FindExistingNode(NodeType.Image) as ImageGenerator; if (this.GDepth == null) { throw new Exception("Viewer must have a depth node!"); } if (this.GImage == null) { throw new Exception("3D Scanner must have a image node!"); } MapOutputMode mapMode = this.GDepth.MapOutputMode; configurated = true; } catch (Exception e) { LOG.Instance.publishMessage("ERROR : " + e.Message + " " + e.InnerException); configurated = false; } } }
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(); }
// 初期化 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); // カメラ画像の // ミラー状態が変更されたことを通知するコールバックを登録 // ミラー状態の取得 OpenNI.MirrorCapability imageMirror = image.MirrorCapability; imageMirror.MirrorChangedEvent += new EventHandler(Form1_MirrorChangedEvent); mirrorState.Add(image.ToString(), imageMirror.IsMirrored()); // デプスの // ミラー状態が変更されたことを通知するコールバックを登録 // ミラー状態の取得 OpenNI.MirrorCapability depthMirror = depth.MirrorCapability; depthMirror.MirrorChangedEvent += new EventHandler(Form1_MirrorChangedEvent); mirrorState.Add(depth.ToString(), depthMirror.IsMirrored()); // ヒストグラムバッファの作成 histogram = new int[depth.DeviceMaxDepth]; }
public MainWindow() { InitializeComponent(); history = new Dictionary<int, List<Point3D>>(); //MessageBox.Show("test"); 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!"); } //--- OpenNI Generators this.gestureGenerator = new GestureGenerator(this.context); this.gestureGenerator.AddGesture("Wave"); this.gestureGenerator.AddGesture("Click"); this.gestureGenerator.GestureRecognized += new EventHandler<GestureRecognizedEventArgs>(gestureGenerator_GestureRecognized); this.handsGenerator = new HandsGenerator(this.context); this.handsGenerator.HandCreate += new EventHandler<HandCreateEventArgs>(handsGenerator_HandCreate); this.handsGenerator.HandUpdate += new EventHandler<HandUpdateEventArgs>(handsGenerator_HandUpdate); this.handsGenerator.HandDestroy += new EventHandler<HandDestroyEventArgs>(handsGenerator_HandDestroy); if (smoothMouseMovement) this.handsGenerator.SetSmoothing(smoothingValue); //--- OpenNI Generators /* //--- NITE Generators sessionManager = new SessionManager(context, "Click", "RaiseHand"); sessionManager.SessionStart += new EventHandler<PositionEventArgs>(sessionManager_SessionStart); sessionManager.SessionEnd += new System.EventHandler(sessionManager_SessionEnd); myControl = new PointControl(); myControl.PrimaryPointUpdate += new System.EventHandler<HandEventArgs>(myControl_PrimaryPointUpdate); myControl.PrimaryPointCreate += new System.EventHandler<HandFocusEventArgs>(myControl_PrimaryPointCreate); myControl.PrimaryPointDestroy += new System.EventHandler<IdEventArgs>(myControl_PrimaryPointDestroy); sessionManager.AddListener(myControl); //--- NITE Generators */ this.context.StartGeneratingAll(); this.histogram = new int[this.depth.DeviceMaxDepth]; MapOutputMode mapMode = this.depth.MapOutputMode; /* * Create the directory for the recorded frames */ if (this.captureFrames) { String subDir = DateTime.Now.ToString().Replace("/", "-").Replace(" ", "_").Replace(":", "-"); this.frameDir = System.IO.Path.Combine("C:/GoogleDrive/opsei/kinect/src/misc/frames/", subDir); System.IO.Directory.CreateDirectory(frameDir); } stopwatch = new Stopwatch(); this.fingersDetectedHistory = new int[fingersDetectedHistorySize]; this.hullRatios = new double[3]; this.mouseHistoryX = new double[mouseHistorySize]; this.mouseHistoryY = new double[mouseHistorySize]; this.palmPositionXHistory = new double[palmHistorySize]; this.palmPositionYHistory = new double[palmHistorySize]; this.palmPositionZHistory = new double[palmHistorySize]; this.startClickLag = false; this.minFingerDistance = 120; this.frame = 0; this.bitmap = new Bitmap((int)mapMode.XRes, (int)mapMode.YRes); this.shouldRun = true; this.readerThread = new Thread(ReaderThread); this.readerThread.Start(); }
// 初期化 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); } // NITEのためのセッションマネージャを作成 sessionManager = new NITE.SessionManager(context, "Wave,Click", "RaiseHand"); // セッションの開始と終了を通知するコールバックを登録する sessionManager.SessionStart += new EventHandler<PositionEventArgs>(sessionManager_SessionStart); sessionManager.SessionEnd += new EventHandler(sessionManager_SessionEnd); sessionManager.SessionFocusProgress += new EventHandler<SessionProgressEventArgs>(sessionManager_SessionFocusProgress); }
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; }
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; }