Inheritance: ObjectWrapper
        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 WebNect()
        {
            this.context = new OpenNI.Context(SAMPLE_XML_FILE);
            this.sessionManager = new NITE.SessionManager(this.context, "Click", "RaiseHand");
            this.context.StartGeneratingAll();

            this.sessionManager.SessionStart += new
                    EventHandler<NITE.PositionEventArgs>(sessionManager_SessionStart);
            this.sessionManager.SessionFocusProgress += new
                    EventHandler<NITE.SessionProgressEventArgs>(sessionManager_SessionProgress);
            this.sessionManager.SessionEnd += sessionManager_SessionEnd;

            this.waveDetector = new NITE.WaveDetector();
            this.waveDetector.Wave += waveDetector_Wave;
            this.waveDetector.PointUpdate += new EventHandler<HandEventArgs>(waveDetector_PointUpdate);
            this.sessionManager.AddListener(this.waveDetector);

            this.zmq_context = new ZMQ.Context(1);
            this.zmq_publisher = this.zmq_context.Socket(SocketType.PUB);
            this.zmq_publisher.Bind(this.SOCKET_SOURCE);
            Console.WriteLine("ZMQ Socket at {0}", this.SOCKET_SOURCE);

            this.shouldRun = true;
            this.readerThread = new Thread(ReaderThread);
            this.readerThread.Start();
        }
Ejemplo n.º 3
0
 internal Player(Context context, IntPtr nodeHandle, bool addRef)
     : base(context, nodeHandle, addRef)
 {
     this.endOfFileReachedEvent = new StateChangedEvent(this,
         SafeNativeMethods.xnRegisterToEndOfFileReached,
         SafeNativeMethods.xnUnregisterFromEndOfFileReached);
 }
        // 初期化
        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("ユーザー検出をサポートしていません");
              }
        }
Ejemplo n.º 5
0
        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]);
            }
        }
Ejemplo n.º 6
0
 internal DepthGenerator(Context context, IntPtr nodeHandle, bool addRef)
     : base(context, nodeHandle, addRef)
 {
     this.fovChanged = new StateChangedEvent(this,
         SafeNativeMethods.xnRegisterToDepthFieldOfViewChange,
         SafeNativeMethods.xnUnregisterFromDepthFieldOfViewChange);
 }
Ejemplo n.º 7
0
 private static IntPtr Create(Context context, CodecID codecID, ProductionNode initializer)
 {
     IntPtr nodeHandle;
     int status = SafeNativeMethods.xnCreateCodec(context.InternalObject, codecID.InternalValue, initializer.InternalObject, out nodeHandle);
     WrapperUtils.ThrowOnError(status);
     return nodeHandle;
 }
Ejemplo n.º 8
0
 internal ImageGenerator(Context context, IntPtr nodeHandle, bool addRef)
     : base(context, nodeHandle, addRef)
 {
     this.pixelFormatChanged = new StateChangedEvent(this,
         SafeNativeMethods.xnRegisterToPixelFormatChange,
         SafeNativeMethods.xnUnregisterFromPixelFormatChange);
 }
Ejemplo n.º 9
0
		private static IntPtr Create(Context context, string format)
		{
			IntPtr nodeHandle;
			int status = SafeNativeMethods.xnCreateScriptNode(context.InternalObject, format, out nodeHandle);
			WrapperUtils.ThrowOnError(status);
			return nodeHandle;
		}
Ejemplo n.º 10
0
 private static IntPtr Create(Context context, string name)
 {
     IntPtr handle;
     int status = SafeNativeMethods.xnCreateMockNode(context.InternalObject, NodeType.Image, name, out handle);
     WrapperUtils.ThrowOnError(status);
     return handle;
 }
Ejemplo n.º 11
0
        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 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();
        }
Ejemplo n.º 13
0
        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();
        }
Ejemplo n.º 14
0
 internal AudioGenerator(Context context, IntPtr nodeHandle, bool addRef)
     : base(context, nodeHandle, addRef)
 {
     this.outputModeChanged = new StateChangedEvent(this,
         SafeNativeMethods.xnRegisterToWaveOutputModeChanges,
         SafeNativeMethods.xnUnregisterFromWaveOutputModeChanges);
 }
Ejemplo n.º 15
0
 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);
 }
Ejemplo n.º 16
0
 internal Device(Context context, IntPtr nodeHandle, bool addRef)
     : base(context, nodeHandle, addRef)
 {
     if (IsCapabilitySupported(Capabilities.DeviceIdentification))
         m_deviceIdentification = new DeviceIdentificationCapability(this);
     else
         m_deviceIdentification = null;
 }
Ejemplo n.º 17
0
		private static IntPtr Create(Context context, Query query, EnumerationErrors errors)
		{
            IntPtr handle;
            int status = SafeNativeMethods.xnCreateDevice(context.InternalObject, out handle,
                query == null ? IntPtr.Zero : query.InternalObject,
                errors == null ? IntPtr.Zero : errors.InternalObject);
            WrapperUtils.ThrowOnError(status);
            return handle;
        }
Ejemplo n.º 18
0
        public DebugController(Context context, KinectUser user, IRenderEngine renderEngine)
        {
            _DepthGenerator = new DepthGenerator(context);

            this.User = user;
            this.RenderEngine = renderEngine;

            _DebugLines = new Dictionary<SkeletonJoint, ILine>();
        }
