l1npengtul / nokhwa

Cross Platform Rust Library for Powerful Webcam/Camera Capture
Apache License 2.0
531 stars 137 forks source link

Reuse OpenCV matrix (decode_into_opencv_mat) #137

Closed sunsided closed 1 year ago

sunsided commented 1 year ago

Hi! I came across decode_opencv_mat and figured it might be useful to have a function that decodes into an existing matrix.

I sketched out the idea against the 0.10 branch (I failed to get senpai to work) with decode_into_opencv_mat. This function takes a mutable destination matrix, and either creates a new matrix if the destination was zero-sized or copies the decoded bytes to the existing buffer.

This behavior is different from decode_opencv_mat in that the original buffer is not shared between the decoded image and the Mat.

Now caveat emptor: I could not test it thoroughly because I'm getting a ton of OpenCV build errors, but you might have a working test suite?