System.Windows.Markup.XamlParseException For Kinect

0

Im currently facing a weird problem with the Microsoft Kinect SDK 2.0 Browser Sample code of Discrete Gesture Basics-WPF

Objective: is to add my own recording of the gesture in filename.gbd into the database and able to extract the gesture inside.

Problem: When i changed the initial name from 'Seated.gbd' to 'RightHandHandsUp.gbd' The error occured below.

However, if i were to rename my 'RightHandHandsUp.gbd' file to 'Seated.gbd' ( the default), it would work. Which is weird, but i suspect there is some binding somewhere in the program but i have already tried searching the entire project for the keyword.

Thanks in advance!!

Error Message: Error Message1

System.Windows.Markup.XamlParseException: ''The invocation of the constructor on type 'Microsoft.Samples.Kinect.DiscreteGestureBasics.MainWindow' that matches the specified binding constraints threw an exception.' Line number '4' and line position '9'.'

With 2 inner exceptions:

InvalidOperationException: This API has returned an exception from an HRESULT: 0x80004005

And

COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.

so in the GestureDetector.cs file where i changed the name of the file.

 //------------------------------------------------------------------------------
// <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);
    }
}

}

c#
exception
kinect
gesture
kinect-sdk
asked on Stack Overflow May 19, 2017 by bingcheng45

1 Answer

0

In my case I didn't know that DiscreteGestureBasics is using AdaBoostTech.dll and RFRProgressTech.dll. I copied directory vgtech from DiscreteGestureBuilder example bin directory to my other project bin directory and everything works fine.

answered on Stack Overflow Oct 24, 2019 by Paweł Kankowski

User contributions licensed under CC BY-SA 3.0