C# 左右手之间的Kinect滑动冲突

C# 左右手之间的Kinect滑动冲突,c#,wpf,kinect,gesture,kinect-v2,C#,Wpf,Kinect,Gesture,Kinect V2,我从头开始编写了一个Kinect滑动测试程序,可以读取Visual手势生成器生成的gbd文件 我想在这个问题中重点关注的四个手势是左手和右手向上,左手和右手向上滑动 在我上面发布的github链接中,它可以很好地集成在一起 然而,当我将代码移植到主项目时,左手 向上和右手向上滑动手势都出现故障。两个手势 无法检测到 我不能在这里发布我的主要项目,因此我将发布我如何在两个主要项目文件上实现的代码片段,主要是gesturedector.cs和gesturesultsview.cs 下面是我对文件有异

我从头开始编写了一个Kinect滑动测试程序,可以读取Visual手势生成器生成的gbd文件

我想在这个问题中重点关注的四个手势是左手和右手向上,左手和右手向上滑动

在我上面发布的github链接中,它可以很好地集成在一起

然而,当我将代码移植到主项目时,左手 向上和右手向上滑动手势都出现故障。两个手势 无法检测到

我不能在这里发布我的主要项目,因此我将发布我如何在两个主要项目文件上实现的代码片段,主要是
gesturedector.cs
gesturesultsview.cs

下面是我对文件有异议的部分

GestureDetector.cs:

