flowty
flowty copied to clipboard
Replace all Mat creations with NumpyAllocator
Currently I'm pretty sure there's some nasty memory bugs waiting to surface and a lot of unnecessary data copying going on to account for this.
We should be taking advantage of the NumpyAllocator
through the pyopencv_to
and pyopencv_from
functions in https://github.com/opencv/opencv/blob/master/modules/python/src2/cv2.cpp.
I'm not 100% sure how to do this, so need to do a spike first to figure out the details. A few places to draw inspiration:
- https://github.com/robotpy/robotpy-cscore/blob/master/src/ndarray_converter.cpp
- https://stackoverflow.com/questions/32481233/opencv-cython-bridge-leaking-memory
- https://gist.github.com/denis-trofimov/cd4c29dac34cf44d6c69f5802554802c]
- http://blog.enthought.com/python/numpy-arrays-with-pre-allocated-memory/
- https://codedump.io/share/cwWNW83GXltN/1/what-is-the-easiest-way-to-convert-ndarray-into-cvmat
- https://stackoverflow.com/questions/12957492/writing-python-bindings-for-c-code-that-use-opencv/12972689#12972689
- https://stackoverflow.com/questions/22736593/what-is-the-easiest-way-to-convert-ndarray-into-cvmat