// 初期化 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]; }
// キーイベント private void xnKeyDown(Keys key) { // すべてを反転する if (key == Keys.M) { context.GlobalMirror = !context.GlobalMirror; } // イメージのみ反転する else if (key == Keys.I) { OpenNI.MirrorCapability mirror = image.MirrorCapability; mirror.SetMirror(!mirror.IsMirrored()); } // デプスのみ反転する else if (key == Keys.D) { OpenNI.MirrorCapability mirror = depth.MirrorCapability; mirror.SetMirror(!mirror.IsMirrored()); } }
// private ctor for singleton private OpenNIContext() { this.context = new Context(); if (null == context) { return; } if (oniFile != "") { context.OpenFileRecording(oniFile); } // NITE license from OpenNI.org License ll = new License(); ll.Key = "0KOIk2JeIBYClPWVnMoRKn5cdY4="; ll.Vendor = "PrimeSense"; context.AddLicense(ll); this.Depth = openNode(NodeType.Depth) as DepthGenerator; this.mirror = this.Depth.MirrorCapability; if (oniFile == "") { this.Mirror = true; } }
internal Generator(Context context, IntPtr pNode, bool addRef) : base(context, pNode, addRef) { this.generationRunningChanged = new StateChangedEvent(this, SafeNativeMethods.xnRegisterToGenerationRunningChange, SafeNativeMethods.xnUnregisterFromGenerationRunningChange); this.newDataAvailable = new StateChangedEvent(this, SafeNativeMethods.xnRegisterToNewDataAvailable, SafeNativeMethods.xnUnregisterFromNewDataAvailable); if(IsCapabilitySupported(Capabilities.AlternativeViewPoint)) m_alternativeViewpointCapability = new AlternativeViewpointCapability(this); else m_alternativeViewpointCapability = null; if(IsCapabilitySupported(Capabilities.FrameSync)) m_frameSyncCapability = new FrameSyncCapability(this); else m_frameSyncCapability = null; if (IsCapabilitySupported(Capabilities.Mirror)) m_mirrorCapability = new MirrorCapability(this); else m_mirrorCapability = null; }
internal Generator(Context context, IntPtr pNode, bool addRef) : base(context, pNode, addRef) { this.generationRunningChanged = new StateChangedEvent(this, SafeNativeMethods.xnRegisterToGenerationRunningChange, SafeNativeMethods.xnUnregisterFromGenerationRunningChange); this.newDataAvailable = new StateChangedEvent(this, SafeNativeMethods.xnRegisterToNewDataAvailable, SafeNativeMethods.xnUnregisterFromNewDataAvailable); if (IsCapabilitySupported(Capabilities.AlternativeViewPoint)) { m_alternativeViewpointCapability = new AlternativeViewpointCapability(this); } else { m_alternativeViewpointCapability = null; } if (IsCapabilitySupported(Capabilities.FrameSync)) { m_frameSyncCapability = new FrameSyncCapability(this); } else { m_frameSyncCapability = null; } if (IsCapabilitySupported(Capabilities.Mirror)) { m_mirrorCapability = new MirrorCapability(this); } else { m_mirrorCapability = null; } }
public void Awake() { Debug.Log("Initing OpenNI" + (LoadFromXML ? "(" + XMLFilename + ")" : "")); try { this.context = LoadFromXML ? new Context(XMLFilename) : new Context(); } catch (Exception ex) { Debug.LogError("Error opening OpenNI context: " + ex.Message); return; } // add license manually if not loading from XML if (!LoadFromXML) { License ll = new License(); ll.Key = LicenseKey; ll.Vendor = LicenseVendor; context.AddLicense(ll); } if (LoadFromRecording) { context.OpenFileRecordingEx(RecordingFilename); Player player = openNode(NodeType.Player) as Player; player.PlaybackSpeed = 0.0; StartCoroutine(ReadNextFrameFromRecording(player)); } this.Depth = openNode(NodeType.Depth) as DepthGenerator; this.mirrorCap = this.Depth.MirrorCapability; if (!LoadFromRecording) { this.mirrorCap.SetMirror(Mirror); mirrorState = Mirror; } }
/// @todo this is a temporary solution for capability not being disposed by anyone external public override void Dispose() { if (m_alternativeViewpointCapability != null) { m_alternativeViewpointCapability.InternalDispose(); m_alternativeViewpointCapability = null; } if (m_frameSyncCapability != null) { m_frameSyncCapability.InternalDispose(); m_frameSyncCapability = null; } if (m_mirrorCapability != null) { m_mirrorCapability.InternalDispose(); m_mirrorCapability = null; } base.Dispose(); }