LoginSignup
4
5

More than 5 years have passed since last update.

インテル® RealSense™ 3Dカメラ を動かしてみる【Depth、IR画像の表示】

Posted at

RealSense3Dカメラ(F200)のIRカメラで取得できるDepth,IR画像を表示するプログラムを書いてみます。

前提

以下の記事の処理をベースにしています。

インテル® RealSense™ 3Dカメラ を動かしてみる【Colorカメラ画像の表示】

Depth,IR画像を表示する処理を追加しているので、ポイントとなる部分だけ記事に書いていきます。

ソース

本記事の全ソースは以下に置きました。
https://github.com/aquaring/RealSenseTestCode
「RealSenseAllCameraWPF」というプロジェクトです。

※ソースはあくまでテストコードですので、厳密にエラー処理を書いていませんし、
 カメラ制御の処理はクラスなどにせずxaml.csにべた書きにしています。
 あくまで基本的に使用方法を押さえる目的で書きました。

Depth,IRストリームの有効化

Color,Depth,IR画像を取得するためにストリームを有効化します。

MainWindows.xaml.cs
m_Cm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 1920, 1080, 30);
m_Cm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 640, 480, 30);
m_Cm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_IR, 640, 480, 30);

Depth,IR画像は最高で640x480の解像度でしか取れないのでこの値にします。
これで、フレームをサンプリングして各画像を取得できるようなります。

WriteableBitmapの作成とImageDataの取得

Color,Depth,IRのそれぞれの画像を表示するためにWritableBitmapを作りますが
以下のようにしています。

MainWindows.xaml.cs
m_ColorWBitmap = new WriteableBitmap(1920, 1080, 96.0, 96.0, PixelFormats.Bgr32, null);
m_DepthWBitmap = new WriteableBitmap(640, 480, 96.0, 96.0, PixelFormats.Gray16, null);
m_IrWBitmap = new WriteableBitmap(640, 480, 96.0, 96.0, PixelFormats.Gray8, null);

どのPixelFormatsを使うかというのは、AcquireAccessメソッドで取得するPXCMImage.ImageDataのピクセルフォーマットに合わせる必要があるので、以下リファレンスを見て
Intel® RealSense™ SDK Documentation PixelFormat

このような組み合わせにしました。

ストリーム AcquireAccessの指定 WriteableBitmapの指定 
Color PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32 PixelFormats.Bgr32
Depth PXCMImage.PixelFormat.PIXEL_FORMAT_DEPTH_RAW PixelFormats.Gray16
Ir PXCMImage.PixelFormat.PIXEL_FORMAT_Y8 PixelFormats.Gray8

ちなみにリファレンスを抜粋すると
・PIXEL_FORMAT_RGB32
The 32-bit RGB32 color format. On little endian machines, the memory layout is BGRA. See fourcc.org for the description and memory layout.

・PIXEL_FORMAT_DEPTH_RAW
The depth map data in 16-bit unsigned integer. The value precision is device specific. The application can get the device precision via the QueryDepthUnit function;

・PIXEL_FORMAT_Y8
The 8-bit gray format. Also used for the 8-bit IR data. See fourcc.org for the description and memory layout.

このように記述があるので
AcquireAccessメソッドで取得したImageDataをバイト配列に変換してWriteableBitmapにピクセルを書き込むと表示ができるという訳です。

AcquireAccessメソッドでImageDataを取得する個所は以下のようにしています。

MainWindows.xaml.cs
sample.color.AcquireAccess(
        PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32, out colorImageData);
sample.depth.AcquireAccess(
        PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_DEPTH_RAW, out depthImageData);
sample.ir.AcquireAccess(
       PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_Y8, out irImageData);

所感

これで、Color,Depth,Irフレームを取得してWriteableBitmapを使って画面に描画する処理が書けました。
Color、Depth、Irが全く別々で取得可能なのでSDKとしては非常に使いやすく感じました。

今後は、指・顔の検知、Blobの処理など基本的な機能を押さえた上で
OpenCV、OpenGL、Unityなどと組み合わせて色々やってみたいと思います。

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5