github地址
https://github.com/NickSwardh/YoloDotNet
1.安装yoloDotNet

下面是根据官网例子,写的测试代码
private async void btnVisionTest_Click(object sender, RoutedEventArgs e)
{
string sourceImg = await VisionHelper.GetInstance().GetLocalImage();
string onnxFile = @"D:\easyboot\Onnx\best.onnx";
// Instantiate a new Yolo object
using var yolo = new Yolo(new YoloOptions
{
OnnxModel = onnxFile, // Your Yolo model in onnx format
ModelType = ModelType.ObjectDetection, // Set your model type
Cuda = false, // Use CPU or CUDA for GPU accelerated inference. Default = true
GpuId = 0, // Select Gpu by id. Default = 0
PrimeGpu = false, // Pre-allocate GPU before first inference. Default = false
// ImageResize = ImageResize.Proportional // Proportional = Default, Stretched = Squares the image
// SamplingOptions = new SKSamplingOptions(SKFilterMode.Linear, SKMipmapMode.None) // View benchmark-test examples: https://github.com/NickSwardh/YoloDotNet/blob/development/test/YoloDotNet.Benchmarks/ImageExtensionTests/ResizeImageTests.cs
});
// Load image
using var image = SKImage.FromEncodedData(sourceImg);
// Run inference and get the results
var results = yolo.RunObjectDetection(image, confidence: 0.25, iou: 0.7);
//results.ForEach(a => a.BoundingBox){
// Console.WriteLine(ar
//}
// Tip:
// Use the extension method FilterLabels([]) on any result if you only want specific labels.
// Example: Select only the labels you're interested in and exclude the rest.
// var results = yolo.RunObjectDetection(image).FilterLabels(["person", "car", "cat"]);
// Draw results
using var resultImage = image.Draw(results);
// Save to file
resultImage.Save(@"D:\new_image.jpg", SKEncodedImageFormat.Jpeg, 80);
D盘生成的图片
这个库非常简单明了
C#使用YOLO及库安装测试

1463

被折叠的 条评论
为什么被折叠?



