前提・実現したいこと
xbox one kinectでタッチスクリーンのように位置によって動画が変わるプログラムを作成しています。
まだ動画までの点はいけておらず、秀和システムの本を参考にしながらサンプルプログラムをもとにプログラミングしています。
点線部分に本の中でプレイヤーのビットマスク値?というものを取得しているのですが、DepthImageFrameが無くうまく取得できません。
初心者で理解も乏しい中やっていて手づまりしてしまいました。アドバイスいただけたら幸いです。
発生している問題・エラーメッセージ
DepthImageFrameに代わるもの
該当のソースコード
C#
1namespace Microsoft.Samples.Kinect.DepthBasics 2{ 3 using System; 4 using System.ComponentModel; 5 using System.Diagnostics; 6 using System.Globalization; 7 using System.IO; 8 using System.Windows; 9 using System.Windows.Input; 10 using System.Windows.Controls; 11 using System.Windows.Media; 12 using System.Windows.Media.Imaging; 13 using Microsoft.Kinect; 14 15 namespace TouchApplication 16 { 17 /// <summary> 18 /// Interaction logic for MainWindow 19 /// </summary> 20 public partial class MainWindow : Window 21 { 22 ///<summary> 23 ///セレクトモード 24 ///</summary> 25 enum SelectMode 26 { 27 NOTSELECTED, /// 領域が選択されていない 28 SELECTENG, /// 領域が選択中 29 SELECTED ///領域が選択されている 30 31 } 32 readonly int Bgr32BytesPerPixxel = PixelFormats.Bgr32.BitsPerPixel / 8; 33 readonly int ERROR_OF_POINT = -100; //タッチポイントのエラー値設定 34 35 36 SelectMode currentMode = SelectMode.NOTSELECTED; //現在の領域選択モード 37 38 Point startPoint0fRect; //指定領域の始点 39 Point preTouchPoint; //前フレームのタッチ座標 40 41 Rect selectRegin; //指定した領域 42 short[] backgroundDepthData; //領域内のデプスマップ 43 short[] depthPixel; 44 45 46 47 48 /// <summary> 49 /// Map depth range to byte range 50 /// </summary> 51 private const int MapDepthToByte = 8000 / 256; 52 53 /// <summary> 54 /// Active Kinect sensor 55 /// </summary> 56 private KinectSensor kinectSensor = null; 57 58 /// <summary> 59 /// Reader for depth frames 60 /// </summary> 61 private DepthFrameReader depthFrameReader = null; 62 63 /// <summary> 64 /// Description of the data contained in the depth frame 65 /// </summary> 66 private FrameDescription depthFrameDescription = null; 67 68 /// <summary> 69 /// Bitmap to display 70 /// </summary> 71 private WriteableBitmap depthBitmap = null; 72 73 /// <summary> 74 /// Intermediate storage for frame data converted to color 75 /// </summary> 76 private byte[] depthPixels = null; 77 78 /// <summary> 79 /// Current status text to display 80 /// </summary> 81 private string statusText = null; 82 83 /// <summary> 84 /// Initializes a new instance of the MainWindow class. 85 /// </summary> 86 public MainWindow() 87 { 88 89 90 91 // get the kinectSensor object 92 this.kinectSensor = KinectSensor.GetDefault(); 93 94 // open the reader for the depth frames 95 this.depthFrameReader = this.kinectSensor.DepthFrameSource.OpenReader(); 96 97 // wire handler for frame arrival 98 this.depthFrameReader.FrameArrived += this.Reader_FrameArrived; 99 100 // get FrameDescription from DepthFrameSource 101 this.depthFrameDescription = this.kinectSensor.DepthFrameSource.FrameDescription; 102 103 // allocate space to put the pixels being received and converted 104 this.depthPixels = new byte[this.depthFrameDescription.Width * this.depthFrameDescription.Height]; 105 106 // create the bitmap to display 107 this.depthBitmap = new WriteableBitmap(this.depthFrameDescription.Width, this.depthFrameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null); 108 109 // set IsAvailableChanged event notifier 110 this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged; 111 112 // open the sensor 113 this.kinectSensor.Open(); 114 115 // set the status text 116 this.StatusText = this.kinectSensor.IsAvailable ? Properties.Resources.RunningStatusText 117 : Properties.Resources.NoSensorStatusText; 118 119 // use the window object as the view model in this simple example 120 this.DataContext = this; 121 122 123 124 } 125 126 private Point CheckThePointTouthingTheRegin() 127 { 128 DepthFrameSource depthFrameSource = kinectSensor.DepthFrameSource; 129 int distanceThreshold = 30; 130 int distanceBetweenWallThreshold = 20; 131 var touthPoints = new BindingList<Point>(); 132 var rePoint = new Point(ERROR_OF_POINT, ERROR_OF_POINT); 133 134 // 135 for (int counter = 0, y = (int)selectRegin.Y; y < (selectRegin.Y + selectRegin.Width); y++) 136 { 137 138 for (int x = (int)selectRegin.X; x < (selectRegin.X + selectRegin.Width); x++, counter++) 139 { 140 short currentDepthVal = 141 (short)(depthPixel[y * depthBitmap.PixelWidth + x] >> ------); 142 // 143 if (backgroundDepthData[counter] > currentDepthVal && (backgroundDepthData[counter] - currentDepthVal) < distanceBetweenWallThreshold && (backgroundDepthData[counter] - currentDepthVal) > distanceBetweenWallThreshold) 144 { 145 touthPoints.Add(new Point(x, y)); 146 } 147 } 148 } 149 150 151 152 int numThreshold = 50; 153 154 if (touthPoints.Count > numThreshold) 155 { 156 double xsum = 0; 157 double ysum = 0; 158 foreach (Point p in touthPoints) 159 { 160 xsum += p.X; 161 ysum += p.Y; 162 } 163 164 rePoint.X = xsum / touthPoints.Count; 165 rePoint.Y = ysum / touthPoints.Count; 166 } 167 return rePoint; 168 } 169 170 171 172 173 174 175 176 177 178 } 179 } 180} 181
試したこと
Depthクラス、Bodyクラスを検索、DepthImageFrameの代替クラスを探索
補足情報(FW/ツールのバージョンなど)
visual studio2019
あなたの回答
tips
プレビュー