Skip to content

Construct Mat from raw pixel directly #19

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

Closed
rainyl opened this issue Apr 3, 2024 Discussed in #18 · 1 comment
Closed

Construct Mat from raw pixel directly #19

rainyl opened this issue Apr 3, 2024 Discussed in #18 · 1 comment
Assignees

Comments

@rainyl
Copy link
Owner

rainyl commented Apr 3, 2024

Discussed in #18

Originally posted by gau-nernst April 3, 2024
Typically we can access raw image data from other library as an Uint8List object. Assuming we know the format of the image (e.g. RGB uint8), what is the best (fast and convenient) way to convert it to OpenCV Mat? Some of the approaches I am thinking of:

  • Create an empty Mat with the required size. Iterate over Uint8List and copy data over. For some formats like YUV_420sp, it might be a bit tricky to copy the data correctly.
  • Encode in a lossless format (e.g. PNG) and use cv.imdecode() -> seems to be the most convenient, but there is overhead in compression-decompression.
  • Allocate C memory with Dart FFI, copy data over, create Mat from C pointer. Need to release the memory after use.
@rainyl rainyl self-assigned this Apr 3, 2024
@rainyl
Copy link
Owner Author

rainyl commented Apr 7, 2024

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