0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

C#でAzure Kinect / Femto Boltを使う

Last updated at Posted at 2025-03-08

はじめに

Azure KinectにはAzure-Kinect-Sensor-SDKが、Femto BoltにはOrbbecSDKまたはOrbbecSDK-K4A-Wrapperがあります。
しかし、これらはいずれもC/C++で使う必要があります。

これを利用すれば、Azure KinectやFemto BoltをC#で使えます。

Microsoftの公式Azure Kinect向けパッケージにはMicrosoft.Azure.Kinect.SensorMicrosoft.Azure.Kinect.BodyTrackingがあります。
OrbbecにはOrbbecSDK_CSharpOrbbecUnitySDKがありますが、NuGetパッケージはありません。

いずれにせよ、統一的な公式C#インターフェースはないようです。

k4a.netの使い方

まずはNuGetパッケージを追加します。

そしてソリューションファイルのAny CPUの部分をx64に置き換えます

あとはAzure Kinectのドキュメントを見たり、リポジトリのK4AdotNet.Samples.*を見たり、入力補完に頼ったりすればいけます。

RGBカメラを開始して終了する例

using K4AdotNet.Sensor;

var deviceCount = Device.InstalledCount;
Console.WriteLine($"Device Count: {deviceCount}");

if (deviceCount == 0)
{
    throw new Exception("Not found: Kinect Device");
}

using (var device = Device.Open())
{
    Console.WriteLine($"Serial Number: {device.SerialNumber}");

    var deviceConfig = new DeviceConfiguration
    {
        CameraFps = FrameRate.Thirty,
        ColorFormat = ImageFormat.ColorBgra32,
        ColorResolution = ColorResolution.R720p,
        DepthMode = DepthMode.Off
    };

    device.StartCameras(deviceConfig);

    Console.WriteLine("Camera started and stopping...");

    device.StopCameras();
}

Body Trackingで人数を数える例

using K4AdotNet.Sensor;
using K4AdotNet.BodyTracking;

var deviceCount = Device.InstalledCount;
Console.WriteLine($"Device Count: {deviceCount}");

if (deviceCount == 0)
{
    throw new Exception("Not found: Kinect Device");
}

using (var device = Device.Open())
{
    Console.WriteLine($"Serial Number: {device.SerialNumber}");

    var deviceConfig = new DeviceConfiguration
    {
        CameraFps = FrameRate.Thirty,
        DepthMode = DepthMode.NarrowViewUnbinned,
        ColorResolution = ColorResolution.Off
    };
    device.StartCameras(deviceConfig);

    device.GetCalibration(deviceConfig.DepthMode, deviceConfig.ColorResolution, out var calibration);

    var trackerConfig = TrackerConfiguration.Default;
    using (var tracker = new Tracker(calibration, trackerConfig))
    {
        using (var capture = device.GetCapture())
        {
            tracker.EnqueueCapture(capture);
        }

        using (var bodyFrame = tracker.PopResult())
        {
            Console.WriteLine($"Timestamp: {bodyFrame.DeviceTimestamp}");
            Console.WriteLine($"Body Count: {bodyFrame.BodyCount}");
        }

        tracker.Shutdown();
    }

    device.StopCameras();
}

device.GetCalibrationdevice.StartCamerasの前でも呼び出せるはずです

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?