-
-
Notifications
You must be signed in to change notification settings - Fork 25
Feature: Unsafe version of imencode()
that does not copy
#304
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
Comments
@Levi-Lesches Yes, it makes sense, so does And, actually the data will be copied 2 times, since
Will look into this in the future. |
Can't you pass a vector to imencode and send its .data() pointer over FFI? That should also result in no copying Like, change the function vecuchar_cpp2c to return a struct of vector.data() and vector.size() |
Yes it's applicable, I just didn't take it into consideration when designing, that's what I said However I have no much time to reconstruct the vector related wrappers recently, it would be nice if you can work on this. 😄 |
Sounds good, I'll submit a PR soon |
Oh, thanks for doing #305 for us! So all that's left for me to do is change all the |
Exactly. But it should be done in dartcv, so please submit PR there, we can keep tracking at rainyl/dartcv#14 |
Is your feature request related to a problem? Please describe.
The
imencode()
function has a line like this:opencv_dart/packages/dartcv/lib/src/imgcodecs/imgcodecs.dart
Lines 107 to 110 in 4983c38
I'm writing a program that tries to read from 8+ cameras, on a Raspberry Pi 5, at ~30 FPS. My old implementation passed a
(Pointer<Uint8> data, int length)
directly between isolates to avoid copying, but now I'm afraid this will introduce latency from copying all those frames.Quick math: (8 cameras) * (30 frames / second / camera) * (60,000 bytes / frame) = 14 Mb / sec.
Describe the solution you'd like
A function like the following could return the pointer itself, allowing me to pass just a single integer across isolates and send the data from native memory, avoiding all copies entirely, so long as I dispose of everything properly.
Describe alternatives you've considered
On a Windows laptop with just one integrated webcam, the current code works fine. I have yet to test this on on my 8+ cameras on a Raspberry Pi 5, so I imagine that copying will introduce unacceptable delays. I am happy to open a PR if you'd like.
It might be worth considering a breaking change in the future to make this the default behavior. Similar to
VideoCapture.read()
which returns aMat
, I think it's okay to let the caller dispose of their data manually, especially if it means avoiding some major copying.Additional context
This might help my use case even more: I recently discovered
@pragma('vm:deeply-immutable')
, which allows some objects to not be copied between isolates, but shared. As far as I know, aUint8List
does not qualify, but if I usevec.ptr.address
, that will work, and I can eliminate all copying across isolates (9+ isolates) entirely!The text was updated successfully, but these errors were encountered: