public void measureAngles(Skeleton skeleton) { if (skeleton.TrackingState == SkeletonTrackingState.Tracked) { //todo: all tracking states double kneeAngle = 0, bodyAngle = 0, headAngle = 0; double sidewaysRatio = 0, spinalRatio = 0; if (skeleton.Joints[JointType.AnkleRight].TrackingState == JointTrackingState.Tracked || skeleton.Joints[JointType.AnkleRight].TrackingState == JointTrackingState.Inferred) { kneeAngle = AngleHelper.measureAngle2D(skeleton.Joints[JointType.AnkleRight], skeleton.Joints[JointType.KneeRight], skeleton.Joints[JointType.HipRight]); kneeAngleText.Text = kneeAngle.ToString(); } if (skeleton.Joints[JointType.HipCenter].TrackingState == JointTrackingState.Tracked) { bodyAngle = AngleHelper.measureVerticalDerivationAngle(skeleton.Joints[JointType.HipCenter], skeleton.Joints[JointType.ShoulderCenter]); bodyAngleText.Text = bodyAngle.ToString(); //spine distance currentSpinaelDistance = AngleHelper.getLengthOfLineBetween2D(skeleton.Joints[JointType.HipCenter], skeleton.Joints[JointType.ShoulderCenter]); spinalRatio = DistanceRatioHelper.distanceRatio(idealSpinalDistance, currentSpinaelDistance); spinalRatioText.Text = spinalRatio.ToString(); } if (skeleton.Joints[JointType.ShoulderCenter].TrackingState == JointTrackingState.Tracked) { headAngle = AngleHelper.measureVerticalDerivationAngle(skeleton.Joints[JointType.ShoulderCenter], skeleton.Joints[JointType.Head]); headAngleText.Text = headAngle.ToString(); //sideways distance currentHipShoulderZDistance = AngleHelper.getZDistance(skeleton.Joints[JointType.ShoulderRight], skeleton.Joints[JointType.HipCenter]); sidewaysRatio = DistanceRatioHelper.distanceRatio(idealHipShoulderZDistance, currentHipShoulderZDistance); sidewaysRatioText.Text = sidewaysRatio.ToString(); } postureInfoText.Text = WrongPostureClassifier.postureToString( WrongPostureClassifier.diagnozeWrongPosture(kneeAngle, bodyAngle, headAngle, spinalRatio, sidewaysRatio)); //if (kneeAngle < 100) //{ // controlError.Fill = new SolidColorBrush(Color.FromRgb(255, 0, 0)); //} //else //{ // controlError.Fill = new SolidColorBrush(Color.FromRgb(0, 255, 0)); //} } }
private void InitializeKinectSensor(KinectSensor sensor) { if (kinect != null) { ColorImageStream colorStream = kinect.ColorStream; colorStream.Enable(); this.colorImageBitmap = new WriteableBitmap(colorStream.FrameWidth, colorStream.FrameHeight, 96, 96, PixelFormats.Bgr32, null); this.colorImageBitmapRect = new Int32Rect(0, 0, colorStream.FrameWidth, colorStream.FrameHeight); this.colorImageStride = colorStream.FrameWidth * colorStream.FrameBytesPerPixel; //initialize drawing this.drawingGroupColor = new DrawingGroup(); this.imageSourceColor = new DrawingImage(this.drawingGroupColor); SkeletonColorOverlappingImage.Source = this.imageSourceColor; DepthImageStream depthStream = kinect.DepthStream; depthStream.Enable(); this.depthImageBitmap = new WriteableBitmap(depthStream.FrameWidth, depthStream.FrameHeight, 96, 96, PixelFormats.Gray16, null); this.depthImageBitmapRect = new Int32Rect(0, 0, depthStream.FrameWidth, depthStream.FrameHeight); this.depthImageStride = depthStream.FrameWidth * depthStream.FrameBytesPerPixel; //initialize drawing this.drawingGroupDepth = new DrawingGroup(); this.imageSourceDepth = new DrawingImage(this.drawingGroupDepth); SkeletonDepthOverlappingImage.Source = this.imageSourceDepth; // SkeletonDepthOverlappingImage.Source = depthImageBitmap; //\ parameters TransformSmoothParameters smoothingParameters = new TransformSmoothParameters(); { smoothingParameters.Smoothing = 0.5f; smoothingParameters.Correction = 0.5f; smoothingParameters.Prediction = 0.5f; smoothingParameters.JitterRadius = 0.05f; smoothingParameters.MaxDeviationRadius = 0.04f; } sensor.SkeletonStream.Enable(smoothingParameters); skeletonData = new Skeleton[sensor.SkeletonStream.FrameSkeletonArrayLength]; this.kinect.AllFramesReady += kinect_AllFramesReady; sensor.Start(); //timer start time = TimeSpan.FromSeconds(0); timer = new System.Windows.Threading.DispatcherTimer( new TimeSpan(0, 0, 1), System.Windows.Threading.DispatcherPriority.Normal, delegate { timerLabel.Content = time.ToString(); if (time == TimeSpan.FromSeconds(10)) { timer.Stop(); } time = time.Add(TimeSpan.FromSeconds(1)); }, Application.Current.Dispatcher ); timer.Start(); // WrongPostureClassifier.setRef(this); } }