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(); }
// 初期化 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("ユーザー検出をサポートしていません"); } }
// 初期化 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(); }
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 static IntPtr CreateBasedOn(ImageGenerator basedOn, string name) { IntPtr handle; int status = SafeNativeMethods.xnCreateMockNodeBasedOn(basedOn.Context.InternalObject, basedOn.InternalObject, name, out handle); WrapperUtils.ThrowOnError(status); return handle; }
private static IntPtr CreateBasedOn(ImageGenerator basedOn, string name) { IntPtr handle; int status = SafeNativeMethods.xnCreateMockNodeBasedOn(basedOn.Context.InternalObject, basedOn.InternalObject, name, out handle); WrapperUtils.ThrowOnError(status); return(handle); }
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() { // コンテキストの初期化 ... (1) ScriptNode scriptNode; context = Context.CreateFromXmlFile( CONFIG_XML_PATH, out scriptNode ); // イメージジェネレータの作成 ... (2) image = context.FindExistingNode(NodeType.Image) as ImageGenerator; if (image == null) { throw new Exception(context.GlobalErrorState); } }
public VideoController(Context kinectContext, ITextureController textureController) { this.Context = kinectContext; this.TextureController = textureController; _ImageGenerator = Context.FindExistingNode(NodeType.Image) as ImageGenerator; if (_ImageGenerator == null) { throw new Exception("Viewer must have an image node!"); } _Bitmap = new Bitmap((int)_ImageGenerator.MapOutputMode.XRes, (int)_ImageGenerator.MapOutputMode.YRes, System.Drawing.Imaging.PixelFormat.Format24bppRgb); }
// 初期化 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; 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 ); } }
private ProductionNode CreateProductionNodeObject(IntPtr nodeHandle, NodeType?type) { lock (this) { if (!this.allNodes.ContainsKey(nodeHandle)) { if (type == null) { IntPtr pNodeInfo = SafeNativeMethods.xnGetNodeInfo(nodeHandle); type = SafeNativeMethods.xnNodeInfoGetDescription(pNodeInfo).Type; } ProductionNode node; switch (type) { case NodeType.Device: node = new Device(this, nodeHandle, true); break; case NodeType.Depth: node = new DepthGenerator(this, nodeHandle, true); break; case NodeType.Image: node = new ImageGenerator(this, nodeHandle, true); break; case NodeType.Audio: node = new AudioGenerator(this, nodeHandle, true); break; case NodeType.IR: node = new IRGenerator(this, nodeHandle, true); break; case NodeType.User: node = new UserGenerator(this, nodeHandle, true); break; case NodeType.Recorder: node = new Recorder(this, nodeHandle, true); break; case NodeType.Player: node = new Player(this, nodeHandle, true); break; case NodeType.Gesture: node = new GestureGenerator(this, nodeHandle, true); break; case NodeType.Scene: node = new SceneAnalyzer(this, nodeHandle, true); break; case NodeType.Hands: node = new HandsGenerator(this, nodeHandle, true); break; case NodeType.Codec: node = new Codec(this, nodeHandle, true); break; case NodeType.ProductionNode: node = new ProductionNode(this, nodeHandle, true); break; case NodeType.Generator: node = new Generator(this, nodeHandle, true); break; case NodeType.MapGenerator: node = new MapGenerator(this, nodeHandle, true); break; case NodeType.ScriptNode: node = new ScriptNode(this, nodeHandle, true); break; default: throw new NotImplementedException("C# wrapper: Unknown generator type!"); } this.allNodes[nodeHandle] = node; } return(this.allNodes[nodeHandle]); } // lock }
// 初期化 private void xnInitialize() { // コンテキストの初期化 ScriptNode scriptNode; context = Context.CreateFromXmlFile( CONFIG_XML_PATH, out scriptNode ); // 鏡モード(反転)にしない context.GlobalMirror = false; // イメージジェネレータの作成 image = context.FindExistingNode(NodeType.Image) as ImageGenerator; if (image == null) { throw new Exception(context.GlobalErrorState); } // デプスジェネレータの作成 depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator; if (depth == null) { throw new Exception(context.GlobalErrorState); } // デプスの座標をイメージに合わせる depth.AlternativeViewpointCapability.SetViewpoint(image); // ジェスチャージェネレータの作成 gesture = context.FindExistingNode(NodeType.Gesture) as GestureGenerator; if (depth == null) { throw new Exception(context.GlobalErrorState); } // ジェスチャーの登録 gesture.AddGesture("RaiseHand"); // ジェスチャー用のコールバックを登録 gesture.GestureRecognized += new EventHandler<GestureRecognizedEventArgs>(gesture_GestureRecognized); gesture.GestureProgress += new EventHandler<GestureProgressEventArgs>(gesture_GestureProgress); // ハンドジェネレータの作成 hands = context.FindExistingNode(NodeType.Hands) as HandsGenerator; if (depth == null) { throw new Exception(context.GlobalErrorState); } // ハンドトラッキング用のコールバックを登録する hands.HandCreate += new EventHandler<HandCreateEventArgs>(hands_HandCreate); hands.HandUpdate += new EventHandler<HandUpdateEventArgs>(hands_HandUpdate); hands.HandDestroy += new EventHandler<HandDestroyEventArgs>(hands_HandDestroy); // ジェスチャーの検出開始 context.StartGeneratingAll(); }
// 初期化 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 MockImageGenerator(Context context, ImageGenerator basedOn, string name) : this(context, CreateBasedOn(basedOn, name), false) { }
public MockImageGenerator(Context context, ImageGenerator basedOn) : this(context, basedOn, null) { }
/// <summary> /// Throws ArgumentNullException on null context /// locates the given nodes and executes /// </summary> /// <param name="c"></param> public void InitializeCamera(Context c,ImageGenerator ig,DepthGenerator dg) { if (c == null) { throw new ArgumentNullException("Context empty"); } if (ig == null) { throw new ArgumentNullException("Image generator empty"); } if (dg == null) { throw new ArgumentNullException("Depth generator empty"); } Context = c; ImageGenerator = ig; DepthGenerator = dg; Histogram = new int[DepthGenerator.DeviceMaxDepth]; }
private ProductionNode CreateProductionNodeObject(IntPtr nodeHandle, NodeType? type) { lock (this) { if (!this.allNodes.ContainsKey(nodeHandle)) { if (type == null) { IntPtr pNodeInfo = SafeNativeMethods.xnGetNodeInfo(nodeHandle); type = NodeInfo.FromNative(pNodeInfo).Description.Type; } ProductionNode node; // start with concrete types if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Device)) { node = new Device(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Depth)) { node = new DepthGenerator(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Image)) { node = new ImageGenerator(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Audio)) { node = new AudioGenerator(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.IR)) { node = new IRGenerator(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.User)) { node = new UserGenerator(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Recorder)) { node = new Recorder(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Player)) { node = new Player(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Gesture)) { node = new GestureGenerator(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Scene)) { node = new SceneAnalyzer(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Hands)) { node = new HandsGenerator(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Codec)) { node = new Codec(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.ScriptNode)) { node = new ScriptNode(this, nodeHandle, true); } // move on to abstract types else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.MapGenerator)) { node = new MapGenerator(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Generator)) { node = new Generator(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.ProductionNode)) { node = new ProductionNode(this, nodeHandle, true); } else { throw new NotImplementedException("C# wrapper: Unknown generator type!"); } this.allNodes[nodeHandle] = node; } return this.allNodes[nodeHandle]; } // lock }
private void Initialise() { try { FMode = FPinInMode[0]; Size size = new Size(640, 480); if (FMode == ImageNodeMode.RGB) { FImageGenerator = new ImageGenerator(FState.Context); FImageImage.Image.Initialise(size, TColourFormat.RGB8); FState.DepthGenerator.AlternativeViewpointCapability.SetViewpoint(FImageGenerator); FImageGenerator.StartGenerating(); } else { FIRGenerator = new IRGenerator(FState.Context); FImageImage.Image.Initialise(size, TColourFormat.L16); FIRGenerator.StartGenerating(); } FImageDepth.Image.Initialise(size, TColourFormat.L16); FImageWorld.Image.Initialise(size, TColourFormat.RGB32F); FPinOutImageImage[0] = FImageImage.Link; FPinOutImageDepth[0] = FImageDepth.Link; FPinOutImageWorld[0] = FImageWorld.Link; for (int x = 0; x < 640; x++) for (int y = 0; y < 480; y++) { FProjective[x + y * 640].X = x; FProjective[x + y * 640].Y = y; } FState.Update += new EventHandler(FState_Update); FStatus = "OK"; } catch (StatusException e) { FStatus = e.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); // ジェスチャージェネレータの作成 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(); }
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."); }
//called when data for any output pin is requested public void Evaluate(int SpreadMax) { if (FPinInContext[0] != FContext) { FContext = FPinInContext[0]; } if (FContext == null) { FRunning = false; return; } if (FContext.running && !FRunning && FContext.context != null) { try { FImageGenerator = FContext.context.FindExistingNode(global::OpenNI.NodeType.Image) as ImageGenerator; FDepthGenerator = FContext.context.FindExistingNode(global::OpenNI.NodeType.Depth) as DepthGenerator; FDepthGenerator.AlternativeViewpointCapability.SetViewpoint(FImageGenerator); FImageRGB = new ImageRGB(); FImageDepth = new ImageL16(); FImageWorld = new ImageRGB32F(); Size size = new Size(640, 480); FImageRGBBuffer = new Image<Bgr, byte>(size); FImageDepthBuffer = new Image<Gray,ushort>(size); FImageWorldBuffer = new Image<Rgb, float>(size); FPinOutRGB[0] = FImageRGB; FPinOutDepth[0] = FImageDepth; FPinOutWorld[0] = FImageWorld; FThread = new Thread(fnThread); FRunning = true; FThread.Start(); FPinOutStatus[0] = "OK"; } catch (StatusException e) { FRunning = false; FPinOutStatus[0] = e.Message; } } }
// 初期化 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(); }
public NuiSensor(Context c, ImageGenerator ig, DepthGenerator dg) { InitializeCamera(c,ig,dg); InitializeBitmaps(); InitializeThread(); }
public Sensor(string config) { if (string.IsNullOrEmpty(config)) throw new ArgumentNullException(); try { _context = Context.CreateFromXmlFile(config, out _scriptNode); _depthGenerator = _context.FindExistingNode(NodeType.Depth) as DepthGenerator; _imageGenerator = _context.FindExistingNode(NodeType.Image) as ImageGenerator; _userGenerator = _context.FindExistingNode(NodeType.User) as UserGenerator; if (_depthGenerator == null) throw new ApplicationException("No depth node found."); if (_imageGenerator == null) throw new ApplicationException("No image node found."); if (_userGenerator == null) throw new ApplicationException("No user node found."); if (_depthGenerator.MapOutputMode.FPS != _imageGenerator.MapOutputMode.FPS) throw new ApplicationException("Depth and image node must have common framerates."); if (_depthGenerator.MapOutputMode.XRes != _imageGenerator.MapOutputMode.XRes) throw new ApplicationException("Depth and image node must have common horizontal resolutions."); if (_depthGenerator.MapOutputMode.YRes != _imageGenerator.MapOutputMode.YRes) throw new ApplicationException("Depth and image node must have common vertical resolutions."); _depthMetaData = new DepthMetaData(); _imageMetaData = new ImageMetaData(); _imageWidth = _depthGenerator.MapOutputMode.XRes; _imageHeight = _depthGenerator.MapOutputMode.YRes; _userGenerator.NewUser += new EventHandler<NewUserEventArgs>(_userGenerator_NewUser); _userGenerator.LostUser += new EventHandler<UserLostEventArgs>(_userGenerator_LostUser); _userGenerator.StartGenerating(); _bitmapGenerator = new BitmapGenerator(this); _readerWaitHandle = new AutoResetEvent(false); _readerThread = new Thread(delegate() { try { while (_run) { if (_pause) _readerWaitHandle.WaitOne(); _context.WaitAndUpdateAll(); _depthGenerator.GetMetaData(_depthMetaData); _imageGenerator.GetMetaData(_imageMetaData); if (_depthMetaData.XRes != _imageWidth || _imageMetaData.XRes != _imageWidth) throw new ApplicationException("Image width must not change."); if (_depthMetaData.YRes != _imageHeight || _imageMetaData.YRes != _imageHeight) throw new ApplicationException("Image height must not change."); if (GeneratorUpdate != null) GeneratorUpdate(this, EventArgs.Empty); } } catch (ThreadInterruptedException) { Console.WriteLine("Reader thread interrupted."); } catch (Exception e) { throw new ApplicationException("Error while processing sensor data.", e); } }) { Name = "ONI Reader Thread" }; } catch (Exception) { throw; } }
private string InitialiseImage() { string messages = ""; MapOutputMode imageMode = new MapOutputMode(); imageMode.XRes = FSize.Width; imageMode.YRes = FSize.Height; imageMode.FPS = 30; if (Mode == ImageNodeMode.RGB) { if (FIRGenerator != null) { FIRGenerator.StopGenerating(); FIRGenerator.Dispose(); } FRGBGenerator = new ImageGenerator(FState.Context); FRGBGenerator.MapOutputMode = imageMode; Image.Image.Initialise(FSize, TColorFormat.RGB8); if (FState.DepthGenerator.AlternativeViewpointCapability.IsViewpointSupported(FRGBGenerator)) { FState.DepthGenerator.AlternativeViewpointCapability.SetViewpoint(FRGBGenerator); } else { messages += "AlternativeViewportCapability not supported\n"; } FRGBGenerator.StartGenerating(); } else { if (FRGBGenerator != null) { FRGBGenerator.StopGenerating(); FRGBGenerator.Dispose(); } FIRGenerator = new IRGenerator(FState.Context); FIRGenerator.MapOutputMode = imageMode; FIRGenerator.StartGenerating(); Image.Image.Initialise(FSize, TColorFormat.L16); } return messages; }
// 初期化 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); }
// 初期化 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]; }
public void StartViewer(Context c, ImageGenerator ig, DepthGenerator dg) { _sensor = new Nui.NuiSensor(); //_sensor. //TODO }
private ProductionNode CreateProductionNodeObject(IntPtr nodeHandle, NodeType? type) { lock (this) { if (!this.allNodes.ContainsKey(nodeHandle)) { if (type == null) { IntPtr pNodeInfo = SafeNativeMethods.xnGetNodeInfo(nodeHandle); type = NodeInfo.FromNative(pNodeInfo).Description.Type; } ProductionNode node; switch (type) { case NodeType.Device: node = new Device(this, nodeHandle, true); break; case NodeType.Depth: node = new DepthGenerator(this, nodeHandle, true); break; case NodeType.Image: node = new ImageGenerator(this, nodeHandle, true); break; case NodeType.Audio: node = new AudioGenerator(this, nodeHandle, true); break; case NodeType.IR: node = new IRGenerator(this, nodeHandle, true); break; case NodeType.User: node = new UserGenerator(this, nodeHandle, true); break; case NodeType.Recorder: node = new Recorder(this, nodeHandle, true); break; case NodeType.Player: node = new Player(this, nodeHandle, true); break; case NodeType.Gesture: node = new GestureGenerator(this, nodeHandle, true); break; case NodeType.Scene: node = new SceneAnalyzer(this, nodeHandle, true); break; case NodeType.Hands: node = new HandsGenerator(this, nodeHandle, true); break; case NodeType.Codec: node = new Codec(this, nodeHandle, true); break; case NodeType.ProductionNode: node = new ProductionNode(this, nodeHandle, true); break; case NodeType.Generator: node = new Generator(this, nodeHandle, true); break; case NodeType.MapGenerator: node = new MapGenerator(this, nodeHandle, true); break; case NodeType.ScriptNode: node = new ScriptNode(this, nodeHandle, true); break; default: throw new NotImplementedException("C# wrapper: Unknown generator type!"); } this.allNodes[nodeHandle] = node; } return this.allNodes[nodeHandle]; } // lock }
// 初期化 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(); }
// 初期化 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 ProductionNode CreateProductionNodeObject(IntPtr nodeHandle, NodeType?type) { lock (this) { if (!this.allNodes.ContainsKey(nodeHandle)) { if (type == null) { IntPtr pNodeInfo = SafeNativeMethods.xnGetNodeInfo(nodeHandle); type = NodeInfo.FromNative(pNodeInfo).Description.Type; } ProductionNode node; // start with concrete types if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Device)) { node = new Device(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Depth)) { node = new DepthGenerator(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Image)) { node = new ImageGenerator(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Audio)) { node = new AudioGenerator(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.IR)) { node = new IRGenerator(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.User)) { node = new UserGenerator(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Recorder)) { node = new Recorder(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Player)) { node = new Player(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Gesture)) { node = new GestureGenerator(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Scene)) { node = new SceneAnalyzer(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Hands)) { node = new HandsGenerator(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Codec)) { node = new Codec(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.ScriptNode)) { node = new ScriptNode(this, nodeHandle, true); } // move on to abstract types else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.MapGenerator)) { node = new MapGenerator(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Generator)) { node = new Generator(this, nodeHandle, true); } else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.ProductionNode)) { node = new ProductionNode(this, nodeHandle, true); } else { throw new NotImplementedException("C# wrapper: Unknown generator type!"); } this.allNodes[nodeHandle] = node; } return(this.allNodes[nodeHandle]); } // lock }