mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
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
This commit is contained in:
@@ -332,11 +332,13 @@ void SimpleBlobDetectorImpl::findBlobs(InputArray _image, InputArray _binaryImag
|
||||
|
||||
//compute blob radius
|
||||
{
|
||||
std::vector<double> dists;
|
||||
for (size_t pointIdx = 0; pointIdx < contours[contourIdx].size(); pointIdx++)
|
||||
const std::vector<cv::Point>& contour = contours[contourIdx];
|
||||
const size_t contourSize = contour.size();
|
||||
AutoBuffer<double> 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.;
|
||||
|
||||
@@ -221,8 +221,8 @@ struct KeyPoint_LessThan
|
||||
void KeyPointsFilter::removeDuplicated( std::vector<KeyPoint>& keypoints )
|
||||
{
|
||||
int i, j, n = (int)keypoints.size();
|
||||
std::vector<int> kpidx(n);
|
||||
std::vector<uchar> mask(n, (uchar)1);
|
||||
AutoBuffer<int> kpidx(n);
|
||||
AutoBuffer<uchar> mask(n, (uchar)1);
|
||||
|
||||
for( i = 0; i < n; i++ )
|
||||
kpidx[i] = i;
|
||||
|
||||
@@ -839,7 +839,7 @@ static void computeKeyPoints(const Mat& imagePyramid,
|
||||
#endif
|
||||
|
||||
int i, nkeypoints, level, nlevels = (int)layerInfo.size();
|
||||
std::vector<int> nfeaturesPerLevel(nlevels);
|
||||
AutoBuffer<int> 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<KeyPoint> keypoints;
|
||||
std::vector<int> counters(nlevels);
|
||||
AutoBuffer<int> counters(nlevels);
|
||||
keypoints.reserve(nfeaturesPerLevel[0]*2);
|
||||
|
||||
for( level = 0; level < nlevels; level++ )
|
||||
|
||||
@@ -225,7 +225,7 @@ void SIFT_Impl::buildGaussianPyramid( const Mat& base, std::vector<Mat>& pyr, in
|
||||
{
|
||||
CV_TRACE_FUNCTION();
|
||||
|
||||
std::vector<double> sig(nOctaveLayers + 3);
|
||||
AutoBuffer<double> sig(nOctaveLayers + 3);
|
||||
pyr.resize(nOctaves*(nOctaveLayers + 3));
|
||||
|
||||
// precompute Gaussian sigmas using the following formula:
|
||||
|
||||
Reference in New Issue
Block a user