質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

Kinect

Kinect(キネクト)はマイクロソフトから発売されたジェスチャー・音声認識によって 操作ができるデバイスです。

Q&A

0回答

2406閲覧

Kinectのハンドトラッキングについての質問です。

ultimo193

総合スコア8

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

Kinect

Kinect(キネクト)はマイクロソフトから発売されたジェスチャー・音声認識によって 操作ができるデバイスです。

0グッド

0クリップ

投稿2016/01/25 02:47

編集2016/01/26 04:17

卒業研究でKinectについて取り組んでいる専門学生です。
現在、手のトラッキングについて取り組んでおり、ソース文を書いてみたのですがうまくいかず、悩んでおります。
プログラムは手をトラッキングしてそこに画像を被せるというプログラムです。
エラーは出ずにプログラム自体は通るのですが動作がうまくいきません。
分かる方がいたら教えてください。
開発環境
Visual Studio2015
Kinect SDK 1.5.2
開発言語はC#です

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Kinect;
using System.IO;
using System.Diagnostics;
using Nui = Microsoft.Kinect;

namespace WpfApplication4
{
/// <summary>
/// MainWindow.xaml の相互作用ロジック
/// </summary>
public partial class MainWindow : Window
{

#region メンバー変数 private KinectSensor _Kinect; private KinectSensor _KinectDevice; private readonly Brush[] _SkeltonBrushes; private Skeleton[] _FrameSkeltons; private JointType[] joints; private DotPuzzle _Puzzle; private int _PuzzleDouIndex; public MainWindow() { InitializeComponent(); this._PuzzleDouIndex = -1; this.Loaded += MainWindow_Loaded; this.Loaded += (s, e) => { DiscoverKinectSensor(); }; this.Unloaded += (s, e) => { this.Kinect = null; }; this._SkeltonBrushes = new[] { Brushes.Black,Brushes.Crimson, Brushes.Indigo, Brushes.DodgerBlue, Brushes.Purple,Brushes.Pink }; KinectSensor.KinectSensors.StatusChanged += KinectSensors_StatusChanged; this.KinectDevice = KinectSensor.KinectSensors.FirstOrDefault(x => x.Status == KinectStatus.Connected); } #region コンストラクタ #region メソッド private void DiscoverKinectSensor() { KinectSensor.KinectSensors.StatusChanged += KinectSensors_StatusChanged; this.Kinect = KinectSensor.KinectSensors.FirstOrDefault(x => x.Status == KinectStatus.Connected); } private void KinectSensors_StatusChanged(object sender, StatusChangedEventArgs e) { switch (e.Status) { case KinectStatus.Initializing: case KinectStatus.Connected: this.KinectDevice = e.Sensor; break; case KinectStatus.Disconnected: //TDSS : Kinectデバイスを接続するようにユーザーに求める this.KinectDevice = null; break; default: //TDSS : エラー状態を表示する break; } } #endregion メソッド #region プロパティ public KinectSensor Kinect { get { return this._Kinect; } set { if (this._Kinect != value) { if (this._Kinect != null) { this._Kinect = null; } if (value != null && value.Status == KinectStatus.Connected) { this._Kinect = value; } } } } public KinectSensor KinectDevice { get { return this._KinectDevice; } set { if (this._KinectDevice != value) { //解放する if (this._KinectDevice != null) { this._KinectDevice.Stop(); this._KinectDevice.SkeletonFrameReady -= KinectDevice_SkeltoFrameReady; this._KinectDevice.SkeletonStream.Disable(); this._FrameSkeltons = null; } this._KinectDevice = value; //初期化する if (this._KinectDevice != null) { if (this._KinectDevice.Status == KinectStatus.Connected) { this._KinectDevice.SkeletonStream.Enable(); _FrameSkeltons = new Skeleton[this._KinectDevice.SkeletonStream.FrameSkeletonArrayLength]; this.KinectDevice.SkeletonFrameReady += KinectDevice_SkeltoFrameReady; this.KinectDevice.Start(); } } } } } #endregion プロパティ

private void KinectDevice_SkeltoFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
using (SkeletonFrame frame = e.OpenSkeletonFrame())
{

if (frame != null)
{
frame.CopySkeletonDataTo(this._FrameSkeltons);
Skeleton skelton = GetPrimarySkelton(this._FrameSkeltons);

if (skelton == null)
{
HandCursorElement.Visibility = Visibility.Collapsed;
}
else
{
Joint primaryHand = GetPrimaryHand(skelton);
TrackHand(primaryHand);
}
}
}
}

private static Skeleton GetPrimarySkelton(Skeleton[] skeltons)
{
Skeleton skelton = null;

if (skeltons != null)
{
//もっと近くにある骨格を見つける
for (int i = 0; i < skeltons.Length; i++)
{
if (skeltons[i].TrackingState == SkeletonTrackingState.Tracked)
{
if (skelton == null)
{
skelton = skeltons[i];
}
else
{
if (skelton.Position.Z > skeltons[i].Position.Z)
{
skelton = skeltons[i];
}
}
}
}
}
return skelton;
}

private static Joint GetPrimaryHand(Skeleton skelton)
{
Joint primaryHand = new Joint();

if (skelton != null)
{
primaryHand = skelton.Joints[JointType.HandLeft];

Joint righHand = skelton.Joints[JointType.HandRight];

if (righHand.TrackingState != JointTrackingState.NotTracked)
{
if (primaryHand.TrackingState == JointTrackingState.NotTracked)
{
primaryHand = righHand;
}
else
{
if (primaryHand.Position.Z > righHand.Position.Z)
{
primaryHand = righHand;
}
}
}
}
return primaryHand;
}
private void TrackHand(Joint hand)
{
if (hand.TrackingState == JointTrackingState.NotTracked)
{
HandCursorElement.Visibility = System.Windows.Visibility.Collapsed;
}
else
{
HandCursorElement.Visibility = System.Windows.Visibility.Visible;

float x = 1; float y = 1; DepthImagePoint point = KinectDevice.MapSkeletonPointToDepth(hand.Position, DepthImageFormat.Resolution640x480Fps30); point.X = (int)((point.X * LayoutRoot.ActualWidth / this.KinectDevice.DepthStream.FrameWidth) - (HandCursorElement.ActualWidth / 2.0)); point.Y = (int)((point.Y * LayoutRoot.ActualHeight / this.KinectDevice.DepthStream.FrameHeight) - (HandCursorElement.ActualHeight / 2.0)); Canvas.SetLeft(HandCursorElement, x); Canvas.SetTop(HandCursorElement, y); if (hand.JointType == JointType.HandRight) { HandCursorScale.ScaleX = 1; } else { HandCursorScale.ScaleX = -1; } } }

以下画面設計のプログラムです
<Window x:Class="WpfApplication4.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="600" Width="800" Background="White">
<Viewbox>
<Grid x:Name="LayoutRoot" Width="1920" Height="1080">
<Polyline x:Name="CrayonElement" Stroke="Black" StrokeThickness="3"/>
<Canvas x:Name="PuzzleBoardElement"/>
<Canvas x:Name="GameBoardElement">
<Image x:Name="HandCursorElement" Source="Image\/ironman.png" Width="267" Height="343" RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform x:Name="HandCursorScale" ScaleX="1"/>
</TransformGroup>
</Image.RenderTransform>
</Image>
</Canvas>
</Grid>
</Viewbox>
</Window>

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問