Replies: 1 comment
-
Found the reason, the format of the buffer is Bgr24 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I obtained a bytmap byte [] from shared memory in the ARM environment and attempted to retrieve RGB data for inference calculation. The implementation code is as follows:
public static byte[] GetRGBBufferByImgData(byte[] bmpBuffer, int width, int height, int channels = 3)
{
using (SKBitmap bmp = SKBitmap.Decode(bmpBuffer))
{
SKSizeI size = new(width, height);
using (SKBitmap resizedImage = bmp.Resize(size, SKFilterQuality.None))
{
var rgbBuffer = new byte[width * height * channels]; // RGB 数据缓冲区
for (int y = 0; y < resizedImage.Height; y++)
{
for (int x = 0; x < resizedImage.Width; x++)
{
int rgbIndex = (y * resizedImage.Width + x) * 3;
// 获取像素颜色信息
SKColor pixel = resizedImage.GetPixel(x, y);
// 将 BGRA8888 转换为 RGB888
rgbBuffer[rgbIndex] = pixel.Red;
rgbBuffer[rgbIndex + 1] = pixel.Green;
rgbBuffer[rgbIndex + 2] = pixel.Blue;
}
}
return rgbBuffer;
}
}
}
Then I saved the original image and RGB data as local images respectively. The original image displayed normally, while the RGB data saved image displayed abnormally. The process of saving the original image is as follows:
using (SKBitmap bmp = SKBitmap.Decode(buffer))
using (SKData data = bmp.Encode( SKEncodedImageFormat.Jpeg,100))
using (FileStream fileStream = File.OpenWrite($"files/{fileNameTemp}.jpg"))
{
data.SaveTo(fileStream);
}
Save the RGB data code as follows:
SKBitmap bitmap = new SKBitmap(640, 640);
Marshal.Copy(rgbBuffer, 0, bitmap.GetPixels(), rgbBuffer.Length);
using (SKImage image = SKImage.FromBitmap(bitmap))
using (SKData data = image.Encode(SKEncodedImageFormat.Jpeg, 100))
{
if (data != null)
{
using (FileStream fileStream = File.OpenWrite($"files/{fileNameTemp}_640.jpg"))
{
data.SaveTo(fileStream);
}
}
}
Should I do this?
Beta Was this translation helpful? Give feedback.
All reactions