Home > Software engineering >  Elementary school students, the efficiency of the vector how low?
Elementary school students, the efficiency of the vector how low?

Time:12-25

I convert recursive to non-recursive method, vector as a stack, the execution time from 19 milliseconds to 7500 milliseconds, the vector efficiency so low?

CodePudding user response:

How did you write this to see your code, it's convenient for can post and see,
Vector in general is very commonly used in project, not so slow,

CodePudding user response:

Void TraceEdge (double * pdMag, unsigned char * pucEdge, int iIWd, int y, int x, double dThrLo,
Int iRecuTm, int iRecuLim)
{
//to query the 8 neighborhood pixels
Int xNb [8]={1, 1, 0, 1, 1, 1, 0, 1};
Int yNb [8]={0, 1, 1, 1, 0, 1, 1, 1};

Int yy.
Int xx;

Int k;

for(k=0; K<8; K++)
{
Yy=y + yNb [k].
Xx=x + xNb [k].

//g_vecStackX push_back (x);
//g_vecStackY push_back (y);
//g_vecNbIdx. Push_back (k);
//if the pixel as possible boundary point, and not processed
//and the gradient is greater than the threshold value
If (pucEdge xx] [yy * iIWd +==128 & amp; & PdMag * iIWd + xx] [yy & gt;=dThrLo)
{
//set the point at which become the boundary point
PucEdge [yy * iIWd + xx]=255;

//centered on that point tracking
If (iRecuTm & lt; IRecuLim)
{
IRecuTm++;
TraceEdge (pdMag, pucEdge iIWd, yy, xx, dThrLo, iRecuTm, iRecuLim);
}
}
}
}

//non recursive depth-first, pay attention to the function not to operate the root node
Void TraceEdge_dfs (double * pdMag, unsigned char * pucEdge, int iIWd, int iIHi, int x, int y, double dThrLo)
{
//to query the 8 neighborhood pixels
Int xNb [8]={1, 1, 0, 1, 1, 1, 0, 1};
Int yNb [8]={0, 1, 1, 1, 0, 1, 1, 1};

//8 neighborhood index and end
Int iNbB=0;
Int iNbE=8;

//right in the path of the traverse the vertex
Vector VecStackX;
Vector VecStackY;
//are traversing the linked vertices, corresponding number 8 neighborhood address
Vector VecNbIdx;

VecStackX. Push_back (x);
VecStackY. Push_back (y);
VecNbIdx. Push_back (iNbB);

//sign back, after traversal if bBacktrack extension road to TRUE indicates no find
BOOL bBacktrack=FALSE;

while(! VecStackX. Empty ())
{
Int x=vecStackX. Back ();
Int iY=vecStackY. Back ();
Int & amp; INbIdx=vecNbIdx. Back ();

//g_vecStackX. Push_back (iX);
//g_vecStackY push_back (iY);
//g_vecNbIdx push_back (iNbIdx);

If (bBacktrack)
{
INbIdx +=1;
BBacktrack=FALSE;
}

If (iNbIdx!=iNbE)
{
Int iNbX=iX + xNb [iNbIdx];
Int iNbY=iY + yNb [iNbIdx];

If ((iNbX & gt;=0) & amp; & (iNbX & lt; IIWd) & amp; & (iNbY & gt;=0) & amp; & (iNbY & lt; IIHi))
{
If ((pucEdge [iNbY * iIWd + iNbX]==128) & amp; & (pdMag [iNbY * iIWd + iNbX] & gt;=dThrLo))
{
//set the point at which become the boundary point
PucEdge [iNbY * iIWd + iNbX]=255;

VecStackX. Push_back (iNbX);
VecStackY. Push_back (iNbY);
VecNbIdx. Push_back (iNbB);

continue;
}
}

//the next neighborhood points, directly modified reference data types, storage stack
INbIdx +=1;
}
The else
{
//back, the first step in return by the way,
VecStackX. Pop_back ();
VecStackY. Pop_back ();
VecNbIdx. Pop_back ();

BBacktrack=TRUE;
}
}
}

CodePudding user response:

Canny algorithm of boundary point tracking code

CodePudding user response:

Recursive hierarchy problems need not consider, I have set the recursive hierarchy is very big, this problem can be ruled out
  • Related