Overview
The Mech-DLK SDK (C#) is a managed wrapper around the native C++ SDK, built with C++/CLI. It exposes the deep learning inference engine to .NET applications.
Quick Start
Environment Preparation
- Visual Studio 2019 or later with the .NET desktop development workload
- .NET Framework 4.6.1 (target framework
net461; included with VS)
- Mech-DLK SDK native libraries (
mmind_dl_sdk_cpp.dll, backend engines, ...) must be built first; see the C++ documentation
Open an Example in Visual Studio
Each example ships with a ready-to-use Visual Studio solution. Open the one you need, build it, and run it directly from the IDE:
start csharp\examples\basic\basic.sln
start csharp\examples\advanced\multi_thread_infer\multi_thread_infer.sln
start csharp\examples\advanced\infer_with_opencv\infer_with_opencv.sln
start csharp\examples\advanced\infer_with_halcon\infer_with_halcon.sln
Prerequisites
See the Environment Preparation section above.
Write Your Own C# Application
using System;
using System.Collections.Generic;
using System.IO;
namespace Mmind.Dl.Examples
{
class Program
{
static void Main(string[] args)
{
try
{
string imagePath = GetImagePath();
if (!File.Exists(imagePath))
{
Console.WriteLine($"Image file not found: {imagePath}");
return;
}
var status = image.CreateFromPath(imagePath);
{
Console.WriteLine($"Failed to load image: {status}");
return;
}
using (var engine = new MMindInferEngine())
{
engine.Create(GetModelPath());
status = engine.Load();
{
Console.WriteLine($"Failed to load model: {status}");
return;
}
var images = new List<MMindImage> { image };
status = engine.Infer(images);
{
Console.WriteLine($"Inference failed: {status}");
return;
}
status = engine.ResultVisualization(images);
{
image.Show("Inference Result");
}
}
Console.WriteLine("Done");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
static string GetResourcePath()
{
return Path.Combine(
AppDomain.CurrentDomain.BaseDirectory, "..", "resources");
}
static string GetImagePath()
{
return Path.Combine(
GetResourcePath(), "DefectSegmentation",
"defect_segmentation_image.jpg");
}
static string GetModelPath()
{
return Path.Combine(
GetResourcePath(), "DefectSegmentation",
"defect_segmentation_model.dlkpack");
}
}
}
Image class for MechMind DL SDK.
StatusCode
Status codes for MechMind DL SDK operations.
Compile & Run a Single Example
cd csharp\examples\basic
dotnet restore
dotnet build --configuration Release
REM Built executable lives under .\build\
.\build\example_csharp_basic.exe
- Note
- At runtime the native dependencies (
mmind_dl_sdk_cpp.dll, backend engines, OpenCV / Halcon DLLs) must be discoverable. Either copy them next to example_csharp_*.exe, or prepend the directory containing them to PATH before launching.
SDK Dependencies
The C# wrapper depends on:
- C++/CLI assembly:
mmind_dl_sdk_csharp.dll
- Native C++ SDK:
mmind_dl_sdk_cpp.dll, mmind_backendengine_cpu.dll, mmind_backendengine_cuda.dll, mmind_cuda_utils.dll
- Optional, only for the matching examples: OpenCvSharp / OpenCV native DLLs, MVTec Halcon assemblies + native DLLs + license.
Available Examples
Each example produces its own executable (defined by <AssemblyName> in the .csproj) under <example>/build/:
- example_csharp_basic (
examples/basic/): single-threaded inference with the defect segmentation model.
- example_csharp_multi_thread (
examples/advanced/multi_thread_infer/): multi-threaded inference; each worker creates its own engine instance.
- example_csharp_opencv (
examples/advanced/infer_with_opencv/): integration with OpenCvSharp for image I/O and visualization.
- example_csharp_halcon (
examples/advanced/infer_with_halcon/): integration with MVTec Halcon (HalconDotNet); requires a Halcon license.
Platform Support
- Windows x64: Full support
- C# wrapper (this SDK): Windows only — the wrapper is a C++/CLI mixed assembly and can only be built/used on Windows
- Target framework:
net461 (.NET Framework 4.6.1)