From 86882e5dd12f8e0f7be71e360ff281c385d1db3c Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Tue, 27 Sep 2011 15:50:17 +0000 Subject: [PATCH] fixed bug #1381 --- modules/objdetect/src/distancetransform.cpp | 26 +++++---------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/modules/objdetect/src/distancetransform.cpp b/modules/objdetect/src/distancetransform.cpp index cb81a1b660..dd8c22c1eb 100644 --- a/modules/objdetect/src/distancetransform.cpp +++ b/modules/objdetect/src/distancetransform.cpp @@ -342,41 +342,30 @@ int DistanceTransformTwoDimensionalProblem(const float *f, { int i, j, tmp; int resOneDimProblem; - float *internalDistTrans; - int *internalPointsX; int size = n * m; + std::vector internalDistTrans(size); + std::vector internalPointsX(size); - // Allocation memory (must be free in this function) - internalDistTrans = (float *)malloc(sizeof(float) * size); - internalPointsX = (int *)malloc(sizeof(int) * size); - - for (i = 0; i < n; i++) { resOneDimProblem = DistanceTransformOneDimensionalProblem( f + i * m, m, coeff[0], coeff[2], - internalDistTrans + i * m, - internalPointsX + i * m); + &internalDistTrans[i * m], + &internalPointsX[i * m]); if (resOneDimProblem != DISTANCE_TRANSFORM_OK) - { - free(internalDistTrans); return DISTANCE_TRANSFORM_ERROR; - } /* if (resOneDimProblem != DISTANCE_TRANSFORM_OK) */ } - Transpose(internalDistTrans, n, m); + Transpose(&internalDistTrans[0], n, m); for (j = 0; j < m; j++) { resOneDimProblem = DistanceTransformOneDimensionalProblem( - internalDistTrans + j * n, n, + &internalDistTrans[j * n], n, coeff[1], coeff[3], distanceTransform + j * n, pointsY + j * n); if (resOneDimProblem != DISTANCE_TRANSFORM_OK) - { - free(internalDistTrans); return DISTANCE_TRANSFORM_ERROR; - } /* if (resOneDimProblem != DISTANCE_TRANSFORM_OK) */ } Transpose(distanceTransform, m, n); Transpose_int(pointsY, m, n); @@ -390,8 +379,5 @@ int DistanceTransformTwoDimensionalProblem(const float *f, } } - // Release allocated memory - free(internalDistTrans); - free(internalPointsX); return DISTANCE_TRANSFORM_OK; }