I use CustomVision.AI to tag images, then train, test and tune models for my projects. I wanted to be able to export a model for use on a embedded device with minimal manual steps so the Object Detection-ASP.NET Core Web & WPF Desktop Sample in the dotnet/machine-learning-samples looked like a reasonable place to get some “inspiration”.
I updated the OnnxObjectDectection library, OnnxObjectDetectionApp, and OnnxObjectDetectionWeb project Nugets to the latest versions then “smoke tested” the desktop and web applications.
The desktop application used the OpenCvSharp3-AnyCPU NuGet which had been deprecated so I upgraded to OpenCvSharp4-Windows NuGet which required a couple of small code modification.
private async Task CaptureCamera(CancellationToken token)
{
if (capture == null)
capture = new VideoCapture();
capture.Open(0,apiPreference:VideoCaptureAPIs.DSHOW);
if (capture.IsOpened())
{
while (!token.IsCancellationRequested)
{
using MemoryStream memoryStream = capture.RetrieveMat().Flip(FlipMode.Y).ToMemoryStream();
await Application.Current.Dispatcher.InvokeAsync(() =>
{
var imageSource = new BitmapImage();
imageSource.BeginInit();
imageSource.CacheOption = BitmapCacheOption.OnLoad;
imageSource.StreamSource = memoryStream;
imageSource.EndInit();
WebCamImage.Source = imageSource;
});
var bitmapImage = new Bitmap(memoryStream);
await ParseWebCamFrame(bitmapImage, token);
}
capture.Release();
}
}
I ran the OnnxObjectDetectionApp and the provided TinyYolo2_model.onnx model using my webcam.
I ran the OnnxObjectDetectionWeb with the provided TinyYolo2_model.onnx model and a photograph of a car I used to own.

I have a simple CustomVision.AI demo project for counting toy farm animals which I used to test my modifications.
I exported The ToyCowCounter in ONNX format
I copied the exported file to the OnnxModels folder, and then in the Visual Studio 2019 solution explorer configured the file properties “Build Action-Content” and “Copy To Output Directory-Copy if newer”.
When I restarted the OnnxObjectDetectionApp the application would detect my toy cows with a reasonable accuracy.
The accuracy of the ToyCowCounter model wasn’t great as it had been trained with a limited dataset collected with a different camera and a plain backdrop.