我正在尝试将kinect区域与Visual手势构建器代码一起使用。 我已经为VGB和Wpf控件添加了正确的引用。我正在尝试使用VGB代码注入我的应用程序,这样我就可以在我的应用程序中执行这些自定义手势。
请建议我使用VGB和我的应用程序以及手形光标的方式。我也发布内部异常的图片。
public MainWindow()
{
InitializeComponent();
KinectRegion.SetKinectRegion(this, kinectRegion);
var app = ((App)Application.Current);
app.KinectRegion = kinectRegion;
this.kinectRegion.KinectSensor = KinectSensor.GetDefault();
var dataSource = DataSource.GetGroup("Group-1");
this.itemsControl.ItemsSource = dataSource;
// set IsAvailableChanged event notifier
this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged;
// open the sensor
this.kinectSensor.Open();
// set the status text
this.StatusText = this.kinectSensor.IsAvailable ? Properties.Resources.RunningStatusText
: Properties.Resources.NoSensorStatusText;
// open the reader for the body frames
this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader();
// set the BodyFramedArrived event notifier
this.bodyFrameReader.FrameArrived += this.Reader_BodyFrameArrived;
// initialize the BodyViewer object for displaying tracked bodies in the UI
// initialize the gesture detection objects for our gestures
this.gestureDetectorList = new List<GestureDetector>();
// initialize the MainWindow
this.InitializeComponent();
// set our data context objects for display in UI
this.DataContext = this;
// create a gesture detector for each body (6 bodies => 6 detectors) and create content controls to display results in the UI
int maxBodies = this.kinectSensor.BodyFrameSource.BodyCount;
for (int i = 0; i < maxBodies; ++i)
{
GestureResultView result = new GestureResultView(false, false, 0.0f);
GestureDetector detector = new GestureDetector(this.kinectSensor, result);
this.gestureDetectorList.Add(detector);
// split gesture results across the first two columns of the content grid
ContentControl contentControl = new ContentControl();
contentControl.Content = this.gestureDetectorList[i].GestureResultView;
}
}
And my Mainwindow.Xaml
<Window x:Class="Microsoft.Samples.Kinect.DiscreteGestureBasics.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Microsoft.Samples.Kinect.DiscreteGestureBasics"
xmlns:controls="http://schemas.microsoft.com/kinect/2014"
Title="Discrete Gesture Basics"
Height="650" Width="750"
Closing="MainWindow_Closing">
<ItemsControl x:Name="itemsControl">
<controls:KinectRegion x:Name="kinectRegion">
</controls:KinectRegion>
</ItemsControl>
</Window>