Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using OpenCV to convert camera frames to SKImage, the performance is low. Is it possible to extend a support for OpenCV Mat detection #23

Open
freefer opened this issue Sep 9, 2024 · 0 comments

Comments

@freefer
Copy link

freefer commented Sep 9, 2024

private SKBitmap MatToSkBitmap(Mat mat)
{
int width = mat.Cols;
int height = mat.Rows;
int bytesPerRow = mat.Cols * 3; // 3 bytes per pixel for BGR

// Create SKBitmap with the same size and color type
SKBitmap skBitmap = new SKBitmap(width, height);

// Get the bitmap's pixel data pointer
IntPtr skBitmapData = skBitmap.GetPixels();

// Copy data from Mat to SKBitmap
unsafe
{
    byte* matData = (byte*)mat.DataPointer;
    byte* skBitmapDataPtr = (byte*)skBitmapData.ToPointer();

    for (int row = 0; row < height; row++)
    {
        // Copy one row of pixels from Mat to SKBitmap
        System.Buffer.MemoryCopy(
            matData + row * bytesPerRow,
            skBitmapDataPtr + row * bytesPerRow,
            bytesPerRow,
            bytesPerRow
        );
    }
}

return skBitmap;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant