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

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

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

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

Visual Studio

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

Kinect

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

Q&A

解決済

1回答

3990閲覧

Kinectで一定の距離範囲だけ深度画像が抽出されるプログラムを書いているのですが...

BOSS723

総合スコア35

C#

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

Visual Studio

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

Kinect

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

0グッド

0クリップ

投稿2016/09/28 10:18

編集2016/09/28 10:36

私のプログラムだとこの画像の通りの結果が出ます。
しかし背景を白に、人間を黒っぽく出したいのですが、どのように変えたらなるのかわかりません。
色々試してみたのですが上手くいかず...
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}

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

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

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

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

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

guest

回答1

0

ベストアンサー

おそらくですが。

C#

1 this.colorPixels[colorPixelIndex++] = intensity; 2 this.colorPixels[colorPixelIndex++] = intensity; 3 this.colorPixels[colorPixelIndex++] = intensity; 4 5 ++colorPixelIndex;

この部分の配列につっこんでいる部分が R G B A(アルファは飛ばしている)
という感じになっていると思われるので、intensity というのを、お望みの色味に変更すれば
いいのではないでしょうか。

投稿2016/09/28 11:34

mugicya

総合スコア1046

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

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

BOSS723

2016/09/28 17:08

あ、できました!ありがとうございますm(__)m
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問