Skip to content

C# API#

The C# API wraps the native C++ interface via SWIG and is distributed as a NuGet package. All camera methods from the C++ API are available with identical names.

Sample applications are available here.

Installation#

The vl NuGet package is published to the project's public package registry — see Installation for details:

dotnet nuget add source \
  "https://git.3dvisionlabs.com/api/v4/projects/3dvisionlabs%2Fsoftware%2Fecm%2Fvl/packages/nuget/index.json" \
  --name vl

dotnet add package vl

The package targets net6.0 and bundles the native linux-arm64 runtime, so no separate C++ installation is required.

Streaming Example#

using Vl;

namespace CameraExample
{
    static class Program
    {
        private static void OnFrameReceived(Frame frame)
        {
            Console.WriteLine($"Frame: {frame.image().width()}x{frame.image().height()}"
                            + $"  timestamp: {frame.timestamp()} µs");
        }

        public static void Main(string[] args)
        {
            // Create camera (auto-detect hardware)
            using var cam = camera.makeCamera(0);

            // Configure image output
            using var settings = new ImageSettings();
            settings.format = ImageFormat.RGB888;

            // Attach observer and start streaming
            using var observer = new FrameObserver(OnFrameReceived);
            var streamId = cam.addStream(observer, settings);

            cam.start();

            Console.WriteLine("Press any key to stop...");
            Console.ReadKey();

            cam.stop();
            cam.removeStream(streamId);
        }
    }
}

FrameObserver#

The FrameObserver wraps the C++ callback pattern for C#:

using Vl;

public class FrameObserver : IFrameObserver
{
    private Action<Frame> frameCallback;

    public FrameObserver(Action<Frame> callback)
    {
        frameCallback = callback;
    }

    public override void onFrameReceived(Frame frame)
    {
        frameCallback(frame);
    }
}

Camera Configuration#

All ICamera methods are available through the SWIG wrapper:

// Exposure
cam.setAutoExposureMode(AutoControlMode.Off);
cam.setExposure(10000);  // 10 ms

// Trigger
cam.setTriggerMode(TriggerMode.Software);
cam.start();
cam.trigger();

// Settings persistence
cam.saveSettings("/path/to/config.json");
cam.loadSettings("/path/to/config.json");

Setup and Run (Docker)#

git clone https://git.3dvisionlabs.com/3dvisionlabs/software/ecm/vl-samples.git
cd vl-samples/dotnet
./run.sh