Skip to content

Object detection in docker #80

@horan74

Description

@horan74

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:

Image

If I start this project in a docker container the output is:

Image

Why? Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions