Joh*_*iou 1 c# wpf xaml kinect
我正在创建一个WPF/C#应用程序,它使用kinect来移动对象,但它也可以使用鼠标运行.目前我使用鼠标注释掉它的kinect代码.我需要知道kinect是否已连接,所以我不需要注释代码,因为它不能使用鼠标(没有像现在这样抛出异常),并且当它发生时使用kinect.我该怎么办?info:我正在使用官方的Microsoft Kinect SDK(大约一周前下载)
编辑 - 我正在使用这些
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;
Run Code Online (Sandbox Code Playgroud)
无法添加引用并使用Microsoft.Kinect,因为它会与其中一些产生冲突
编辑 -
Device dvc = new Device();
if (dvc.Count.Equals(0))
MessageBox.Show("apoellin");
Run Code Online (Sandbox Code Playgroud)
我尝试了上面的代码和应用程序崩溃同样的错误它崩溃如果我使用任何Kinect代码与Kinect没有连接
小智 5
这是"使用Microsoft SDK开始使用Kinect编程"一书中的代码,它可以很好地处理这个问题
// (in your page/window constructor):
this.KinectDevice = KinectSensor.KinectSensors
.FirstOrDefault(x => x.Status == KinectStatus.Connected);
// (and create a property like this:)
public KinectSensor KinectDevice
{
get { return this._KinectDevice; }
set
{
if (this._KinectDevice != value)
{
//Uninitialize
if (this._KinectDevice != null)
{
this._KinectDevice.Stop();
this._KinectDevice.SkeletonFrameReady -= KinectDevice_SkeletonFrameReady;
this._KinectDevice.SkeletonStream.Disable();
this._FrameSkeletons = null;
}
this._KinectDevice = value;
//Initialize
if (this._KinectDevice != null)
{
if (this._KinectDevice.Status == KinectStatus.Connected)
{
this._KinectDevice.SkeletonStream.Enable();
this._FrameSkeletons = new
Skeleton[this._KinectDevice.SkeletonStream.FrameSkeletonArrayLength];
this.KinectDevice.SkeletonFrameReady +=
KinectDevice_SkeletonFrameReady;
ColorImageStream colorStream = this._KinectDevice.ColorStream;
colorStream.Enable();
this._ColorImageBitmap = new WriteableBitmap(colorStream.FrameWidth,
colorStream.FrameHeight, 96, 96, PixelFormats.Bgr32, null);
this._ColorImageBitmapRect = new Int32Rect(0, 0, colorStream.FrameWidth,
colorStream.FrameHeight);
this._ColorImageStride = colorStream.FrameWidth * colorStream.FrameBytesPerPixel;
ColorImageElement.Source = this._ColorImageBitmap;
this._KinectDevice.ColorFrameReady += Kinect_ColorFrameReady;
this.ColorImageElement.Dispatcher.BeginInvoke(new Action(() =>
{
this._ColorImageBitmap = new WriteableBitmap(colorStream.FrameWidth,
colorStream.FrameHeight,
96, 96, PixelFormats.Bgr32,
null);
this._ColorImageBitmapRect = new Int32Rect(0, 0, colorStream.FrameWidth,
colorStream.FrameHeight);
this._ColorImageStride = colorStream.FrameWidth *
colorStream.FrameBytesPerPixel;
this._ColorImagePixelData = new byte[colorStream.FramePixelDataLength];
this.ColorImageElement.Source = this._ColorImageBitmap;
}));
this._KinectDevice.Start();
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4361 次 |
| 最近记录: |