-
-
Notifications
You must be signed in to change notification settings - Fork 121
Open
Description
Hello there!
I have minimal API (.Net10) (Hier is the key method):
using SkiaSharp;
using YoloDotNet;
using YoloDotNet.Enums;
using YoloDotNet.Extensions;
using YoloDotNet.Models;
using System.Net.Mime;
namespace Object.Detection.API.Detection;
public class Detector
{
public static byte[] Detect(
IFormFile formFile,
DetectionOptions detectOptions,
DetectionDrawingOptions drawingOptions,
string onnxModel)
{
using var yolo = new Yolo(GetYoloOptions(onnxModel));
using var image = SKBitmap.Decode(formFile.OpenReadStream());
var results = yolo.RunObjectDetection(image, detectOptions.Confidence, detectOptions.IoU);
image.Draw(results, drawingOptions);
var skEncodedImageFormat = MediaTypeNameToSKEncodedImageFormat(formFile.ContentType);
image.Save("1.jpg");
return image.Encode(skEncodedImageFormat, 100).ToArray();
}
private static YoloOptions GetYoloOptions(string onnxModel) => new()
{
OnnxModel = Path.Combine("OnnxModels", onnxModel),
ImageResize = ImageResize.Proportional,
};
private static SKEncodedImageFormat MediaTypeNameToSKEncodedImageFormat(string mediaTypeName)
{
return mediaTypeName switch
{
MediaTypeNames.Image.Bmp => SKEncodedImageFormat.Bmp,
MediaTypeNames.Image.Jpeg => SKEncodedImageFormat.Jpeg,
MediaTypeNames.Image.Png => SKEncodedImageFormat.Png,
_ => throw new Exception("Unknown image format!")
};
}
}
The detected image (if I start the project local) is:
If I start this project in a docker container the output is:
Why? Thanks in advance!
Metadata
Metadata
Assignees
Labels
No labels