dme-compunet/YoloV8

Load Image

Elliot8212 opened this issue · 2 comments

Cannot use Image or Bitmap, it necessary need to be a path.

you can convert the bitmap/image to a byte array and pass it to the predictor

static byte[] ToByteArray(System.Drawing.Image imageIn, System.Drawing.Imaging.ImageFormat fmt)
{
    if (imageIn != null)
    {
        using (MemoryStream ms = new MemoryStream())
        {
            imageIn.Save(ms, fmt);
            return ms.ToArray();
        }
    }

    return new byte[] { };
}

var result = await predictor.DetectAsync(ToByteArray(image, System.Drawing.Imaging.ImageFormat.Png));

Bitmap is only in Windows, you can use the code in the comment above.