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

Convert screenshot to OpenCV Mat #36

Open
rxerox opened this issue Jul 15, 2024 · 2 comments
Open

Convert screenshot to OpenCV Mat #36

rxerox opened this issue Jul 15, 2024 · 2 comments

Comments

@rxerox
Copy link

rxerox commented Jul 15, 2024

Hi,

First, many thanks for this code/project.

Do you have a sample code to convert the screencapture to an OpenCV image ? Or a link to do this ?

Thanks.

@DarthAffe
Copy link
Owner

hey, this is just based on the docs and not tested. it assumes that emgu.cv is used and opencv has BGRA as internal color format (I couldn't verify that).

IImage image = default; // get your image here
Mat material = new Mat(image.Height, image.Width, DepthType.Cv8U, image.ColorFormat.BytesPerPixel);
image.CopyTo(new Span<byte>((void*)material.DataPointer, image.Width * image.Height * image.ColorFormat.BytesPerPixel));

or

RefImage<ColorBGRA> image = default; // get your image here
Mat material = new Mat(image.Height, image.Width, DepthType.Cv8U, ColorBGRA.ColorFormat.BytesPerPixel);
image.CopyTo(new Span<ColorBGRA>((void*)material.DataPointer, image.Width * image.Height));

I'm currently working on abstracting this kind of conversion a bit more to make it easier in the future.

@rxerox
Copy link
Author

rxerox commented Jul 17, 2024

Hi, nice and quick answer. Your right, I'am using emgu.cv, and I try your 2nd sample code : it's work fine.

Again, many thanks ;)

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

2 participants