Skip to content

Getting Started

Speykious edited this page Feb 23, 2022 · 6 revisions

First of all, install the SeeShark NuGet package:

On the Visual Studio Package Manager Console:

PM> Install-Package SeeShark

or on the .NET CLI:

dotnet add package SeeShark

You'll also need the ffmpeg 5 native shared libraries on your system.

If you are having trouble loading FFmpeg libraries, see how you can debug it.


Start by adding a reference to SeeShark at the top of the file, like so:

using SeeShark.Device;

In order to enumerate all the cameras plugged into the PC you use the CameraManager class.

var manager = new CameraManager();

The devices will be listed under manager.Devices.

After you have chosen your device, you can instantiate it using

Camera camera = manager.GetDevice(/* int or CameraInfo object */);

Note: both CameraManager and Camera implement IDisposable, so remember to dispose them after use by calling Dispose(), or declare them with the using var syntax.

Since SeeShark 3.0.0, there are now two ways of getting image frames: a synchronous way and an asynchronous one. (you can not use both at the same time)


Getting frames synchronously

All you need to do, is call either camera.GetFrame() or camera.TryGetFrame(out Frame frame)

The difference between the two methods is that the first will throw when there are no more frames, while the latter one will not, as it reports a status.

Additionally, the latter one can also report when a frame gets duplicated, by returning DecodeStatus.NoFrameAvailable.


Getting frames asynchronously

You can listen to the OnFrame event, that will be called whenever a frame is available, creating the OnFrameEventHandler() method.

camera.OnFrame += OnFrameEventHandler;

void OnFrameEventHandler(object sender, FrameEventArgs e)
{
    // Here you will be using your camera frames.
}

You will get access to the frame in e.Frame, as well as the status of the frame in e.Status. It can either be:

  • NewFrame: it is a new frame.
  • NoFrameAvailable: no new frame available, e.Frame is the previous frame.
  • EndOfStream: stream of frames ended. Will probably never happen for a camera.

After you start listening to the event, you can start the capture with

camera.StartCapture();

After you got the frames, you might want to actually use them. For that, you can look into Saving images.