manual memory handling is error-prone, we try to avoid it by all means. Use std::vector or cv::AutoBuffer. The buffer may not be well-aligned, so make it slightly bigger and then use alignPtr() before passing the pointer to fund().