示例#1
0
        private Ray3D calibrateDeviceOnePosition(int user, byte device)
        {
            UserPrompt.Write("Turning on device " + device);

            Device.turnOn(device);
            Thread.Sleep(CALIBRATION_OFFSET_SEC * 1000);
            Vector3D[] headPoints      = new Vector3D[STEADY_SEC * SAMPLES_PER_SEC];
            Vector3D[] rightHandPoints = new Vector3D[STEADY_SEC * SAMPLES_PER_SEC];

            // Sample the user's hopefully steady hand.
            SkeletonJointPosition head      = new SkeletonJointPosition();
            SkeletonJointPosition rightHand = new SkeletonJointPosition();

            for (int i = 0; i < STEADY_SEC * SAMPLES_PER_SEC; i++)
            {
                head               = userGenerator.SkeletonCapability.GetSkeletonJointPosition(user, SkeletonJoint.Head);
                rightHand          = userGenerator.SkeletonCapability.GetSkeletonJointPosition(user, SkeletonJoint.RightHand);
                headPoints[i]      = new Vector3D(head.Position.X, head.Position.Y, head.Position.Z);
                rightHandPoints[i] = new Vector3D(rightHand.Position.X, rightHand.Position.Y, rightHand.Position.Z);
            }
            Thread.Sleep((CALIBRATION_SEC - STEADY_SEC - CALIBRATION_OFFSET_SEC) * 1000);

            // Take the averages of each side.
            Vector3D averageHeadPoint = new Vector3D(headPoints.Average(x => x.X),
                                                     headPoints.Average(x => x.Y), headPoints.Average(x => x.Z));
            Vector3D averageRightHandPoint = new Vector3D(rightHandPoints.Average(x => x.X),
                                                          rightHandPoints.Average(x => x.Y), rightHandPoints.Average(x => x.Z));

            UserPrompt.Write("Turning off device " + device);

            Device.turnOff(device);
            return(new Ray3D(averageHeadPoint, averageRightHandPoint));
        }
示例#2
0
 private void SpeakAndWriteToPrompt(String s)
 {
     UserPrompt.Write(s);
     synth.Speak(s);
 }
 public UserPrompt()
 {
     InitializeComponent();
     Active = this;
 }
        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.");
        }
        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.");
        }