Ejemplo n.º 19
0
        internal GestureGenerator(Context context, IntPtr nodeHandle, bool addRef)
            : base(context, nodeHandle, addRef)
        {
            this.gestureChanged = new StateChangedEvent(this,
                SafeNativeMethods.xnRegisterToGestureChange,
                SafeNativeMethods.xnUnregisterFromGestureChange);

            this.internalGestureRecognized = new SafeNativeMethods.XnGestureRecognized(this.InternalGestureRecognized);
            this.internalGestureProgress = new SafeNativeMethods.XnGestureProgress(this.InternalGestureProgress);
        }
Ejemplo n.º 20
0
 private void Form1_Load(object sender, EventArgs e)
 {
     try {
         Context context = new Context();
         MessageBox.Show( "Success" );
     }
     catch (Exception ex) {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 21
0
        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 );
            }
        }
Ejemplo n.º 22
0
 internal DepthGenerator(Context context, IntPtr nodeHandle, bool addRef)
     : base(context, nodeHandle, addRef)
 {
     this.fovChanged = new StateChangedEvent(this,
         SafeNativeMethods.xnRegisterToDepthFieldOfViewChange,
         SafeNativeMethods.xnUnregisterFromDepthFieldOfViewChange);
     if (IsCapabilitySupported(Capabilities.UserPosition))
         m_userPositionCapability = new UserPositionCapability(this);
     else
         m_userPositionCapability = null;
 }
Ejemplo n.º 23
0
        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);
        }
Ejemplo n.º 24
0
        public OpenNIDataSourceFactory(string configFile)
        {
            if (!File.Exists(configFile))
            {
                throw new FileNotFoundException("Config file is missing: " + configFile);
            }
            ScriptNode node = null;
            this.context = Context.CreateFromXmlFile(configFile, out node);

            this.runner = new OpenNIRunner(this.context);
            this.runner.Start();
        }
        // 初期化
        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);
              }
        }
Ejemplo n.º 26
0
 public OpenNIRunner(Context context)
 {
     lock (typeof(OpenNIRunner))
     {
         if (existing)
         {
             throw new NotSupportedException("Only one instance of OpenNIRunner must exist");
         }
         existing = true;
     }
     this.context = context;
     this.generators = new ConcurrentBag<IGenerator>();
 }
Ejemplo n.º 27
0
		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;
        }
Ejemplo n.º 28
0
        public GestureController(IParkEngine parkEngine, ILogProvider logProvider, Context context)
        {
            this.ParkEngine = parkEngine;
            this.LogProvider = logProvider;

            _EventHandlers = new Dictionary<string, List<string>>();
            _ListenerLock = new object();

            _GestureGenerator = new GestureGenerator(context);
            _GestureGenerator.GestureRecognized += new EventHandler<GestureRecognizedEventArgs>(_GestureGenerator_GestureRecognized);
            _GestureGenerator.GestureProgress += new EventHandler<GestureProgressEventArgs>(_GestureGenerator_GestureProgress);
            _GestureGenerator.GestureChanged += new EventHandler(_GestureGenerator_GestureChanged);
            _GestureGenerator.StartGenerating();
        }
Ejemplo n.º 29
0
        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);
        }
        public DepthVideoController(Context kinectContext, ITextureController textureController)
        {
            this.Context = kinectContext;
            this.TextureController = textureController;

            _DepthGenerator = Context.FindExistingNode(NodeType.Depth) as DepthGenerator;

            if (_DepthGenerator == null)
            {
                throw new Exception("Viewer must have a depth node!");
            }

            _Histogram = new int[_DepthGenerator.DeviceMaxDepth];
            _Bitmap = new Bitmap((int)_DepthGenerator.MapOutputMode.XRes, (int)_DepthGenerator.MapOutputMode.YRes/*, System.Drawing.Imaging.PixelFormat.Format24bppRgb*/);
        }
Ejemplo n.º 31
0
        static void Main(string[] args)
        {
            try {
                // 設定ファイルのパス(環境に合わせて変更してください)
                string CONFIG_XML_PATH = @"../../../../../Data/SamplesConfig.xml";

                // XMLをファイルから設定情報を取得して初期化する
                Console.Write(@"Context.InitFromXmlFile ... ");
                ScriptNode     scriptNode;
                OpenNI.Context context = OpenNI.Context.CreateFromXmlFile(CONFIG_XML_PATH, out scriptNode);
                Console.WriteLine(@"Success");

                // ライセンス情報を取得する
                Console.Write(@"Context.EnumerateLicenses ... ");
                License[] licenses = context.EnumerateLicenses();
                Console.WriteLine(@"Success");

                foreach (License license in licenses)
                {
                    Console.WriteLine(license.Vendor + @", " + license.Key);
                }

                // 登録されたデバイスを取得する
                Console.Write(@"Context.EnumerateExistingNodes ... ");
                NodeInfoList nodeList = context.EnumerateExistingNodes();
                Console.WriteLine(@"Success");

                foreach (NodeInfo node in nodeList)
                {
                    // GetDescriptionの呼び出しで落ちる、、、
                    //Console.WriteLine(node.Description.Name + "," +
                    //                  node.Description.Vendor + "," +
                    //                  node.InstanceName + ",");
                    Console.WriteLine(node.InstanceName);
                }

                Console.WriteLine(@"Shutdown");
            }
            catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
        }