Skip to content

Commit 8cc03d4

Browse files
committed
Update edge_drawing.cpp
1 parent e832005 commit 8cc03d4

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

modules/ximgproc/src/edge_drawing.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,17 +1303,13 @@ void EdgeDrawingImpl::JoinAnchorPointsUsingSortedAnchors()
13031303
delete[] pixels;
13041304
}
13051305

1306-
int* EdgeDrawingImpl::sortAnchorsByGradValue1()
1307-
{
1308-
int SIZE = 128 * 256;
1309-
int* C = new int[SIZE];
1310-
memset(C, 0, sizeof(int) * SIZE);
1306+
int* EdgeDrawingImpl::sortAnchorsByGradValue1() {
1307+
const int SIZE = 128 * 256;
1308+
std::vector<int> C(SIZE, 0);
13111309

13121310
// Count the number of grad values
1313-
for (int i = 1; i < height - 1; i++)
1314-
{
1315-
for (int j = 1; j < width - 1; j++)
1316-
{
1311+
for (int i = 1; i < height - 1; i++) {
1312+
for (int j = 1; j < width - 1; j++) {
13171313
if (edgeImg[i * width + j] != ANCHOR_PIXEL)
13181314
continue;
13191315

@@ -1323,16 +1319,15 @@ int* EdgeDrawingImpl::sortAnchorsByGradValue1()
13231319
}
13241320

13251321
// Compute indices
1326-
for (int i = 1; i < SIZE; i++)
1322+
for (int i = 1; i < SIZE; i++) {
13271323
C[i] += C[i - 1];
1324+
}
13281325

13291326
int noAnchors = C[SIZE - 1];
13301327
int* A = new int[noAnchors];
13311328

1332-
for (int i = 1; i < height - 1; i++)
1333-
{
1334-
for (int j = 1; j < width - 1; j++)
1335-
{
1329+
for (int i = 1; i < height - 1; i++) {
1330+
for (int j = 1; j < width - 1; j++) {
13361331
if (edgeImg[i * width + j] != ANCHOR_PIXEL)
13371332
continue;
13381333

@@ -1342,7 +1337,6 @@ int* EdgeDrawingImpl::sortAnchorsByGradValue1()
13421337
}
13431338
}
13441339

1345-
delete[] C;
13461340
return A;
13471341
}
13481342

0 commit comments

Comments
 (0)