C# API#
The C# API is derived directly from the C++ interfaces via SWIG. In itself, the C#/C++ interface does not introduce new logic to the API. It merely maps the C++ native data types correctly to C#.
Tip
new in 2.0.0: zero-copy memory management from C++ to C#
As the SWIG compiler creates the interface descriptions, currently we do not offer a dedicated C# API documentation. Please refer to our sample applications (publicly available here) and C++ API for details on the actual API.
Also, please do not hesitate to contact us for further assistance.
C# Example#
The following minimal example shows how to use the C# ICamera and IFrameObserver to configure the camera hardware device and attach to a camera stream. Setup and bring up should be done in a docker environment, the sample in the repository comes with ready-to-use docker and CMake files.
Setup and run#
Log into the camera (see OS section for details) and issue the following commands:
## clone the git sample repository from 3dvl gitlab server
git clone https://git.3dvisionlabs.com/3dvisionlabs/software/ecm/vl-samples.git
## enter c# sample folder
cd vl-samples/dotnet
## build docker image; build c# executable and run in docker context
./run.sh
C# code#
Main: the main program handles setup and configuration of the camera instance as well as the "outer logic", e.g. waiting for user-input before stopping the application. "Streaming mode", as outlined in the sample is the recommended way of handling the camera - asynchronously waiting for new camera images in the FrameObserver, and keeping the camera handle and config "idle" in the main tread, e.g. for handling new configurations.
using Vl;
namespace CameraTest
{
static class Program
{
private static void OnFrameIn(Frame frame)
{
Console.WriteLine("Frame Received: ");
Console.WriteLine(" Timestamp: " + frame.timestamp());
Console.WriteLine(" Width: " + frame.image().width());
Console.WriteLine(" Height: " + frame.image().height());
}
public static void Main(string[] args)
{
using var cam = camera.createCamera(0);
// define image settings for the stream
using var imgSettings = new ImageSettings();
// create a new frame observer and add a stream
// frames capture by the camera will be forwarded to the OnFrameIn function
using var frameObserver = new FrameObserver(OnFrameIn);
var streamId = cam.addStream(frameObserver, imgSettings);
cam.setTriggerMode(TriggerMode.Off);
// start the camera
// this starts the internal capture loop
cam.start();
// keep the application open until key press
if (cam.triggerMode() == TriggerMode.Software)
{
while (true)
{
var cki = Console.ReadKey();
if (cki.Key == ConsoleKey.Escape)
break;
Console.Write("Trigger");
cam.trigger();
}
}
else
{
Console.ReadKey();
}
Console.Write("Stopping");
// stop the capture loop
cam.stop();
// remove the stream
cam.removeStream(streamId);
}
}
}
Tn a second source file, the FrameObserver is demonstrated. Basically, the camera itself will spawn the handler thread for processing the image and perform a callback into FrameObserver.
using Vl;
public class FrameObserver : IFrameObserver
{
private Action<Frame> frameCallback;
public FrameObserver(Action<Frame> callback)
{
frameCallback = callback;
}
public overriupport YAML style delimiters (--- or ...) for MultiMarkdown style meta-data. In fact, MkDocs relies on the the presencde void onFrameReceived(Frame frame)
{
frameCallback(frame);
}
}