-
-
Notifications
You must be signed in to change notification settings - Fork 103
Description
Hello Nick,
Great package! I ran it using grayscale images and found it is not yet made for this. But it only requires a few tweaks to make it compatible. Below the changes I made in YoloCore.cs and ImateResizeExtension.cs. One only has to make the canvas grayscale or Rgb888x depending on the channel count. And handle the transform to normalized pixel values correctly.
YoloCore.cs
///
/// Initializes the YOLO model with the specified model type.
///
public void InitializeYolo()
{
...
customSizeObjectResultPool = ArrayPool.Create(maxArrayLength: OnnxModel.Outputs[0].Channels + 1, maxArraysPerBucket: 10);
_var format = (OnnxModel.Input.Channels == 1) ? SKColorType.Gray8 : SKColorType.Rgb888x;
imageInfo = new SKImageInfo(OnnxModel.Input.Width, OnnxModel.Input.Height, format, SKAlphaType.Opaque);
_pinnedMemoryPool = new PinnedMemoryBufferPool(_imageInfo);
ImageResizeExtension.cs
// Lock the pixel data for fast, unsafe memory access.
byte* pixels = (byte*)pixelsPtr;
if (colorChannels == 1) // newly added: copy 1 channel data
{
// Loop through all pixels in the image.
for (int i = 0; i < totalPixels; i++)
{
tensorArrayBuffer[i] = pixels[i] * inv255;
}
}
else
{
// Loop through all pixels in the image.
for (int i = 0; i < totalPixels; i++)
// Compute the offset into the pixel array.
int offset = i * 4; // Assuming pixel format is RGBx or similar with 4 bytes per pixel.
// Read the red, green, and blue components.
byte* px = pixels + offset;
byte r = px[0];
byte g = px[1];
,,,