Skip to main content
Version: 3.22.0 (latest)

C# samples

The bin/csharp_demo directory contains the following folders with executable files of the samples:

  • demo – An example of face tracking and face estimation.
  • video_recognition_demo – An example of identification/verification of faces on the video stream from the camera.

The following dependencies are required to build and run C# demos:

To build the demo project in VisualStudio, follow the instructions below:

  • Create an empty C# console application.
  • Add the source files of the demo to the project.
  • Add links to FacerecCSharpWrapper.dll and OpenCvSharp4.

demo

The sample demonstrates tracking, detection and cropping of faces, detection of anthropometric points and angles, as well as estimation of face quality, age and gender, emotions, and liveness (by processing an RGB image from your camera).

To make a quick run of the demo with default parameters on Windows, go to the bin/csharp_demo/demo folder and double-left-click run.bat.

Location of C# demo

Tracking results and information about each face are displayed in a window. The upper left corner shows Face SDK components, which you can turn on and off by left mouse click. This sample is similar to C++ demo. See the detailed description of the components in C++ demo.

To run the application on Linux, go to the bin/csharp_demos/video_recognition_demo directory and execute the run.sh <path_to_opencv_csharp> command, where <path_to_opencv_csharp> is the path to the directory with the OpenCvCsharp library.

You can also run C# demo, specifying some parameters (for example, the path to your online license).

To build the demo, run the following commands:

cd examples/csharp_demos/demo
dotnet publish -o publish

Startup parameters: [--config_dir=<config_dir>] [--license_dir=<license_dir>] [--capturer_config=<capturer_config>]

Where:

  • config_dir – Path to the conf/facerec directory.
  • capturer_conf – Path to the Capturer config file (learn more about Capturer config files.
  • license_dir – Path to the directory with a license; provide this parameter if you need to change a default directory license.

To run the demo on Windows:
Add the path to the directory that includes facerec.dll to the PATH environment variable.

set PATH=%PATH%; ..\...\..\bin
dotnet publish\csharp_demo.dll --config_dir=../../../conf/facerec --capturer_config=common_video_capturer_lbf.xml

To run the demo on Linux:
Add the path to the directory that includes libfacerec.so, and path to the directory with the OpenCVSharp library built for Linux to the LD_LIBRARY_PATH environment variable.

LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:../../../lib:/path/to/opencvsharp/native/libs dotnet publish/csharp_demo.dll --config_dir=../../../conf/facerec --capturer_config=common_video_capturer_lbf.xml

Error messages (if any) are printed in the console.

Source code: demo.cs

video_recognition_demo

The sample shows tracking, detection and identification/verification of faces from the database on the video stream from the camera.

Note: if you use a RealSense sensor, we recommend you to run video_recognition_demo_realsense. In this sample the RealSense SDK is used for the DepthLivenessEstimator object. See more info about liveness estimation with a depth map in the DepthLivenessEstimator section.

To make a quick run of the demo with default parameters and check face recognition on Windows, follow the steps below:

  1. Create a database to be used for face recognition (see p.1 of C++ Video Recognition Demo).
  2. To run the demo, go to bin/csharp_demo/video_recognition_demo and double-left-click run.bat.

Location of C# video_recognition_demo

  1. Tracking and identification results are displayed in a window (one window per one source). Tracked faces are highlighted with a green circle. The upper right corner of the window shows the recognition results: a tracked face is displayed on the left, and a face from the database with the name is displayed on the right.

To run the application on Linux, go to the bin/csharp_demos/video_recognition_demo directory and execute the run.sh <path_to_opencv_csharp> command, where <path_to_opencv_csharp> is the path to the directory with the OpenCvCsharp library.

You can also run C# video_recognition_demo, specifying some parameters.

To build the demo, run the following commands:

cd examples/csharp_demos/video_recognition_demo
dotnet publish -o publish

To run the demo, specify the path to the csharp_video_recognition_demo.dll library, startup options (optional) and a video source:

dotnet csharp_video_recognition_demo.dll [OPTIONS] <video_source>...

Startup examples:

  • Webcam: dotnet csharp_video_recognition_demo.dll –config_dir ../../../conf/facerec 0
  • RTSP stream: dotnet csharp_video_recognition_demo.dll –config_dir ../../../conf/facerec rtsp://localhost:8554/

Startup parameters:

[--config_dir=<config_dir>] [--license_dir=<license_dir>] [--database_dir=<database_dir>] [--method_config=<method_config>] [--recognition_far_threshold=<recognition_far_threshold>] [--frame_fps_limit=<frame_fps_limit>] (<camera_id> | <rtsp_url>)...

Where:

  • config_dir – Path to the conf/facerec directory
  • license_dir – Path to the directory with a license; provide this parameter if you need to change a default directory license
  • database_dir – Path to the directory with the database
  • method_config – Name of the Recognizer configuration file
  • recognition_far_threshold – Recognition far threshold (float number)
  • camera_id | rtsp_url – One or several sources, each source is a number (webcam ID) or a string (video stream URL or path to the video file)
  • frame_fps_limit – FPS limit

To run the demo on Windows:
Add the path to the directory that includes facerec.dll to the PATH environment variable.

set PATH=%PATH%;..\...\..\bin
dotnet publish/csharp_video_recognition_demo.dll --config_dir=../../../conf/facerec --database_dir=../../../bin/base --method_config=method6v7_recognizer.xml --recognition_far_threshold=7000 --frame_fps_limit=25 0

To run the demo on Linux:
Add the path to the directory that includes libfacerec.so and path to the directory with the OpenCVSharp library built for Linux to the LD_LIBRARY_PATH environment variable.

LD_LIBRARY_PATH=${LD_LIBRARY_PATH}: ../../../lib:~/opencv/lib/x86_64-linux-gnu dotnet publish/csharp_demo.dll --config_dir=../../../conf/facerec --database_dir=../../../bin/base --method_config=method6v7_recognizer.xml --recognition_far_threshold=7000 --frame_fps_limit=25 0

Tracking and identification results are displayed in windows (one window per one video source).

Source code: