Esempio n. 1
0
        public Xtion()
        {
            Trace.WriteLine( Assembly.GetExecutingAssembly().FullName );

            context = new Context();
            context.GlobalMirror = true;

            Image = new ImageGenerator( context );
            Image.NewDataAvailable += new EventHandler( ImageGenrator_NewDataAvailable );
            Image.MapOutputMode = new MapOutputMode()
            {
                XRes = Width,
                YRes = Height,
                FPS = FPS
            };

            Depth = new DepthGenerator( context );
            Depth.NewDataAvailable += new EventHandler( DepthGenerator_NewDataAvailable );
            Depth.MapOutputMode = new MapOutputMode()
            {
                XRes = Width,
                YRes = Height,
                FPS = FPS
            };

            User = new UserGenerator( context );
            User.NewUser += new EventHandler<NewUserEventArgs>( UserGenerator_NewUser );
            User.LostUser += new EventHandler<UserLostEventArgs>( UserGenerator_LostUser );
            User.UserExit += new EventHandler<UserExitEventArgs>( UserGenerator_UserExit );
            User.UserReEnter += new EventHandler<UserReEnterEventArgs>( UserGenerator_UserReEnter );

            User.NewDataAvailable += new EventHandler( UserGenerator_NewDataAvailable );

            Skeleton = User.SkeletonCapability;
            if ( Skeleton.DoesNeedPoseForCalibration ) {
                throw new Exception( "OpenNI 1.4.0.2 以降をインストールしてください" );
            }

            Skeleton.CalibrationComplete += new EventHandler<CalibrationProgressEventArgs>( Skeleton_CalibrationComplete );
            Skeleton.SetSkeletonProfile( SkeletonProfile.HeadAndHands );
            Skeleton.SetSmoothing( 0.7f );

            // 画像更新のためのスレッドを作成
            shouldRun = true;
            readerThread = new Thread( new ThreadStart( () =>
            {
                while ( shouldRun ) {
                    context.WaitAndUpdateAll();
                }
            } ) );
            readerThread.Start();

            context.StartGeneratingAll();
        }
 public static Point3D ScaleTo( this Point3D point, DepthGenerator depth, int width, int height )
 {
     return new Point3D( (point.X * width) / depth.MapOutputMode.XRes, (point.Y * height) / depth.MapOutputMode.YRes, point.Z );
 }