using OpenCvSharp;

namespace VisionBuilder.UI.Blazor.Helpers;

public static class MatExtensions
{
    public static string ToBase64DataUri(this Mat mat, int quality = 75)
    {
        if (mat == null || mat.Empty())
            return string.Empty;

        Cv2.ImEncode(".jpg", mat, out var buf,
            new ImageEncodingParam(ImwriteFlags.JpegQuality, quality));
        return $"data:image/jpeg;base64,{Convert.ToBase64String(buf)}";
    }
}
