私のプログラムだとこの画像の通りの結果が出ます。
しかし背景を白に、人間を黒っぽく出したいのですが、どのように変えたらなるのかわかりません。
色々試してみたのですが上手くいかず...
C#もVisual StudioもKinectも私は初心者なのでまだちゃんと理解していないのが悪いのですが何か解決策がありましたらご教授願いたいです。
C#
1using System; 2using System.IO; 3using System.Windows; 4using System.Windows.Media; 5using System.Windows.Media.Imaging; 6using Microsoft.Kinect; 7 8namespace DepthBasics 9{ 10 public partial class MainWindow : Window 11 { 12 private KinectSensor sensor; 13 private WriteableBitmap colorBitmap; 14 private DepthImagePixel[] depthPixels; 15 private byte[] colorPixels; 16 17 public MainWindow() 18 { 19 InitializeComponent(); 20 try 21 { 22 //Kinectが接続されているかどうか確認する 23 if (KinectSensor.KinectSensors.Count == 0) 24 { 25 string msg = "Kinect for Windows センサーが " + "接続されていません。"; 26 throw new Exception(msg); 27 } 28 } 29 catch (Exception ex) 30 { 31 MessageBox.Show(ex.Message); 32 } 33 } 34 35 private void WindowLoaded(object sender, RoutedEventArgs e) 36 { 37 38 foreach (var potentialSensor in KinectSensor.KinectSensors) 39 { 40 if (potentialSensor.Status == KinectStatus.Connected) 41 { 42 this.sensor = potentialSensor; 43 break; 44 } 45 } 46 47 if (null != this.sensor) 48 { 49 this.sensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30); 50 this.depthPixels = new DepthImagePixel[this.sensor.DepthStream.FramePixelDataLength]; 51 this.colorPixels = new byte[this.sensor.DepthStream.FramePixelDataLength * sizeof(int)]; 52 this.colorBitmap = new WriteableBitmap(this.sensor.DepthStream.FrameWidth, this.sensor.DepthStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null); 53 this.Image.Source = this.colorBitmap; 54 this.sensor.DepthFrameReady += this.SensorDepthFrameReady; 55 56 try 57 { 58 this.sensor.Start(); 59 } 60 catch (IOException) 61 { 62 this.sensor = null; 63 } 64 } 65 } 66 67 private void WindowClosing(object sender, System.ComponentModel.CancelEventArgs e) 68 { 69 if (null != this.sensor) 70 { 71 this.sensor.Stop(); 72 } 73 } 74 75 private void SensorDepthFrameReady(object sender, DepthImageFrameReadyEventArgs e) 76 { 77 using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) 78 { 79 if (depthFrame != null) 80 { 81 82 depthFrame.CopyDepthImagePixelDataTo(this.depthPixels); 83 84 int minDepth = 500; 85 int maxDepth = 900; 86 87 int colorPixelIndex = 0; 88 89 for (int i = 0; i < this.depthPixels.Length; ++i) 90 { 91 short depth = depthPixels[i].Depth; 92 93 byte intensity = (byte)(depth >= minDepth && depth <= maxDepth ? depth : 0); 94 95 this.colorPixels[colorPixelIndex++] = intensity; 96 this.colorPixels[colorPixelIndex++] = intensity; 97 this.colorPixels[colorPixelIndex++] = intensity; 98 99 ++colorPixelIndex; 100 } 101 102 this.colorBitmap.WritePixels( 103 new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight), 104 this.colorPixels, 105 this.colorBitmap.PixelWidth * sizeof(int), 106 0); 107 } 108 } 109 } 110 } 111}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/28 17:08