Example #1
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     if (this.bodyFrameReader != null){
         this.bodyFrameReader.Dispose();
         this.bodyFrameReader = null;
     }
     if (this.kinectSensor != null){
         this.kinectSensor.Close();
         this.kinectSensor = null;
     }
     this.coordinateMapper = null;
     this.displayWidth = 0;
     this.displayHeight = 0;
     this.bodyFrameReader = null;
     this.bones = null;
     this.bodyColors = null;
     this.drawingGroup = null;
     this.imageSource = null;
     this.DataContext = null;
     this.scanType = ScanType.Arm;
     init();
     this.bodyFrameReader.FrameArrived += this.Reader_FrameArrived;
 }
Example #2
0
        public void init()
        {
            this.kinectSensor = KinectSensor.GetDefault();
            this.coordinateMapper = this.kinectSensor.CoordinateMapper;
         
            FrameDescription frameDescription =      this.kinectSensor.DepthFrameSource.FrameDescription;
            FrameDescription colorFrameDescription = this.kinectSensor.ColorFrameSource.FrameDescription;
            this.displayWidth = colorFrameDescription.Width;
            this.displayHeight = colorFrameDescription.Height;
            this.bitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
            this.bodyFrameReader =  this.kinectSensor.BodyFrameSource.OpenReader();
            this.colorFrameReader = this.kinectSensor.ColorFrameSource.OpenReader();

            if (this.bodyFrameReader != null)  this.bodyFrameReader.FrameArrived += this.Reader_FrameArrived;
            if (this.colorFrameReader != null) this.colorFrameReader.FrameArrived += this.ColorFrameReaderFrameArrived;
            this.bones = new List<Tuple<JointType, JointType>>();
            switch (scanType)
            {
                case ScanType.All:
                    Helpers.addJointTorso(this.bones);
                    Helpers.addJointArm(this.bones);
                    Helpers.addJointLeg(this.bones);
                break;
                case ScanType.Arm:
                Helpers.addJointArm(this.bones);
                break;
                case ScanType.LowerBody:
                Helpers.addJointLeg(this.bones);
                break;
                case ScanType.UpperBody:
                Helpers.addJointArm(this.bones);
                break;
                default:
                Helpers.addJointTorso(this.bones);
                Helpers.addJointArm(this.bones);
                Helpers.addJointLeg(this.bones);
                break;
            }
            this.bodyColors = new List<Pen>();
            this.bodyColors.Add(new Pen(Brushes.Red, 3));
            this.bodyColors.Add(new Pen(Brushes.Orange, 3));
            this.bodyColors.Add(new Pen(Brushes.Green, 3));
            this.bodyColors.Add(new Pen(Brushes.Blue, 3));
            this.bodyColors.Add(new Pen(Brushes.Indigo, 3));
            this.bodyColors.Add(new Pen(Brushes.Violet, 3));
            this.StatusText = this.kinectSensor.IsAvailable ? ProjectK.ErgoMC.Assessment.Properties.Resources.RunningStatusText : ProjectK.ErgoMC.Assessment.Properties.Resources.NoSensorStatusText;
            this.drawingGroup = new DrawingGroup();
            this.imageSource = new DrawingImage(this.drawingGroup);
            this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged;
            this.kinectSensor.OpenMultiSourceFrameReader(FrameSourceTypes.Body | FrameSourceTypes.BodyIndex | FrameSourceTypes.Color | FrameSourceTypes.Depth);
           
            this.kinectSensor.Open();
            this.DataContext = this;

        }