公共类手势检测器:IDisposable
{
//存储指向gbd文件的路径数组
私有字符串[]数据库数组={//左侧
@“数据库\LeftHandDownToTop.gbd”
//,@“数据库\LeftHandsUp.gbd”
//,@“数据库\LeftHandLeftToRight.gbd”
//,@“数据库\LeftHandRightToLeft.gbd”
//右手
,@“Database\RightHandBottomToUp.gbd”
,@“Database\RightHandsUp.gbd”
//,@“数据库\RightHandLeftToRight.gbd”
//,@“数据库\RightHandRightToLeft.gbd”
};
//存储在gbd文件中找到的手势名称数组
私有字符串[]databaseGestureNameArray={//向上滑动
“SwipeUp_左”,
“SwipeUp_Right”,
//向右滑动
//“SwipeRight_左”,
//“SwipeRight_Right”,
//左击
//“左SwipeLeft_”,
//“SwipeLeft_Right”,
//举手
//“左上手”,
“举起手来,好的”
};
for(int i=0;i
GestureResultView.cs:

public bool-UpdateGestureResult(bool-isBodyTrackingIdValid、bool-isgesturedtected、float-detectionConfidence、string-gestureName)
{
this.IsTracked=isBodyTrackingIdValid;
这个。置信度=0.0f;
bool gestureFound=false;
如果(!this.IsTracked)
{
this.ImageSource=this.notTrackedImage;
这个。检测到=错误;
this.BodyColor=画笔.灰色;
}
其他的
{
this.Detected=isGestureDetected;
this.BodyColor=this.trackedColor[this.BodyIndex];
如果(检测到这个)
{
这个。置信度=检测置信度;
如果(该置信度>0.4)
{
this.ImageSource=this.seatedImage;
/
public class GestureDetector : IDisposable
{
    //stores an array of paths that leads to the gbd files
    private string[] databaseArray = {//Left Hand
                                       @"Database\LeftHandDownToTop.gbd"
                                     //, @"Database\LeftHandHandsUp.gbd"
                                     //, @"Database\LeftHandLeftToRight.gbd"
                                     //, @"Database\LeftHandRightToLeft.gbd"
                                      //Right Hand
                                     , @"Database\RightHandBottomToUp.gbd"
                                     , @"Database\RightHandHandsUp.gbd"
                                     //, @"Database\RightHandLeftToRight.gbd"
                                     //, @"Database\RightHandRightToLeft.gbd"
                                     };

    //stores an array of the names of the gesture found inside the gbd file
    private string[] databaseGestureNameArray = { //Swipe Up
                                                    "SwipeUp_Left",
                                                    "SwipeUp_Right",
                                                  //Swipe Right
                                                  //"SwipeRight_Left",
                                                  //"SwipeRight_Right",
                                                  //Swipe Left
                                                  // "SwipeLeft_Left",
                                                  // "SwipeLeft_Right",
                                                  //Hands Up
                                                  //"HandsUp_Left",
                                                    "HandsUp_Right"
                                                };


    for (int i = 0; i < databaseArray.Length; i++)
    {
        // load the 'Seated' gesture from the gesture database
        using (VisualGestureBuilderDatabase database = new VisualGestureBuilderDatabase(databaseArray[i]))
        {
            // we could load all available gestures in the database with a call to vgbFrameSource.AddGestures(database.AvailableGestures), 
            // but for this program, we only want to track one discrete gesture from the database, so we'll load it by name
            foreach (Gesture gesture in database.AvailableGestures)
            {
                if (gesture.Name.Equals(databaseGestureNameArray[i]))
                {
                    this.vgbFrameSource.AddGesture(gesture);
                }
            }
        }
    }
}


/// <summary>
/// Handles gesture detection results arriving from the sensor for the associated body tracking Id
/// </summary>
/// <param name="sender">object sending the event</param>
/// <param name="e">event arguments</param>
private void Reader_GestureFrameArrived(object sender, VisualGestureBuilderFrameArrivedEventArgs e)
{
    VisualGestureBuilderFrameReference frameReference = e.FrameReference;
    using (VisualGestureBuilderFrame frame = frameReference.AcquireFrame())
    {
        if (frame != null)
        {
            // get the discrete gesture results which arrived with the latest frame
            IReadOnlyDictionary<Gesture, DiscreteGestureResult> discreteResults = frame.DiscreteGestureResults;
            bool foundGesture = false;
            if (discreteResults != null)
            {
                // we only have one gesture in this source object, but you can get multiple gestures
                foreach (Gesture gesture in this.vgbFrameSource.Gestures)
                {
                    for (int i = 0; i < databaseGestureNameArray.Length; i++)
                    {
                        if (gesture.Name.Equals(databaseGestureNameArray[i]) && gesture.GestureType == GestureType.Discrete)
                        {
                            DiscreteGestureResult result = null;
                            discreteResults.TryGetValue(gesture, out result);

                            if (result != null && !foundGesture)
                            {
                                // update the GestureResultView object with new gesture result values & update the label
                                foundGesture = this.GestureResultView.UpdateGestureResult(true, result.Detected, result.Confidence, databaseGestureNameArray[i]);
                            }
                        }
                    }
                }
            }
        }
    }
}
public bool UpdateGestureResult(bool isBodyTrackingIdValid, bool isGestureDetected, float detectionConfidence, string gestureName)
{
    this.IsTracked = isBodyTrackingIdValid;
    this.Confidence = 0.0f;
    bool gestureFound = false;

    if (!this.IsTracked)
    {
        this.ImageSource = this.notTrackedImage;
        this.Detected = false;
        this.BodyColor = Brushes.Gray;
    }
    else
    {
        this.Detected = isGestureDetected;
        this.BodyColor = this.trackedColors[this.BodyIndex];

        if (this.Detected)
        {
            this.Confidence = detectionConfidence;
            if (this.Confidence > 0.4)
            {
                this.ImageSource = this.seatedImage;
                //https://stackoverflow.com/questions/15425495/change-wpf-mainwindow-label-from-another-class-and-separate-thread
                //to change label in other class wpf
                //http://the--semicolon.blogspot.co.id/p/change-wpf-window-label-content-from.html

                string state = App.Current.Properties["state"].ToString();
                switch (gestureName)
                {
                    case "SwipeUp_Right":
                        SwipeUp(state);
                        break;

                    case "SwipeUp_Left":
                        SwipeUp(state);
                        break;

                    case "SwipeDown_Right":
                        break;

                    case "SwipeDown_Left":
                        break;

                    case "SwipeLeft_Right":
                        break;

                    case "SwipeLeft_Left":
                        break;

                    case "HandsUp_Right":
                        if (state.Equals("GoBackHome"))
                        {

                        }
                        else
                        {
                            Thread.Sleep(350);
                            MainWindow.handsUp();
                        }

                        break;

                    case "HandsUp_Left":
                        if (state.Equals("GoBackHome"))
                        {

                        }
                        else
                        {
                            Thread.Sleep(350);
                            MainWindow.handsUp();
                        }
                        break;




                }
                //"HandsUp_Right"
                //                            , "SwipeRight_Right"
                //                            , "SwipeUp_Right"
                //                            , "SwipeLeft_Right"
                //                            , "HandsUp_Left"
                //                            , "SwipeRight_Left"

                gestureFound = true;
            }
        }
        else
        {
            this.ImageSource = this.notSeatedImage;
        }
    }

    return gestureFound;
}

}  
    //Routing for gesture start
    /// <summary>
    /// Take in the current screen, filtered swipe up gesture
    /// </summary>
    /// <param name="state"></param>
    private void SwipeUp(string state)
    {
        if (state.Equals("Home"))
        {
            int milliseconds = 350;
            Thread.Sleep(milliseconds);
            //await Task.Delay(500);
            Home.swipeUp();
        }
        else if (state.Equals("ItemChoice"))
        {
            int milliseconds = 350;
            Thread.Sleep(milliseconds);
            //await Task.Delay(500);
            ItemChoice.swipeUp();

        }
        else if (state.Equals("ItemParentChoice"))
        {
            int milliseconds = 350;
            Thread.Sleep(milliseconds);
            //await Task.Delay(500);
            ItemParentChoice.swipeUp();
        }
        else if (state.Equals("LoanSummary"))
        {
            int milliseconds = 350;
            Thread.Sleep(milliseconds);
            //await Task.Delay(500);
            LoanSummary.swipeUp();
        }
        else if (state.Equals("Timeslot"))
        {
            int milliseconds = 350;
            Thread.Sleep(milliseconds);
            //await Task.Delay(500);
            Timeslot.swipeUp();
        }
        else if (state.Equals("ViewLoans"))
        {
            int milliseconds = 350;
            Thread.Sleep(milliseconds);
            //await Task.Delay(500);
            ViewLoans.swipeUp();
        }
        else if (state.Equals("WhatToDo"))
        {
            int milliseconds = 350;
            Thread.Sleep(milliseconds);
            //await Task.Delay(500);
            //WhatToDo.swipeUp();
        }
    }

    /// <summary>
    /// Take in the current screen, filtered swipe right gesture
    /// </summary>
    /// <param name="state"></param>
    private void swipeRight(string state)
    {
        if (state.Equals("Home"))
        {
            //int milliseconds = 500;
            //Thread.Sleep(milliseconds);
            //Home.swipeUp();
        }
        else if (state.Equals("ItemChoice"))
        {
            int milliseconds = 500;
            Thread.Sleep(milliseconds);
            ItemChoice.swipeRight();
        }
        else if (state.Equals("ItemParentChoice"))
        {
            int milliseconds = 500;
            Thread.Sleep(milliseconds);
            ItemParentChoice.swipeRight();
        }
        else if (state.Equals("LoanSummary"))
        {
            //int milliseconds = 500;
            //Thread.Sleep(milliseconds);
            //LoanSummary.swipeUp();
        }
        else if (state.Equals("Timeslot"))
        {
            int milliseconds = 500;
            Thread.Sleep(milliseconds);
            Timeslot.swipeRight();
        }
        else if (state.Equals("ViewLoans"))
        {
            //int milliseconds = 500;
            //Thread.Sleep(milliseconds);
            //ViewLoans.swipeUp();
        }
        else if (state.Equals("WhatToDo"))
        {
            //int milliseconds = 500;
            //Thread.Sleep(milliseconds);
            //Home.swipeUp();
        }
    }

    /// <summary>
    /// Take in the current screen, filtered swipe right gesture
    /// </summary>
    /// <param name="state"></param>
    private void swipeLeft(string state)
    {
        if (state.Equals("Home"))
        {
            //int milliseconds = 500;
            //Thread.Sleep(milliseconds);
            //Home.swipeUp();
        }
        else if (state.Equals("ItemChoice"))
        {
            int milliseconds = 500;
            Thread.Sleep(milliseconds);
            ItemChoice.swipeLeft();
        }
        else if (state.Equals("ItemParentChoice"))
        {
            int milliseconds = 500;
            Thread.Sleep(milliseconds);
            ItemParentChoice.swipeLeft();
        }
        else if (state.Equals("LoanSummary"))
        {
            //int milliseconds = 500;
            //Thread.Sleep(milliseconds);
            //LoanSummary.swipeUp();
        }
        else if (state.Equals("Timeslot"))
        {
            int milliseconds = 500;
            Thread.Sleep(milliseconds);
            Timeslot.swipeLeft();
        }
        else if (state.Equals("ViewLoans"))
        {
            //int milliseconds = 500;
            //Thread.Sleep(milliseconds);
            //ViewLoans.swipeUp();
        }
        else if (state.Equals("WhatToDo"))
        {
            //int milliseconds = 500;
            //Thread.Sleep(milliseconds);
            //Home.swipeUp();
        }
    }

    //routing for gesture end
}