本文整理汇总了C#中Microsoft.Kinect.KinectSensor类的典型用法代码示例。如果您正苦于以下问题:C# KinectSensor类的具体用法?C# KinectSensor怎么用?C# KinectSensor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KinectSensor类属于Microsoft.Kinect命名空间,在下文中一共展示了KinectSensor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Form1
public Form1()
{
InitializeComponent();
outputDevice.Open();
try
{
if (KinectSensor.KinectSensors.Count == 0)
{
throw new Exception("Kinectが接続されていません");
}
// Kinectインスタンスを取得する
kinect = KinectSensor.KinectSensors[0];
// すべてのフレーム更新通知をもらう
kinect.AllFramesReady += new EventHandler<AllFramesReadyEventArgs>(kinect_AllFramesReady);
// Color,Depth,Skeletonを有効にする
kinect.SkeletonStream.Enable();
// Kinectの動作を開始する
kinect.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
Close();
}
}
示例2: KinectControl
public KinectControl(HoverButton kinectButton, double layoutHeight, double layoutWidth, List<Button> buttons, TextBox debugBox = null)
{
_kinectButton = kinectButton;
_layoutHeight = layoutHeight;
_layoutWidth = layoutWidth;
_buttons = buttons;
_debugBox = debugBox;
_kinect = KinectSensor.KinectSensors.FirstOrDefault();
if (_kinect != null)
{
_kinect.Start();
_kinect.ColorStream.Enable();
_kinect.SkeletonStream.Enable(new TransformSmoothParameters
{
Smoothing = 0.7f,
Correction = 0.1f,
Prediction = 0.1f,
JitterRadius = 0.05f,
MaxDeviationRadius = 0.05f
});
_kinect.SkeletonFrameReady += kinect_SkeletonFrameReady;
}
_activeRecognizer = CreateRecognizer();
_kinectButton.Click += KinectButton_Click;
}
示例3: KinectDance
public KinectDance(double layoutHeight, double layoutWidth, List<TextBlock> menus, Style mouseOverStyle, Border menuBorder,TextBox debugBox = null)
{
_layoutHeight = layoutHeight;
_layoutWidth = layoutWidth;
_debugBox = debugBox;
_menus = menus;
_menuBorder = menuBorder;
_mouseOverStyle = mouseOverStyle;
_kinect = KinectSensor.KinectSensors.FirstOrDefault();
if (_kinect == null) return;
//_kinect.SkeletonStream.TrackingMode = SkeletonTrackingMode.Seated;
_kinect.Start();
_kinect.ColorStream.Enable();
_kinect.SkeletonStream.Enable(new TransformSmoothParameters
{
Smoothing = 0.7f,
Correction = 0.3f,
Prediction = 0.4f,
JitterRadius = 0.5f,
MaxDeviationRadius = 0.5f
});
_kinect.SkeletonFrameReady += kinect_SkeletonFrameReady;
}
示例4: connexion_kinect
public KinectSensor connexion_kinect()
{
foreach (var potentialSensor in KinectSensor.KinectSensors)
{
if (potentialSensor.Status == KinectStatus.Connected)
{
sensor = potentialSensor;
}
}
if (null != sensor)
{
// Turn on the skeleton stream to receive skeleton frames
sensor.SkeletonStream.Enable();
// Start the sensor!
try
{
sensor.Start();
}
catch (IOException)
{
return sensor = null;
}
}
return sensor;
}
示例5: startKinect
private void startKinect()
{
if (KinectSensor.KinectSensors.Count > 0)
{
// Choose the first Kinect device
kinect = KinectSensor.KinectSensors[0];
if (kinect == null)
return;
kinect.ColorStream.Enable();
var tsp = new TransformSmoothParameters
{
Smoothing = 0.5f,
Correction = 0.5f,
Prediction = 0.5f,
JitterRadius = 0.05f,
MaxDeviationRadius = 0.04f
};
kinect.SkeletonStream.Enable(tsp);
// Start skeleton tracking
//kinect.ColorFrameReady += new EventHandler<ColorImageFrameReadyEventArgs>(kinect_ColorFrameReady);
//kinect.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(kinect_SkeletonFrameReady);
// Start Kinect device
kinect.Start();
}
else
{
MessageBox.Show("No Kinect Device found.");
}
}
示例6: KinectHelper
private KinectHelper(TransformSmoothParameters tsp, bool near = false,
ColorImageFormat colorFormat = ColorImageFormat.RgbResolution1280x960Fps12,
DepthImageFormat depthFormat = DepthImageFormat.Resolution640x480Fps30)
{
_kinectSensor = KinectSensor.KinectSensors.FirstOrDefault(s => s.Status == KinectStatus.Connected);
if (_kinectSensor == null)
{
throw new Exception("No Kinect-Sensor found.");
}
if (near)
{
_kinectSensor.SkeletonStream.TrackingMode = SkeletonTrackingMode.Seated;
_kinectSensor.DepthStream.Range = DepthRange.Near;
_kinectSensor.SkeletonStream.EnableTrackingInNearRange = true;
}
DepthImageFormat = depthFormat;
ColorImageFormat = colorFormat;
_kinectSensor.SkeletonStream.Enable(tsp);
_kinectSensor.ColorStream.Enable(colorFormat);
_kinectSensor.DepthStream.Enable(depthFormat);
_kinectSensor.AllFramesReady += AllFramesReady;
_kinectSensor.Start();
_faceTracker = new FaceTracker(_kinectSensor);
}
示例7: setupKinect
public int setupKinect(Model mod, Image img)
{
theModel = mod;
theImage = img;
foreach (var potentialSensor in KinectSensor.KinectSensors)
{
if (potentialSensor.Status == KinectStatus.Connected)
{
this.sensor = potentialSensor;
this.foundSensor = true;
break;
}
}
if (this.foundSensor == false)
{
return -1;
}
this.setupSkeleton();
this.setupColor();
this.setupDepth();
this.sensor.Start();
this.setupAudio();
this.sensor.AllFramesReady += sensor_AllFramesReady;
return 0;
}
示例8: Start_Click
private void Start_Click(object sender, RoutedEventArgs e)
{
if (this.StartStopButton.Content.ToString() == ButtonStartText)
{
if (KinectSensor.KinectSensors.Any())
{
KinectSensor.KinectSensors.StatusChanged += (o, args) =>
{
this.Status.Content = args.Status.ToString();
};
sensor = KinectSensor.KinectSensors.First();
}
sensor.Start();
sensor.ElevationAngle = 0;
sensor.ColorStream.Enable();
sensor.DepthStream.Enable();
sensor.SkeletonStream.Enable();
sensor.SkeletonStream.TrackingMode = SkeletonTrackingMode.Default; // Default is standing
sensor.AllFramesReady += sensorAllFramesReady;
this.ConnectionID.Content = sensor.DeviceConnectionId;
this.StartStopButton.Content = ButtonStopText;
}
else
{
if (sensor != null && sensor.IsRunning)
{
sensor.Stop();
StartStopButton.Content = ButtonStartText;
}
}
}
示例9: Cage4_Loaded
void Cage4_Loaded(object sender, RoutedEventArgs e)
{
foreach (var potentialSensor in KinectSensor.KinectSensors)
{
if (potentialSensor.Status == KinectStatus.Connected)
{
this.sensor = potentialSensor;
break;
}
}
if (null != this.sensor)
{
this.sensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
this.colorPixels = new byte[this.sensor.ColorStream.FramePixelDataLength];
this.colorBitmap = new WriteableBitmap(this.sensor.ColorStream.FrameWidth, this.sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);
this.cimg_cage4.Source = this.colorBitmap;
this.sensor.AllFramesReady += this.sensor_AllFramesReady;
try
{
this.sensor.Start();
}
catch (IOException)
{
//this.sensor = null;
}
}
}
示例10: MainWindow
public MainWindow()
{
InitializeComponent();
try {
// 利用可能なKinectを探す
foreach ( var k in KinectSensor.KinectSensors ) {
if ( k.Status == KinectStatus.Connected ) {
kinect = k;
break;
}
}
if ( kinect == null ) {
throw new Exception( "利用可能なKinectがありません" );
}
// Colorを有効にする
kinect.ColorFrameReady += new EventHandler<ColorImageFrameReadyEventArgs>( kinect_ColorFrameReady );
kinect.ColorStream.Enable( ColorImageFormat.RgbResolution640x480Fps30 );
// Kinectの動作を開始する
kinect.Start();
}
catch ( Exception ex ) {
MessageBox.Show( ex.Message );
Close();
}
}
示例11: KinectCoreV2
public KinectCoreV2(ref KinectBase.MasterSettings settings, bool isGUILaunched, int kinectNumber)
{
masterSettings = settings;
dynamic temp = masterSettings.kinectOptionsList[kinectNumber];
masterKinectSettings = (KinectV2Settings)temp;
//TODO: Update this to open a specific Kinect v2, if the SDK is ever updated to support multiple on one machine
kinect = KinectSensor.GetDefault();
kinectID = kinectNumber;
uint tempC = kinect.ColorFrameSource.FrameDescription.LengthInPixels;
uint tempD = kinect.DepthFrameSource.FrameDescription.LengthInPixels;
uint tempI = kinect.InfraredFrameSource.FrameDescription.LengthInPixels;
colorImagePool = new KinectBase.ObjectPool<byte[]>(() => new byte[tempC * 4]);
depthImagePool = new KinectBase.ObjectPool<byte[]>(() => new byte[tempD * 4]);
irImagePool = new KinectBase.ObjectPool<byte[]>(() => new byte[tempI * sizeof(UInt16)]);
if (isGUILaunched)
{
isGUI = true;
LaunchKinect();
}
else
{
launchKinectDelegate kinectDelegate = LaunchKinect;
IAsyncResult result = kinectDelegate.BeginInvoke(null, null);
kinectDelegate.EndInvoke(result); //Even though this is blocking, the events should be on a different thread now.
}
}
示例12: DiscoverKinectSensor
private void DiscoverKinectSensor()
{
if (this._Kinect != null && this._Kinect.Status != KinectStatus.Connected)
{
// If the sensor is no longer connected, we need to discover a new one.
this._Kinect = null;
}
if (this._Kinect == null)
{
//Find the first connected sensor
this._Kinect = KinectSensor.KinectSensors.FirstOrDefault(x => x.Status == KinectStatus.Connected);
if (this._Kinect != null)
{
//Initialize the found sensor
this._Kinect.ColorStream.Enable();
this._Kinect.Start();
ColorImageStream colorSteam = this._Kinect.ColorStream;
this._ColorImageBitmap = new WriteableBitmap(colorSteam.FrameWidth,
colorSteam.FrameHeight,
96, 96, PixelFormats.Bgr32,
null);
this._ColorImageBitmapRect = new Int32Rect(0, 0, colorSteam.FrameWidth,
colorSteam.FrameHeight);
this._ColorImageStride = colorSteam.FrameWidth *
colorSteam.FrameBytesPerPixel;
this.ColorImageElement.Source = this._ColorImageBitmap;
this._ColorImagePixelData = new byte[colorSteam.FramePixelDataLength];
}
}
}
示例13: initialize
public void initialize( int elevationAngle = 0 )
{
try { kinectSensor = KinectSensor.KinectSensors[0]; }
catch (Exception e)
{
Console.WriteLine("kinect not detected, continuing with kinect disabled {0}",e);
return;
}
if (kinectSensor == null) {
return;
}
// limits elevation angle to keep the motors from trying too extreme an angle
if (elevationAngle >= 26 )
{
elevationAngle = 26;
}
else if (elevationAngle <= -26)
{
elevationAngle = -26;
}
// Only initializes Skeletal Tracking
kinectSensor.SkeletonStream.Enable();
// set a call back function to process skeleton data
kinectSensor.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(kinectSkeletonFrameReadyCallback);
kinectSensor.Start();
kinectSensor.ElevationAngle = elevationAngle;
}
示例14: MathiasCore
/// <summary>
/// Simply a empty Constructor
/// </summary>
public MathiasCore()
{
CONNECTED = false;
KinectAudio = new KinectAudioController();
kinect = KinectSensor.GetDefault();
dbManager = new DBManager();
}
示例15: ConvertDepthColor
/// <summary>
/// 距離データをカラー画像に変換する
/// </summary>
/// <param name="kinect"></param>
/// <param name="depthFrame"></param>
/// <returns></returns>
private byte[] ConvertDepthColor( KinectSensor kinect, DepthImageFrame depthFrame )
{
ColorImageStream colorStream = kinect.ColorStream;
DepthImageStream depthStream = kinect.DepthStream;
// 距離カメラのピクセルごとのデータを取得する
short[] depthPixel = new short[depthFrame.PixelDataLength];
depthFrame.CopyPixelDataTo( depthPixel );
// 距離カメラの座標に対応するRGBカメラの座標を取得する(座標合わせ)
ColorImagePoint[] colorPoint = new ColorImagePoint[depthFrame.PixelDataLength];
kinect.MapDepthFrameToColorFrame( depthStream.Format, depthPixel,
colorStream.Format, colorPoint );
byte[] depthColor = new byte[depthFrame.PixelDataLength * Bgr32BytesPerPixel];
for ( int index = 0; index < depthPixel.Length; index++ ) {
// 距離カメラのデータから、プレイヤーIDと距離を取得する
int player = depthPixel[index] & DepthImageFrame.PlayerIndexBitmask;
int distance = depthPixel[index] >> DepthImageFrame.PlayerIndexBitmaskWidth;
// 変換した結果が、フレームサイズを超えることがあるため、小さいほうを使う
int x = Math.Min( colorPoint[index].X, colorStream.FrameWidth - 1 );
int y = Math.Min( colorPoint[index].Y, colorStream.FrameHeight - 1 );
int colorIndex = ((y * depthFrame.Width) + x) * Bgr32BytesPerPixel;
if ( player != 0 ) {
depthColor[colorIndex] = 255;
depthColor[colorIndex + 1] = 255;
depthColor[colorIndex + 2] = 255;
}
else {
// サポート外 0-40cm
if ( distance == depthStream.UnknownDepth ) {
depthColor[colorIndex] = 0;
depthColor[colorIndex + 1] = 0;
depthColor[colorIndex + 2] = 255;
}
// 近すぎ 40cm-80cm(default mode)
else if ( distance == depthStream.TooNearDepth ) {
depthColor[colorIndex] = 0;
depthColor[colorIndex + 1] = 255;
depthColor[colorIndex + 2] = 0;
}
// 遠すぎ 3m(Near),4m(Default)-8m
else if ( distance == depthStream.TooFarDepth ) {
depthColor[colorIndex] = 255;
depthColor[colorIndex + 1] = 0;
depthColor[colorIndex + 2] = 0;
}
// 有効な距離データ
else {
depthColor[colorIndex] = 0;
depthColor[colorIndex + 1] = 255;
depthColor[colorIndex + 2] = 255;
}
}
}
return depthColor;
}