0

我正在开发一个 C# WPF 跌倒检测应用程序,我需要计算头部关节的速度并每 1/3 秒(大约)显示一次。因此,如果该人跌倒(头部位置离地板太近),我会计算最后一秒的平均速度来确定是跌倒还是类似跌倒的活动。

问题是有时我得到“非数字”速度值,我不确定我的算法是否正确计算速度。请你帮助我好吗?

这是我的代码:

int init = 1;
double yHead;
int compteur=0;

void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            if (closing)
            {
                return;
            }


            using (SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame())
            {
                if (skeletonFrameData == null) 
                {
                    return ;
                }

                skeletonFrameData.CopySkeletonDataTo(allSkeletons);
                skeletonFrameData.Dispose();

                Skeleton first = (from s in allSkeletons
                                  where s.TrackingState == SkeletonTrackingState.Tracked
                                  select s).FirstOrDefault();

                if (first == null)
                {
                    return;
                }

                compteur++; // Compteur de frames
                plane = skeletonFrameData.FloorClipPlane;

                GetCameraPoint(first, e);
                if  ((init==1)&&(first.Joints[JointType.Head].TrackingState == JointTrackingState.Tracked))
                {
                    yHead = calculerDistance(first.Joints[JointType.Head]);
                    init = 0;
                    Di = yHead;
                    Ti = skeletonFrameData.Timestamp;
                }
                else{

                    if(init == 0)

                    if (fall == false)
                    {

                        yHead = calculerDistance(first.Joints[JointType.Head]);

                        Dj = yHead; Tj = skeletonFrameData.Timestamp;
                        Vi = Math.Abs(1000 * ((Dj - Di) / (Tj - Ti)));

                        if (compteur == 8)
                        { 
                            speed.Content = "Speed=" + Vi.ToString("0.##") + "m/s";             
                            compteur = 0;
                        }
                        posit.Content = "Head position: " + yHead.ToString("0.##");
                        Di = Dj;
                        Ti = Tj;

                    }
                }

            }

        }


        double calculerDistance(Joint joint)
        {
            float A = plane.Item1;
            float B = plane.Item2;
            float C = plane.Item3;
            float D = plane.Item4;

            float x = (joint.Position.X) * A;
            float y = (joint.Position.Y) * B;
            float z = (joint.Position.Z) * C;

            double distance = Math.Abs((x + y + z + D) / Math.Sqrt((A * A) + (B * B) + (C * C)));
            return distance;
        }
4

0 回答 0