Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdlib.h>
00023 #include "cvWrapper.h"
00024 #include "AstDetector.h"
00025
00026 using namespace std;
00027 using namespace agast;
00028
00029 void AstDetector::nonMaximumSuppression(const std::vector<CvPoint>& corners_all,
00030 std::vector<CvPoint>& corners_nms)
00031 {
00032 int currCorner_ind;
00033 int lastRow=0, next_lastRow=0;
00034 vector<CvPoint>::const_iterator currCorner;
00035 int lastRowCorner_ind=0, next_lastRowCorner_ind=0;
00036 vector<int>::iterator nmsFlags_p;
00037 vector<CvPoint>::iterator currCorner_nms;
00038 int j;
00039 int numCorners_all=corners_all.size();
00040 int nMaxCorners=corners_nms.capacity();
00041
00042 currCorner=corners_all.begin();
00043
00044 if(numCorners_all > nMaxCorners)
00045 {
00046 if(nMaxCorners==0)
00047 {
00048 nMaxCorners=512 > numCorners_all ? 512 : numCorners_all;
00049 corners_nms.reserve(nMaxCorners);
00050 nmsFlags.reserve(nMaxCorners);
00051 }
00052 else
00053 {
00054 nMaxCorners *=2;
00055 if(numCorners_all > nMaxCorners)
00056 nMaxCorners = numCorners_all;
00057 corners_nms.reserve(nMaxCorners);
00058 nmsFlags.reserve(nMaxCorners);
00059 }
00060 }
00061 corners_nms.resize(numCorners_all);
00062 nmsFlags.resize(numCorners_all);
00063
00064 nmsFlags_p=nmsFlags.begin();
00065 currCorner_nms=corners_nms.begin();
00066
00067
00068 for(j=numCorners_all; j>0; j--)
00069 *nmsFlags_p++=-1;
00070 nmsFlags_p=nmsFlags.begin();
00071
00072 for(currCorner_ind=0; currCorner_ind<numCorners_all; currCorner_ind++)
00073 {
00074 int t;
00075
00076
00077 if(lastRow+1 < currCorner->y)
00078 {
00079 lastRow=next_lastRow;
00080 lastRowCorner_ind=next_lastRowCorner_ind;
00081 }
00082 if(next_lastRow!=currCorner->y)
00083 {
00084 next_lastRow=currCorner->y;
00085 next_lastRowCorner_ind=currCorner_ind;
00086 }
00087 if(lastRow+1==currCorner->y)
00088 {
00089
00090 while((corners_all[lastRowCorner_ind].x < currCorner->x) && (corners_all[lastRowCorner_ind].y == lastRow))
00091 lastRowCorner_ind++;
00092
00093 if( (corners_all[lastRowCorner_ind].x == currCorner->x) && (lastRowCorner_ind!=currCorner_ind) )
00094 {
00095 int t=lastRowCorner_ind;
00096 while(nmsFlags[t]!=-1)
00097 t=nmsFlags[t];
00098
00099 if( scores[currCorner_ind] < scores[t] )
00100 {
00101 nmsFlags[currCorner_ind]=t;
00102 }
00103 else
00104 nmsFlags[t]=currCorner_ind;
00105 }
00106 }
00107
00108
00109 t=currCorner_ind-1;
00110 if( (currCorner_ind!=0) && (corners_all[t].y == currCorner->y) && (corners_all[t].x+1 == currCorner->x) )
00111 {
00112 int currCornerMaxAbove_ind=nmsFlags[currCorner_ind];
00113
00114 while(nmsFlags[t]!=-1)
00115 t=nmsFlags[t];
00116
00117 if(currCornerMaxAbove_ind==-1)
00118 {
00119 if(t!=currCorner_ind)
00120 {
00121 if( scores[currCorner_ind] < scores[t] )
00122 nmsFlags[currCorner_ind]=t;
00123 else
00124 nmsFlags[t]=currCorner_ind;
00125 }
00126 }
00127 else
00128 {
00129 if(t!=currCornerMaxAbove_ind)
00130 {
00131 if(scores[currCornerMaxAbove_ind] < scores[t])
00132 {
00133 nmsFlags[currCornerMaxAbove_ind]=t;
00134 nmsFlags[currCorner_ind]=t;
00135 }
00136 else
00137 {
00138 nmsFlags[t]=currCornerMaxAbove_ind;
00139 nmsFlags[currCorner_ind]=currCornerMaxAbove_ind;
00140 }
00141 }
00142 }
00143 }
00144
00145 currCorner++;
00146 }
00147
00148
00149 corners_nms.resize(0);
00150 for(currCorner_ind=0; currCorner_ind<numCorners_all; currCorner_ind++)
00151 {
00152 if(*nmsFlags_p++ == -1)
00153 corners_nms.push_back(corners_all[currCorner_ind]);
00154 }
00155 }
00156