can use use cv::AutoBuffer instead of manually allocated buffer? I think, AutoBuffer should be much more efficient