Tags: AnyVisionltd/gocv
Tags
imencode: optimize IMEncode avoiding multiple data copies. Currently IMEncode implemented the following way: 1) In Image_IMEncode std::vector is allocated and filled by cv::imencode 2) In Image_IMEncode function toByteArray allocated another native array and copies the data from the vector 3) In IMEncode the result of Image_IMEncode is further copied to golang allocated byte array. Hence there are 2 additional copies of the data for each call to IMEncode. This is highly inefficient, especially if this needs to be performed frequently. The solution is to avoid copies altogether (though with a slight API cost). First we introduce NativeByteBuffer struct which is just a wrapper for std::vector. Note that it is hard-coded 24 bytes (std::vector is 3 pointers of data, and this will never change as this will force recompilation of probably every existing c++ application). Second We call Image_IMEncode with this "preallocated" and pre-initialied std::vector. Finally the "func (buffer *NativeByteBuffer) GetBytes() []byte" function returns a hand-made slice from the underlying std::vector buffer. Note that we both provide a "Close" function and register "finalizer" to clear the native buffer when NativeByteBuffer goes out of scope. Usage Example: buf, err := IMEncode(PNGFileExt, img) defer buf.Close() bytes := buf.GetBytes()
imencode: optimize IMEncode avoiding multiple data copies. Currently IMEncode implemented the following way: 1) In Image_IMEncode std::vector is allocated and filled by cv::imencode 2) In Image_IMEncode function toByteArray allocated another native array and copies the data from the vector 3) In IMEncode the result of Image_IMEncode is further copied to golang allocated byte array. Hence there are 2 additional copies of the data for each call to IMEncode. This is highly inefficient, especially if this needs to be performed frequently. The solution is to avoid copies altogether (though with a slight API cost). First we introduce NativeByteBuffer struct which is just a wrapper for std::vector. Note that it is hard-coded 24 bytes (std::vector is 3 pointers of data, and this will never change as this will force recompilation of probably every existing c++ application). Second We call Image_IMEncode with this "preallocated" and pre-initialied std::vector. Finally the "func (buffer *NativeByteBuffer) GetBytes() []byte" function returns a hand-made slice from the underlying std::vector buffer. Note that we both provide a "Close" function and register "finalizer" to clear the native buffer when NativeByteBuffer goes out of scope. Usage Example: buf, err := IMEncode(PNGFileExt, img) defer buf.Close() bytes := buf.GetBytes()
imencode: optimize IMEncode avoiding multiple data copies. Currently IMEncode implemented the following way: 1) In Image_IMEncode std::vector is allocated and filled by cv::imencode 2) In Image_IMEncode function toByteArray allocated another native array and copies the data from the vector 3) In IMEncode the result of Image_IMEncode is further copied to golang allocated byte array. Hence there are 2 additional copies of the data for each call to IMEncode. This is highly inefficient, especially if this needs to be performed frequently. The solution is to avoid copies altogether (though with a slight API cost). First we introduce NativeByteBuffer struct which is just a wrapper for std::vector. Note that it is hard-coded 24 bytes (std::vector is 3 pointers of data, and this will never change as this will force recompilation of probably every existing c++ application). Second We call Image_IMEncode with this "preallocated" and pre-initialied std::vector. Finally the "func (buffer *NativeByteBuffer) GetBytes() []byte" function returns a hand-made slice from the underlying std::vector buffer. Note that we both provide a "Close" function and register "finalizer" to clear the native buffer when NativeByteBuffer goes out of scope. Usage Example: buf, err := IMEncode(PNGFileExt, img) defer buf.Close() bytes := buf.GetBytes()
imencode: optimize IMEncode avoiding multiple data copies. Currently IMEncode implemented the following way: 1) In Image_IMEncode std::vector is allocated and filled by cv::imencode 2) In Image_IMEncode function toByteArray allocated another native array and copies the data from the vector 3) In IMEncode the result of Image_IMEncode is further copied to golang allocated byte array. Hence there are 2 additional copies of the data for each call to IMEncode. This is highly inefficient, especially if this needs to be performed frequently. The solution is to avoid copies altogether (though with a slight API cost). First we introduce NativeByteBuffer struct which is just a wrapper for std::vector. Note that it is hard-coded 24 bytes (std::vector is 3 pointers of data, and this will never change as this will force recompilation of probably every existing c++ application). Second We call Image_IMEncode with this "preallocated" and pre-initialied std::vector. Finally the "func (buffer *NativeByteBuffer) GetBytes() []byte" function returns a hand-made slice from the underlying std::vector buffer. Note that we both provide a "Close" function and register "finalizer" to clear the native buffer when NativeByteBuffer goes out of scope. Usage Example: buf, err := IMEncode(PNGFileExt, img) defer buf.Close() bytes := buf.GetBytes()
imencode: optimize IMEncode avoiding multiple data copies. Currently IMEncode implemented the following way: 1) In Image_IMEncode std::vector is allocated and filled by cv::imencode 2) In Image_IMEncode function toByteArray allocated another native array and copies the data from the vector 3) In IMEncode the result of Image_IMEncode is further copied to golang allocated byte array. Hence there are 2 additional copies of the data for each call to IMEncode. This is highly inefficient, especially if this needs to be performed frequently. The solution is to avoid copies altogether (though with a slight API cost). First we introduce NativeByteBuffer struct which is just a wrapper for std::vector. Note that it is hard-coded 24 bytes (std::vector is 3 pointers of data, and this will never change as this will force recompilation of probably every existing c++ application). Second We call Image_IMEncode with this "preallocated" and pre-initialied std::vector. Finally the "func (buffer *NativeByteBuffer) GetBytes() []byte" function returns a hand-made slice from the underlying std::vector buffer. Note that we both provide a "Close" function and register "finalizer" to clear the native buffer when NativeByteBuffer goes out of scope. Usage Example: buf, err := IMEncode(PNGFileExt, img) defer buf.Close() bytes := buf.GetBytes()
release: updates for v0.27.0 release Signed-off-by: deadprogram <[email protected]>
docs: update for 0.26.0 release Signed-off-by: deadprogram <[email protected]>
release: prepare for v0.25.0 Signed-off-by: deadprogram <[email protected]>
PreviousNext