C# Kinect的System.Windows.Markup.XamlParseException
我目前面临着一个奇怪的问题,微软Kinect SDK 2.0浏览器的离散手势基本WPF示例代码 目标:将我自己在filename.gbd中记录的手势添加到数据库中,并能够提取其中的手势 问题:当我将初始名称从“seatd.gbd”更改为“RightHandUp.gbd”时,下面发生了错误 但是,如果我要将我的“RightHandsUp.gbd”文件重命名为“seatd.gbd”(默认值),它会起作用。这很奇怪,但我怀疑程序中的某个地方有绑定,但我已经尝试在整个项目中搜索关键字 提前谢谢 错误消息: 除了两个内部例外:C# Kinect的System.Windows.Markup.XamlParseException,c#,exception,kinect,gesture,kinect-sdk,C#,Exception,Kinect,Gesture,Kinect Sdk,我目前面临着一个奇怪的问题,微软Kinect SDK 2.0浏览器的离散手势基本WPF示例代码 目标:将我自己在filename.gbd中记录的手势添加到数据库中,并能够提取其中的手势 问题:当我将初始名称从“seatd.gbd”更改为“RightHandUp.gbd”时,下面发生了错误 但是,如果我要将我的“RightHandsUp.gbd”文件重命名为“seatd.gbd”(默认值),它会起作用。这很奇怪,但我怀疑程序中的某个地方有绑定,但我已经尝试在整个项目中搜索关键字 提前谢谢 错误消息
InvalidOperationException: This API has returned an exception from an HRESULT: 0x80004005
及
所以在gesturedetator.cs文件中,我更改了文件名
//------------------------------------------------------------------------------
//
//版权所有(c)微软公司。版权所有。
//
//------------------------------------------------------------------------------
命名空间Microsoft.Samples.Kinect.DiscreteTestureBasics
{
使用制度;
使用System.Collections.Generic;
使用Microsoft.Kinect;
使用Microsoft.Kinect.VisualGestureBuilder;
///
///手势检测器类,用于侦听来自服务的VisualGestureBuilderFrame事件
///并使用“坐下”手势的最新结果更新关联的GestureResultView对象
///
公共类手势检测器:IDisposable
{
///使用VGB训练的手势数据库的路径
私有只读字符串gestureDatabase=@“Database\RightHandHandsUp.gbd”;
///数据库中要跟踪的离散手势的名称
私有只读字符串seatedGestureName=“HandsUp\u Right”;
///应绑定到身体跟踪ID的手势帧源
私有VisualGestureBuilderFrameSource vgbFrameSource=null;
///手势帧读取器,用于处理来自传感器的手势事件
私有VisualGetStureBuilderFrameReader vgbFrameReader=null;
///
///初始化GestureDetector类的新实例以及手势帧源和读取器
///
///用于初始化VisualGestureBuilderFrameSource对象的活动传感器
///GestureResultView对象,用于将单个身体的手势结果存储到
公共手势检测器(KinectSensor、KinectSensor、GestureResultView、GestureResultView)
{
如果(kinectSensor==null)
{
抛出新异常(“kinectSensor”);
}
如果(gestureResultView==null)
{
抛出新ArgumentNullException(“gestureResultView”);
}
this.gesturesultview=gesturesultview;
//创建vgb源。当传感器收到有效的正文帧时,将设置关联的正文跟踪ID。
this.vgbFrameSource=新的VisualGetStureBuilder框架源(kinectSensor,0);
this.vgbFrameSource.TrackingIdLost+=this.Source\u TrackingIdLost;
//打开vgb帧的读取器
this.vgbFrameReader=this.vgbFrameSource.OpenReader();
if(this.vgbFrameReader!=null)
{
this.vgbFrameReader.IsPaused=true;
this.vgbFrameReader.frameArrized+=this.Reader\u gestureframearized;
}
//从手势数据库加载“坐下”手势
使用(VisualGestureBuilderDatabase=new VisualGestureBuilderDatabase(this.gestureDatabase))
{
//我们可以通过调用vgbFrameSource.addpirates(database.availablegestrues)加载数据库中所有可用的手势,
//但是对于这个程序,我们只想从数据库中跟踪一个离散的手势,所以我们将按名称加载它
foreach(数据库中的手势。可用的手势)
{
if(手势.Name.Equals(this.seatedGestureName))
{
this.vgbFrameSource.add手势(手势);
}
}
}
}
///获取GestureResultView对象,该对象存储要在UI中显示的检测器结果
public GestureResultView GestureResultView{get;private set;}
///
///获取或设置与当前检测器关联的正文跟踪ID
///跟踪ID可以在主体进入/离开范围时更改
///
公共ulong TrackingId
{
得到
{
返回this.vgbFrameSource.TrackingId;
}
设置
{
if(this.vgbFrameSource.TrackingId!=值)
{
this.vgbFrameSource.TrackingId=值;
}
}
}
///
///获取或设置一个值,该值指示检测器当前是否暂停
///如果与探测器相关的身体跟踪ID无效,则应暂停探测器
///
公共场所
{
得到
{
返回this.vgbFrameReader.IsPaused;
}
设置
{
if(this.vgbFrameReader.IsPaused!=值)
{
this.vgbFrameReader.IsPaused=值;
}
}
}
///
///处理类的所有非托管资源
///
公共空间处置()
{
这个。处置(真实);
总干事(本);
}
///
///处置VisualGestureBuilderFrameSource和VisualGestureBuilderFrameReader对象
///
///如果直接调用Dispose,则为True;如果GC处理Dispose,则为false
受保护的虚拟void Dispose(bool disposing)
{
如果(处置)
{
if(this.vgbFrameReader!=null)
{
this.vgbFrameReader.frameArrized-=this.Reader\u gestureframearized;
这是.vgbFrameReader.Dispose();
this.vgbFrameReader=null;
}
如果(第
InvalidOperationException: This API has returned an exception from an HRESULT: 0x80004005
COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.
//------------------------------------------------------------------------------
// <copyright file="GestureDetector.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace Microsoft.Samples.Kinect.DiscreteGestureBasics
{
using System;
using System.Collections.Generic;
using Microsoft.Kinect;
using Microsoft.Kinect.VisualGestureBuilder;
/// <summary>
/// Gesture Detector class which listens for VisualGestureBuilderFrame events from the service
/// and updates the associated GestureResultView object with the latest results for the 'Seated' gesture
/// </summary>
public class GestureDetector : IDisposable
{
/// <summary> Path to the gesture database that was trained with VGB </summary>
private readonly string gestureDatabase = @"Database\RightHandHandsUp.gbd";
/// <summary> Name of the discrete gesture in the database that we want to track </summary>
private readonly string seatedGestureName = "HandsUp_Right";
/// <summary> Gesture frame source which should be tied to a body tracking ID </summary>
private VisualGestureBuilderFrameSource vgbFrameSource = null;
/// <summary> Gesture frame reader which will handle gesture events coming from the sensor </summary>
private VisualGestureBuilderFrameReader vgbFrameReader = null;
/// <summary>
/// Initializes a new instance of the GestureDetector class along with the gesture frame source and reader
/// </summary>
/// <param name="kinectSensor">Active sensor to initialize the VisualGestureBuilderFrameSource object with</param>
/// <param name="gestureResultView">GestureResultView object to store gesture results of a single body to</param>
public GestureDetector(KinectSensor kinectSensor, GestureResultView gestureResultView)
{
if (kinectSensor == null)
{
throw new ArgumentNullException("kinectSensor");
}
if (gestureResultView == null)
{
throw new ArgumentNullException("gestureResultView");
}
this.GestureResultView = gestureResultView;
// create the vgb source. The associated body tracking ID will be set when a valid body frame arrives from the sensor.
this.vgbFrameSource = new VisualGestureBuilderFrameSource(kinectSensor, 0);
this.vgbFrameSource.TrackingIdLost += this.Source_TrackingIdLost;
// open the reader for the vgb frames
this.vgbFrameReader = this.vgbFrameSource.OpenReader();
if (this.vgbFrameReader != null)
{
this.vgbFrameReader.IsPaused = true;
this.vgbFrameReader.FrameArrived += this.Reader_GestureFrameArrived;
}
// load the 'Seated' gesture from the gesture database
using (VisualGestureBuilderDatabase database = new VisualGestureBuilderDatabase(this.gestureDatabase))
{
// 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(this.seatedGestureName))
{
this.vgbFrameSource.AddGesture(gesture);
}
}
}
}
/// <summary> Gets the GestureResultView object which stores the detector results for display in the UI </summary>
public GestureResultView GestureResultView { get; private set; }
/// <summary>
/// Gets or sets the body tracking ID associated with the current detector
/// The tracking ID can change whenever a body comes in/out of scope
/// </summary>
public ulong TrackingId
{
get
{
return this.vgbFrameSource.TrackingId;
}
set
{
if (this.vgbFrameSource.TrackingId != value)
{
this.vgbFrameSource.TrackingId = value;
}
}
}
/// <summary>
/// Gets or sets a value indicating whether or not the detector is currently paused
/// If the body tracking ID associated with the detector is not valid, then the detector should be paused
/// </summary>
public bool IsPaused
{
get
{
return this.vgbFrameReader.IsPaused;
}
set
{
if (this.vgbFrameReader.IsPaused != value)
{
this.vgbFrameReader.IsPaused = value;
}
}
}
/// <summary>
/// Disposes all unmanaged resources for the class
/// </summary>
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Disposes the VisualGestureBuilderFrameSource and VisualGestureBuilderFrameReader objects
/// </summary>
/// <param name="disposing">True if Dispose was called directly, false if the GC handles the disposing</param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (this.vgbFrameReader != null)
{
this.vgbFrameReader.FrameArrived -= this.Reader_GestureFrameArrived;
this.vgbFrameReader.Dispose();
this.vgbFrameReader = null;
}
if (this.vgbFrameSource != null)
{
this.vgbFrameSource.TrackingIdLost -= this.Source_TrackingIdLost;
this.vgbFrameSource.Dispose();
this.vgbFrameSource = null;
}
}
}
/// <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;
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)
{
if (gesture.Name.Equals(this.seatedGestureName) && gesture.GestureType == GestureType.Discrete)
{
DiscreteGestureResult result = null;
discreteResults.TryGetValue(gesture, out result);
if (result != null)
{
// update the GestureResultView object with new gesture result values
this.GestureResultView.UpdateGestureResult(true, result.Detected, result.Confidence);
}
}
}
}
}
}
}
/// <summary>
/// Handles the TrackingIdLost event for the VisualGestureBuilderSource object
/// </summary>
/// <param name="sender">object sending the event</param>
/// <param name="e">event arguments</param>
private void Source_TrackingIdLost(object sender, TrackingIdLostEventArgs e)
{
// update the GestureResultView object to show the 'Not Tracked' image in the UI
this.GestureResultView.UpdateGestureResult(false, false, 0.0f);
}
}