private void Window_Loaded(object sender, RoutedEventArgs e) { //haarCascade = new HaarCascade(@"haarcascade_frontalface_alt_tree.xml"); _sensor = KinectSensor.GetDefault(); //music load player.Open(new Uri(@"Resources\res_music\Happy Background Music.mp3", UriKind.Relative)); //player.Open(new Uri(@"Resources\res_music\Jesu Joy of Mans Desiring.mp3", UriKind.Relative));//右側屬性要記得改成copy always player.Play(); player.MediaEnded += Player_MediaEnded; if (_sensor != null) //當取得 sensor 之後 { _sensor.Open(); //開啟 //Initialize the background removal tool. //_bgRemovalHelper = new BgRemoveHelper(_sensor.CoordinateMapper); _bgRemovalHelper = new BackgroundRemovalTool(_sensor.CoordinateMapper); _reader = _sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Color | FrameSourceTypes.Depth | FrameSourceTypes.BodyIndex | FrameSourceTypes.Body); _reader.MultiSourceFrameArrived += Reader_MultiSourceFrameArrived; FrameDescription frameDescription = _sensor.ColorFrameSource.FrameDescription; displayWidth = frameDescription.Width; displayHeight = frameDescription.Height; displayRect = new Rect(0, 0, displayWidth, displayHeight); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { //haarCascade = new HaarCascade(@"haarcascade_frontalface_alt_tree.xml"); _sensor = KinectSensor.GetDefault(); if (_sensor != null) //當取得 sensor 之後 { _sensor.Open(); //開啟 //Initialize the background removal tool. //_bgRemovalHelper = new BgRemoveHelper(_sensor.CoordinateMapper); _bgRemovalHelper = new BackgroundRemovalTool(_sensor.CoordinateMapper); _reader = _sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Color | FrameSourceTypes.Depth | FrameSourceTypes.BodyIndex | FrameSourceTypes.Body); _reader.MultiSourceFrameArrived += Reader_MultiSourceFrameArrived; FrameDescription frameDescription = _sensor.ColorFrameSource.FrameDescription; displayWidth = frameDescription.Width; displayHeight = frameDescription.Height; displayRect = new Rect(0, 0, displayWidth, displayHeight); bodyFrameReader = _sensor.BodyFrameSource.OpenReader(); bodyFrameReader.FrameArrived += bodyFrameReader_FrameArrived; bodyCount = _sensor.BodyFrameSource.BodyCount; bodies = new Body[bodyCount]; InitializeFace(); } }