Closed bnuzhouwei closed 10 months ago
Thank you very much for your report! You are absolutely right. I think that a little later I will transfer the stack to another core for working with images
sys.drawing namespace also can't be used in UWP (not supported), use bytes or stream is better, I think.
@bnuzhouwei , @songshizhao you can use float[][,] methods
Any chance you could update the examples to use this new method? Then it would be properly cross-platform. I'm going to use ImageSharp
to load the bitmap, but it would be great if there was an example showing either ImageSharp
or SkiaSharp
bitmaps.
Any chance you could update the examples to use this new method? Then it would be properly cross-platform. I'm going to use
ImageSharp
to load the bitmap, but it would be great if there was an example showing eitherImageSharp
orSkiaSharp
bitmaps.
I asked ChatGPT and it gave me this example:
using SkiaSharp;
using System.Numerics;
public float[][,] ConvertSKBitmapToFloatArray(SKBitmap bitmap)
{
// Ensure the bitmap is in BGR8888 format
if (bitmap.ColorType != SKColorType.Rgb && bitmap.AlphaType != SKAlphaType.Opaque)
{
bitmap = bitmap.Copy(SKColorType.Rgb, SKAlphaType.Opaque);
}
// Lock pixels to get access to pixel data
using (var info = bitmap.PeekPixels())
{
if (info == null)
{
throw new InvalidOperationException("Failed to peek pixels from bitmap.");
}
var bytes = info.GetPixels();
var width = bitmap.Width;
var height = bitmap.Height;
// Convert byte array to float array
var floatArray = new float[3, height, width];
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
var index = (y * width + x) * 4; // Each pixel is 4 bytes
var b = bytes[index];
var g = bytes[index + 1];
var r = bytes[index + 2];
// Normalize values
floatArray[0, y, x] = b / 255.0f; // Blue
floatArray[1, y, x] = g / 255.0f; // Green
floatArray[2, y, x] = r / 255.0f; // Red
}
}
return floatArray;
}
}
Maybe helpful?
Any chance you could update the examples to use this new method? Then it would be properly cross-platform. I'm going to use
ImageSharp
to load the bitmap, but it would be great if there was an example showing eitherImageSharp
orSkiaSharp
bitmaps.
@Webreaper , @Misaka12456 or you can try something like this https://github.com/FaceONNX/FaceONNX/blob/main/netstandard/Examples/FaceEmbeddingsClassification/Program.cs
I already submitted a PR (https://github.com/FaceONNX/FaceONNX/pull/22) which fixes this and makes it cross-platform.
I already submitted a PR (#22) which fixes this and makes it cross-platform.
I actually use it in Emgu.CV Mat, but I didn't find a best solution... @asiryan Do you have any other example?
I already submitted a PR (#22) which fixes this and makes it cross-platform.
I actually use it in Emgu.CV Mat, but I didn't find a best solution... @asiryan Do you have any other example?
Do you need an example with Emgu.CV?
yeah.... planned to use faceonnx for a real-time face detection
@Misaka12456 I think you can find information about images and their transformations here https://www.emgu.com/wiki/index.php/Working_with_Images
@Misaka12456 I think you can find information about images and their transformations here https://www.emgu.com/wiki/index.php/Working_with_Images
thx
System.Drawing is not suit for linux, for libgdiplus has memory leak problem in linux, and have been removed since .net7.