检查kinect是否已连接 [英] checking if kinect is connected or not

查看:180
本文介绍了检查kinect是否已连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个使用kinect来移动对象的WPF/C#应用程序,但是它也可以使用鼠标来运行.目前,我使用鼠标将kinect代码注释掉,以使其正常工作.我需要一种方法来识别kinect是否已连接,因此我不必注释掉它的代码即可在不使用kinect时使用鼠标(不像当前那样抛出异常),而在使用kinect时使用它. 我该怎么办? 信息:我正在使用官方的Microsoft Kinect SDK(大约一周前下载)

I am creating a WPF/C# app that uses the kinect for moving objects but it also runs with using the mouse. Currently I comment out the kinect code for it work using the mouse. I need way to recognize whether the kinect is connected or not so I don't have to comment out code for it to use the mouse when it's not (without throwing an exception as it currently does) and use kinect when it does. How may I do that?? info: I am using official Microsoft Kinect SDKs (Downloaded about a week ago)

编辑- 我正在使用这些

Edit-- I am using these

using System;
using System.ComponentModel;
using System.Threading;
using System.Windows;
using System.Windows.Media;
using System.Windows.Input;
using System.Windows.Media.Media3D;
using System.Windows.Media.Animation;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using GridAnimationDemo;
using System.Windows.Threading;
using HtmlAgilityPack;
using System.Xml.Linq;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Net;
using Microsoft.Research.Kinect.Nui;
using Microsoft.Research.Kinect.Audio;
using Microsoft.Research.Kinect;
using Microsoft.Office.Interop.PowerPoint;
using System.Windows.Data;
using Microsoft.Research.Kinect.Samples.CursorControl;
using Coding4Fun.Kinect.Wpf;
using Coding4Fun;
using System.Speech.Synthesis;

无法添加引用并使用Microsoft.Kinect,因为它会与其中的某些冲突

Cannot add reference and use Microsoft.Kinect as it creates conflicts with some of these

编辑-

Device dvc = new Device();
            if (dvc.Count.Equals(0))
                MessageBox.Show("apoellin");

我尝试了上面的代码,该应用程序崩溃,并显示了与我在未连接Kinect的情况下使用任何Kinect代码时崩溃相同的错误

I tried the above code and the app crashes with the same error it crashes if I use any Kinect code with Kinect not connected

推荐答案

您正在使用Kinect for Windows SDK的过时版本. Microsoft.Research.Kinect名称空间来自beta.

You are using a very out of date version of the Kinect for Windows SDK. The Microsoft.Research.Kinect namespace is from the beta.

最新的SDK可以在这里下载:

The latest SDK can be downloaded here:

http://www.microsoft.com/zh-我们/kinectforwindows/develop/developer-downloads.aspx

执行完此操作后,请下载开发人员工具包,该工具包也可从上面的链接获得.它包含有关如何执行许多任务的多个示例.

After you do that, download the Developer Toolkit, also available from the link above. It contains multiple examples of how to do many tasks.

我强烈建议您看一下Kinect Explorer示例.这将向您展示如何使用名为KinectSensorManager的数据容器.此类是数据包装器,而不是SDK的一部分-它有助于管理Kinect传感器.它包含在几个Toolkit示例中.

I strongly suggest looking at the Kinect Explorer example. This will show you how to use a data container called KinectSensorManager. This class is a data wrapper and not part of the SDK -- it helps manage the Kinect sensor. It is included in several of the Toolkit examples.

除其他事项外,该类会在Kinect传感器状态更改时触发事件.因此,您可以在适当的事件处理程序中将程序设置为初始化和未初始化Kinect.

The class, among other things, fires events when the Kinect sensor state changes. So you can set your program up to initialize and uninitialized the Kinect in the appropriate event handlers.

这篇关于检查kinect是否已连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