From 6eb0dc97f530aca0d1735107297e2f0a0bedab29 Mon Sep 17 00:00:00 2001 From: Pierre Chatelier Date: Tue, 16 Jun 2026 17:51:37 +0200 Subject: [PATCH] Merge pull request #28907 from chacha21:more_autobuffer More use of AutoBuffer #28907 When possible, AutoBuffer should be faster than std::vector<>, and should not be worse if it requires a heap allocation rather than a stack allocation. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [X] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [X] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake --- modules/calib3d/src/homography_decomp.cpp | 5 +-- modules/core/src/matrix_transform.cpp | 8 ++--- modules/core/src/minmax.cpp | 2 +- .../core/src/persistence_base64_encoding.cpp | 8 ++--- modules/core/src/persistence_types.cpp | 2 +- modules/features2d/src/blobdetector.cpp | 10 +++--- modules/features2d/src/keypoint.cpp | 4 +-- modules/features2d/src/orb.cpp | 4 +-- modules/features2d/src/sift.dispatch.cpp | 2 +- .../include/opencv2/flann/ground_truth.h | 4 +-- .../flann/hierarchical_clustering_index.h | 4 +-- .../include/opencv2/flann/index_testing.h | 4 +-- .../flann/include/opencv2/flann/lsh_table.h | 2 +- .../imgproc/src/bilateral_filter.dispatch.cpp | 16 +++++----- modules/imgproc/src/connectedcomponents.cpp | 32 +++++++++---------- modules/imgproc/src/deriv.cpp | 2 +- modules/imgproc/src/hough.cpp | 14 ++++---- modules/imgproc/src/median_blur.simd.hpp | 4 +-- modules/imgproc/src/morph.dispatch.cpp | 2 +- modules/imgproc/src/subdivision2d.cpp | 2 ++ modules/imgproc/src/templmatch.cpp | 3 +- modules/video/src/optflowgf.cpp | 2 +- 22 files changed, 70 insertions(+), 66 deletions(-) diff --git a/modules/calib3d/src/homography_decomp.cpp b/modules/calib3d/src/homography_decomp.cpp index 3bfb62ec2c..001a7cfb1c 100644 --- a/modules/calib3d/src/homography_decomp.cpp +++ b/modules/calib3d/src/homography_decomp.cpp @@ -517,7 +517,7 @@ void filterHomographyDecompByVisibleRefpoints(InputArrayOfArrays _rotations, CV_Assert(pointsMask.empty() || pointsMask.checkVector(1, CV_8U) == npoints); const uchar* pointsMaskPtr = pointsMask.data; - std::vector solutionMask(nsolutions, (uchar)1); + AutoBuffer solutionMask(nsolutions, (uchar)1); std::vector normals(nsolutions); std::vector rotnorm(nsolutions); Mat R; @@ -559,7 +559,8 @@ void filterHomographyDecompByVisibleRefpoints(InputArrayOfArrays _rotations, if( solutionMask[i] ) possibleSolutions.push_back(i); - Mat(possibleSolutions).copyTo(_possibleSolutions); + constexpr int cvType = traits::Type::value; + Mat(static_cast(possibleSolutions.size()), 1, cvType, possibleSolutions.data()).copyTo(_possibleSolutions); } } //namespace cv diff --git a/modules/core/src/matrix_transform.cpp b/modules/core/src/matrix_transform.cpp index 245cd89843..e53462fdf8 100644 --- a/modules/core/src/matrix_transform.cpp +++ b/modules/core/src/matrix_transform.cpp @@ -558,7 +558,7 @@ void transposeND(InputArray src_, const std::vector& order, OutputArray dst CV_CheckEQ(static_cast(order_[i]), i, "New order should be a valid permutation of the old one"); } - std::vector newShape(order.size()); + AutoBuffer newShape(order.size()); for (size_t i = 0; i < order.size(); ++i) { newShape[i] = inp.size[order[i]]; @@ -582,7 +582,7 @@ void transposeND(InputArray src_, const std::vector& order, OutputArray dst size_t continuous_size = continuous_idx == 0 ? out.total() : out.step1(continuous_idx - 1); size_t outer_size = out.total() / continuous_size; - std::vector steps(order.size()); + AutoBuffer steps(order.size()); for (int i = 0; i < static_cast(steps.size()); ++i) { steps[i] = inp.step1(order[i]); @@ -1229,7 +1229,7 @@ void broadcast(InputArray _src, InputArray _shape, OutputArray _dst) { // impl _dst.create(dims_shape, shape.ptr(), src.type()); Mat dst = _dst.getMat(); - std::vector is_same_shape(dims_shape, 0); + AutoBuffer is_same_shape(dims_shape, 0); for (int i = 0; i < static_cast(shape_src.size()); ++i) { if (shape_src[i] == ptr_shape[i]) { is_same_shape[i] = 1; @@ -1328,7 +1328,7 @@ void broadcast(InputArray _src, InputArray _shape, OutputArray _dst) { std::memcpy(p_dst + dst_offset, p_src + src_offset, dst.elemSize()); } // broadcast copy (dst inplace) - std::vector cumulative_shape(dims_shape, 1); + AutoBuffer cumulative_shape(dims_shape, 1); int total = static_cast(dst.total()); for (int i = dims_shape - 1; i >= 0; --i) { cumulative_shape[i] = static_cast(total / ptr_shape[i]); diff --git a/modules/core/src/minmax.cpp b/modules/core/src/minmax.cpp index d89a10a906..ae5823679f 100644 --- a/modules/core/src/minmax.cpp +++ b/modules/core/src/minmax.cpp @@ -1330,7 +1330,7 @@ static void reduceMinMax(cv::InputArray src, cv::OutputArray dst, ReduceMode mod axis = (axis + srcMat.dims) % srcMat.dims; CV_Assert(srcMat.channels() == 1 && axis >= 0 && axis < srcMat.dims); - std::vector sizes(srcMat.dims); + cv::AutoBuffer sizes(srcMat.dims); std::copy(srcMat.size.p, srcMat.size.p + srcMat.dims, sizes.begin()); sizes[axis] = 1; diff --git a/modules/core/src/persistence_base64_encoding.cpp b/modules/core/src/persistence_base64_encoding.cpp index 3fce79c080..e2f15fdbcc 100644 --- a/modules/core/src/persistence_base64_encoding.cpp +++ b/modules/core/src/persistence_base64_encoding.cpp @@ -65,15 +65,15 @@ public: /* * a convertor must provide : * - `operator >> (uchar * & dst)` for writing current binary data to `dst` and moving to next data. - * - `operator bool` for checking if current loaction is valid and not the end. + * - `operator bool` for checking if current location is valid and not the end. */ template inline Base64ContextEmitter & write(_to_binary_convertor_t & convertor) { - static const size_t BUFFER_MAX_LEN = 1024U; + constexpr size_t BUFFER_MAX_LEN = 1024U; - std::vector buffer(BUFFER_MAX_LEN); - uchar * beg = buffer.data(); + uchar buffer[BUFFER_MAX_LEN]; + uchar * beg = buffer; uchar * end = beg; while (convertor) { diff --git a/modules/core/src/persistence_types.cpp b/modules/core/src/persistence_types.cpp index 6ea259d9bc..2eeb7b4604 100644 --- a/modules/core/src/persistence_types.cpp +++ b/modules/core/src/persistence_types.cpp @@ -75,7 +75,7 @@ void write( FileStorage& fs, const String& name, const SparseMat& m ) fs << "data" << "[:"; size_t i = 0, n = m.nzcount(); - std::vector elems(n); + AutoBuffer elems(n); SparseMatConstIterator it = m.begin(), it_end = m.end(); for( ; it != it_end; ++it ) diff --git a/modules/features2d/src/blobdetector.cpp b/modules/features2d/src/blobdetector.cpp index 7cd49d8193..7e9b7053fe 100644 --- a/modules/features2d/src/blobdetector.cpp +++ b/modules/features2d/src/blobdetector.cpp @@ -332,11 +332,13 @@ void SimpleBlobDetectorImpl::findBlobs(InputArray _image, InputArray _binaryImag //compute blob radius { - std::vector dists; - for (size_t pointIdx = 0; pointIdx < contours[contourIdx].size(); pointIdx++) + const std::vector& contour = contours[contourIdx]; + const size_t contourSize = contour.size(); + AutoBuffer dists(contourSize); + for (size_t pointIdx = 0; pointIdx < contourSize; pointIdx++) { - Point2d pt = contours[contourIdx][pointIdx]; - dists.push_back(norm(center.location - pt)); + const Point2d& pt = contour[pointIdx]; + dists[pointIdx] = norm(center.location - pt); } std::sort(dists.begin(), dists.end()); center.radius = (dists[(dists.size() - 1) / 2] + dists[dists.size() / 2]) / 2.; diff --git a/modules/features2d/src/keypoint.cpp b/modules/features2d/src/keypoint.cpp index aad9fe36e3..38374890a0 100644 --- a/modules/features2d/src/keypoint.cpp +++ b/modules/features2d/src/keypoint.cpp @@ -221,8 +221,8 @@ struct KeyPoint_LessThan void KeyPointsFilter::removeDuplicated( std::vector& keypoints ) { int i, j, n = (int)keypoints.size(); - std::vector kpidx(n); - std::vector mask(n, (uchar)1); + AutoBuffer kpidx(n); + AutoBuffer mask(n, (uchar)1); for( i = 0; i < n; i++ ) kpidx[i] = i; diff --git a/modules/features2d/src/orb.cpp b/modules/features2d/src/orb.cpp index d33758c6f9..3d79edf151 100644 --- a/modules/features2d/src/orb.cpp +++ b/modules/features2d/src/orb.cpp @@ -839,7 +839,7 @@ static void computeKeyPoints(const Mat& imagePyramid, #endif int i, nkeypoints, level, nlevels = (int)layerInfo.size(); - std::vector nfeaturesPerLevel(nlevels); + AutoBuffer nfeaturesPerLevel(nlevels); // fill the extractors and descriptors for the corresponding scales float factor = (float)(1.0 / scaleFactor); @@ -877,7 +877,7 @@ static void computeKeyPoints(const Mat& imagePyramid, allKeypoints.clear(); std::vector keypoints; - std::vector counters(nlevels); + AutoBuffer counters(nlevels); keypoints.reserve(nfeaturesPerLevel[0]*2); for( level = 0; level < nlevels; level++ ) diff --git a/modules/features2d/src/sift.dispatch.cpp b/modules/features2d/src/sift.dispatch.cpp index 3f4a7ceb41..f7c6116093 100644 --- a/modules/features2d/src/sift.dispatch.cpp +++ b/modules/features2d/src/sift.dispatch.cpp @@ -225,7 +225,7 @@ void SIFT_Impl::buildGaussianPyramid( const Mat& base, std::vector& pyr, in { CV_TRACE_FUNCTION(); - std::vector sig(nOctaveLayers + 3); + AutoBuffer sig(nOctaveLayers + 3); pyr.resize(nOctaves*(nOctaveLayers + 3)); // precompute Gaussian sigmas using the following formula: diff --git a/modules/flann/include/opencv2/flann/ground_truth.h b/modules/flann/include/opencv2/flann/ground_truth.h index 4c030bc040..6cd2d6731c 100644 --- a/modules/flann/include/opencv2/flann/ground_truth.h +++ b/modules/flann/include/opencv2/flann/ground_truth.h @@ -47,8 +47,8 @@ void find_nearest(const Matrix& dataset, typenam typedef typename Distance::ResultType DistanceType; int n = nn + skip; - std::vector match(n); - std::vector dists(n); + cv::AutoBuffer match(n); + cv::AutoBuffer dists(n); dists[0] = distance(dataset[0], query, dataset.cols); match[0] = 0; diff --git a/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h b/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h index 9567d71f5e..56ae38e8c1 100644 --- a/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h +++ b/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h @@ -686,8 +686,8 @@ private: return; } - std::vector centers(branching); - std::vector labels(indices_length); + cv::AutoBuffer centers(branching); + cv::AutoBuffer labels(indices_length); int centers_length; (this->*chooseCenters)(branching, dsindices, indices_length, ¢ers[0], centers_length); diff --git a/modules/flann/include/opencv2/flann/index_testing.h b/modules/flann/include/opencv2/flann/index_testing.h index 203974562b..63b90e600c 100644 --- a/modules/flann/include/opencv2/flann/index_testing.h +++ b/modules/flann/include/opencv2/flann/index_testing.h @@ -99,8 +99,8 @@ float search_with_ground_truth(NNIndex& index, const Matrix resultSet(nn+skipMatches); SearchParams searchParams(checks); - std::vector indices(nn+skipMatches); - std::vector dists(nn+skipMatches); + cv::AutoBuffer indices(nn+skipMatches); + cv::AutoBuffer dists(nn+skipMatches); int* neighbors = &indices[skipMatches]; int correct = 0; diff --git a/modules/flann/include/opencv2/flann/lsh_table.h b/modules/flann/include/opencv2/flann/lsh_table.h index 3a5961e0cf..66c2cf79fd 100644 --- a/modules/flann/include/opencv2/flann/lsh_table.h +++ b/modules/flann/include/opencv2/flann/lsh_table.h @@ -490,7 +490,7 @@ inline LshStats LshTable::getStats() const != end; ) if (*iterator < bin_end) { if (is_new_bin) { - stats.size_histogram_.push_back(std::vector(3, 0)); + stats.size_histogram_.emplace_back(3, 0); stats.size_histogram_.back()[0] = bin_start; stats.size_histogram_.back()[1] = bin_end - 1; is_new_bin = false; diff --git a/modules/imgproc/src/bilateral_filter.dispatch.cpp b/modules/imgproc/src/bilateral_filter.dispatch.cpp index 1cc21521f6..da19e1e394 100644 --- a/modules/imgproc/src/bilateral_filter.dispatch.cpp +++ b/modules/imgproc/src/bilateral_filter.dispatch.cpp @@ -98,8 +98,8 @@ static bool ocl_bilateralFilter_8u(InputArray _src, OutputArray _dst, int d, return false; copyMakeBorder(src, temp, radius, radius, radius, radius, borderType); - std::vector _space_weight(d * d); - std::vector _space_ofs(d * d); + AutoBuffer _space_weight(d * d); + AutoBuffer _space_ofs(d * d); float * const space_weight = &_space_weight[0]; int * const space_ofs = &_space_ofs[0]; @@ -188,9 +188,9 @@ bilateralFilter_8u( const Mat& src, Mat& dst, int d, Mat temp; copyMakeBorder( src, temp, radius, radius, radius, radius, borderType ); - std::vector _color_weight(cn*256); - std::vector _space_weight(d*d); - std::vector _space_ofs(d*d); + AutoBuffer _color_weight(cn*256); + AutoBuffer _space_weight(d*d); + AutoBuffer _space_ofs(d*d); float* color_weight = &_color_weight[0]; float* space_weight = &_space_weight[0]; int* space_ofs = &_space_ofs[0]; @@ -283,15 +283,15 @@ bilateralFilter_32f( const Mat& src, Mat& dst, int d, copyMakeBorder( src, temp, radius, radius, radius, radius, borderType ); // allocate lookup tables - std::vector _space_weight(d*d); - std::vector _space_ofs(d*d); + AutoBuffer _space_weight(d*d); + AutoBuffer _space_ofs(d*d); float* space_weight = &_space_weight[0]; int* space_ofs = &_space_ofs[0]; // assign a length which is slightly more than needed len = (float)(maxValSrc - minValSrc) * cn; kExpNumBins = kExpNumBinsPerChannel * cn; - std::vector _expLUT(kExpNumBins+2); + AutoBuffer _expLUT(kExpNumBins+2); float* expLUT = &_expLUT[0]; scale_index = kExpNumBins/len; diff --git a/modules/imgproc/src/connectedcomponents.cpp b/modules/imgproc/src/connectedcomponents.cpp index e6285bdecd..065e871c5a 100644 --- a/modules/imgproc/src/connectedcomponents.cpp +++ b/modules/imgproc/src/connectedcomponents.cpp @@ -1153,10 +1153,10 @@ namespace cv{ //Array used to store info and labeled pixel by each thread. //Different threads affect different memory location of chunksSizeAndLabels const int chunksSizeAndLabelsSize = roundUp(h, 2); - std::vector chunksSizeAndLabels(chunksSizeAndLabelsSize); + AutoBuffer chunksSizeAndLabels(chunksSizeAndLabelsSize); //Tree of labels - std::vector P(Plength, 0); + AutoBuffer P(Plength, 0); //First label is for background //P[0] = 0; @@ -1176,7 +1176,7 @@ namespace cv{ } //Array for statistics data - std::vector sopArray(h); + AutoBuffer sopArray(h); sop.init(nLabels); //Second scan @@ -1218,7 +1218,7 @@ namespace cv{ // ............ const size_t Plength = size_t(((h + 1) / 2) * size_t((w + 1) / 2)) + 1; - std::vector P_(Plength, 0); + AutoBuffer P_(Plength, 0); LabelT *P = P_.data(); //P[0] = 0; LabelT lunique = 1; @@ -1782,10 +1782,10 @@ namespace cv{ //Array used to store info and labeled pixel by each thread. //Different threads affect different memory location of chunksSizeAndLabels - std::vector chunksSizeAndLabels(roundUp(h, 2)); + AutoBuffer chunksSizeAndLabels(roundUp(h, 2)); //Tree of labels - std::vector P_(Plength, 0); + AutoBuffer P_(Plength, 0); LabelT* P = P_.data(); //First label is for background //P[0] = 0; @@ -1806,7 +1806,7 @@ namespace cv{ } //Array for statistics dataof threads - std::vector sopArray(h); + AutoBuffer sopArray(h); sop.init(nLabels); //Second scan @@ -1842,7 +1842,7 @@ namespace cv{ // ............ const size_t Plength = size_t((size_t(h) * size_t(w) + 1) / 2) + 1; - std::vector P_(Plength, 0); + AutoBuffer P_(Plength, 0); LabelT* P = P_.data(); P[0] = 0; LabelT lunique = 1; @@ -2315,10 +2315,10 @@ namespace cv{ //Array used to store info and labeled pixel by each thread. //Different threads affect different memory location of chunksSizeAndLabels - std::vector chunksSizeAndLabels(roundUp(h, 2)); + AutoBuffer chunksSizeAndLabels(roundUp(h, 2)); //Tree of labels - std::vector P_(Plength, 0); + AutoBuffer P_(Plength, 0); LabelT *P = P_.data(); //First label is for background //P[0] = 0; @@ -2352,7 +2352,7 @@ namespace cv{ } //Array for statistics dataof threads - std::vector sopArray(h); + AutoBuffer sopArray(h); sop.init(nLabels); //Second scan @@ -2387,7 +2387,7 @@ namespace cv{ //Obviously, 4-way connectivity upper bound is also good for 8-way connectivity labeling const size_t Plength = (size_t(h) * size_t(w) + 1) / 2 + 1; //array P for equivalences resolution - std::vector P_(Plength, 0); + AutoBuffer P_(Plength, 0); LabelT *P = P_.data(); //first label is for background pixels //P[0] = 0; @@ -4265,10 +4265,10 @@ namespace cv{ //Array used to store info and labeled pixel by each thread. //Different threads affect different memory location of chunksSizeAndLabels const int chunksSizeAndLabelsSize = roundUp(h, 2); - std::vector chunksSizeAndLabels(chunksSizeAndLabelsSize); + AutoBuffer chunksSizeAndLabels(chunksSizeAndLabelsSize); //Tree of labels - std::vector P(Plength, 0); + AutoBuffer P(Plength, 0); //First label is for background //P[0] = 0; @@ -4288,7 +4288,7 @@ namespace cv{ } //Array for statistics data - std::vector sopArray(h); + AutoBuffer sopArray(h); sop.init(nLabels); //Second scan @@ -4323,7 +4323,7 @@ namespace cv{ //............ const size_t Plength = size_t(((h + 1) / 2) * size_t((w + 1) / 2)) + 1; - std::vector P_(Plength, 0); + AutoBuffer P_(Plength, 0); LabelT *P = P_.data(); //P[0] = 0; LabelT lunique = 1; diff --git a/modules/imgproc/src/deriv.cpp b/modules/imgproc/src/deriv.cpp index e2e6658b47..11524b7a5c 100644 --- a/modules/imgproc/src/deriv.cpp +++ b/modules/imgproc/src/deriv.cpp @@ -101,7 +101,7 @@ static void getSobelKernels( OutputArray _kx, OutputArray _ky, if( _ksize % 2 == 0 || _ksize > 31 ) CV_Error( cv::Error::StsOutOfRange, "The kernel size must be odd and not larger than 31" ); - std::vector kerI(std::max(ksizeX, ksizeY) + 1); + AutoBuffer kerI(std::max(ksizeX, ksizeY) + 1); CV_Assert( dx >= 0 && dy >= 0 && dx+dy > 0 ); diff --git a/modules/imgproc/src/hough.cpp b/modules/imgproc/src/hough.cpp index ae0f1bd8f1..8faa2a64f3 100644 --- a/modules/imgproc/src/hough.cpp +++ b/modules/imgproc/src/hough.cpp @@ -359,13 +359,13 @@ HoughLinesSDiv( InputArray image, OutputArray lines, int type, lst.push_back(hough_index(threshold, -1.f, 0.f)); // Precalculate sin table - std::vector _sinTable( 5 * tn * stn ); + AutoBuffer _sinTable( 5 * tn * stn ); float* sinTable = &_sinTable[0]; for( index = 0; index < 5 * tn * stn; index++ ) sinTable[index] = (float)cos( stheta * index * 0.2f ); - std::vector _caccum(rn * tn, (uchar)0); + AutoBuffer _caccum(rn * tn, (uchar)0); uchar* caccum = &_caccum[0]; // Counting all feature pixels @@ -373,7 +373,7 @@ HoughLinesSDiv( InputArray image, OutputArray lines, int type, for( col = 0; col < w; col++ ) fn += _POINT( row, col ) != 0; - std::vector _x(fn), _y(fn); + AutoBuffer _x(fn), _y(fn); int* x = &_x[0], *y = &_y[0]; // Full Hough Transform (it's accumulator update part) @@ -445,7 +445,7 @@ HoughLinesSDiv( InputArray image, OutputArray lines, int type, return; } - std::vector _buffer(srn * stn + 2); + AutoBuffer _buffer(srn * stn + 2); uchar* buffer = &_buffer[0]; uchar* mcaccum = buffer + 1; @@ -586,7 +586,7 @@ HoughLinesProbabilistic( Mat& image, Mat accum = Mat::zeros( numangle, numrho, CV_32SC1 ); Mat mask( height, width, CV_8UC1 ); - std::vector trigtab(numangle*2); + AutoBuffer trigtab(numangle*2); for( int n = 0; n < numangle; n++ ) { @@ -2382,7 +2382,7 @@ static void HoughCircles( InputArray _image, OutputArray _circles, if( type == CV_32FC4 ) { - std::vector cw(ncircles); + AutoBuffer cw(ncircles); for( i = 0; i < ncircles; i++ ) cw[i] = GetCircle4f(circles[i]); if (ncircles > 0) @@ -2390,7 +2390,7 @@ static void HoughCircles( InputArray _image, OutputArray _circles, } else if( type == CV_32FC3 ) { - std::vector cwow(ncircles); + AutoBuffer cwow(ncircles); for( i = 0; i < ncircles; i++ ) cwow[i] = GetCircle(circles[i]); if (ncircles > 0) diff --git a/modules/imgproc/src/median_blur.simd.hpp b/modules/imgproc/src/median_blur.simd.hpp index 0b9db8ebb4..d2db45cec1 100644 --- a/modules/imgproc/src/median_blur.simd.hpp +++ b/modules/imgproc/src/median_blur.simd.hpp @@ -128,8 +128,8 @@ medianBlur_8u_O1( const Mat& _src, Mat& _dst, int ksize ) # define CV_ALIGNMENT 16 #endif - std::vector _h_coarse(1 * 16 * (STRIPE_SIZE + 2*r) * cn + CV_ALIGNMENT); - std::vector _h_fine(16 * 16 * (STRIPE_SIZE + 2*r) * cn + CV_ALIGNMENT); + AutoBuffer _h_coarse(1 * 16 * (STRIPE_SIZE + 2*r) * cn + CV_ALIGNMENT); + AutoBuffer _h_fine(16 * 16 * (STRIPE_SIZE + 2*r) * cn + CV_ALIGNMENT); HT* h_coarse = alignPtr(&_h_coarse[0], CV_ALIGNMENT); HT* h_fine = alignPtr(&_h_fine[0], CV_ALIGNMENT); diff --git a/modules/imgproc/src/morph.dispatch.cpp b/modules/imgproc/src/morph.dispatch.cpp index ee473886ad..31affbed60 100644 --- a/modules/imgproc/src/morph.dispatch.cpp +++ b/modules/imgproc/src/morph.dispatch.cpp @@ -887,7 +887,7 @@ static bool ocl_morphOp(InputArray _src, OutputArray _dst, InputArray _kernel, if (actual_op < 0) actual_op = op; - std::vector kernels(iterations); + AutoBuffer kernels(iterations); for (int i = 0; i < iterations; i++) { int current_op = iterations == i + 1 ? actual_op : op; diff --git a/modules/imgproc/src/subdivision2d.cpp b/modules/imgproc/src/subdivision2d.cpp index 78432f456d..ec27011119 100644 --- a/modules/imgproc/src/subdivision2d.cpp +++ b/modules/imgproc/src/subdivision2d.cpp @@ -793,6 +793,7 @@ void Subdiv2D::getLeadingEdgeList(std::vector& leadingEdgeList) const { leadingEdgeList.clear(); int i, total = (int)(qedges.size()*4); + //use a std::vector to benefit from the "bitset size/8" implementation std::vector edgemask(total, false); for( i = 4; i < total; i += 2 ) @@ -813,6 +814,7 @@ void Subdiv2D::getTriangleList(std::vector& triangleList) const { triangleList.clear(); int i, total = (int)(qedges.size()*4); + //use a std::vector to benefit from the "bitset size/8" implementation std::vector edgemask(total, false); Rect2f rect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y); diff --git a/modules/imgproc/src/templmatch.cpp b/modules/imgproc/src/templmatch.cpp index ac01c85d74..466823819e 100644 --- a/modules/imgproc/src/templmatch.cpp +++ b/modules/imgproc/src/templmatch.cpp @@ -568,7 +568,6 @@ void crossCorr( const Mat& img, const Mat& _templ, Mat& corr, { const double blockScale = 4.5; const int minBlockSize = 256; - std::vector buf; Mat templ = _templ; int depth = img.depth(), cn = img.channels(); @@ -624,7 +623,7 @@ void crossCorr( const Mat& img, const Mat& _templ, Mat& corr, if( (ccn > 1 || cn > 1) && cdepth != maxDepth ) bufSize = std::max( bufSize, blocksize.width*blocksize.height*CV_ELEM_SIZE(cdepth)); - buf.resize(bufSize); + AutoBuffer buf(bufSize); Ptr c = hal::DFT2D::create(dftsize.width, dftsize.height, dftTempl.depth(), 1, 1, CV_HAL_DFT_IS_INPLACE, templ.rows); diff --git a/modules/video/src/optflowgf.cpp b/modules/video/src/optflowgf.cpp index 7d654f747b..5827ebea28 100644 --- a/modules/video/src/optflowgf.cpp +++ b/modules/video/src/optflowgf.cpp @@ -822,7 +822,7 @@ private: float m_ig[4]; void setPolynomialExpansionConsts(int n, double sigma) { - std::vector buf(n*6 + 3); + AutoBuffer buf(n*6 + 3); float* g = &buf[0] + n; float* xg = g + n*2 + 1; float* xxg = xg + n*2 + 1;