00001 #ifndef SEARCHRADIUS_H
00002 #define SEARCHRADIUS_H
00003
00004 #include "correlation.h"
00005
00006
00007
00008
00009 namespace seemicro
00010 {
00011
00020 struct SearchRadiusModule : public RecognitionModule
00021 {
00025 CorrelationModule& correlation;
00026
00031 float best;
00032
00033 float step;
00034 int MINR;
00035 int MAXR;
00041 float *maximaz, *maximazGemittelt;
00042
00046 int maximazMAXI;
00047
00048 SearchRadiusModule(CorrelationModule& Ac, int AMINR=30, int AMAXR=120, float Astep=1.0) :
00049 correlation(Ac), step(Astep), MINR(AMINR), MAXR(AMAXR)
00050 {
00051 maximazMAXI = int((MAXR-MINR)/step);
00052 maximaz = new float[maximazMAXI];
00053 maximazGemittelt = new float[maximazMAXI];
00054 correlation.micro.radiusValid = false;
00055 }
00056
00057 ~SearchRadiusModule()
00058 {
00059 delete [] maximaz;
00060 delete [] maximazGemittelt;
00061 }
00062
00063 void processKeyFrame(void)
00064 {
00065 if(correlation.micro.radiusValid) return;
00066
00067 #ifdef DEBUG
00068 if(DEBUGLEVEL >= 2) cerr << "radiusValid = false\n";
00069 #endif
00070
00071
00072 best = searchRadius(maximaz, float(MINR), float(MAXR), step);
00073 correlation.micro.radius = best;
00074 correlation.micro.radiusValid = true;
00075 correlation.kparams->radius = best;
00076 correlation.paramChanged = true;
00077 correlation.outputChanged = true;
00078 outputChanged = true;
00079 }
00080
00087 float searchRadius(float *values, float minRadius, float maxRadius,
00088 float step)
00089 {
00090 int index = 0;
00091 int mostmaxindex = 0;
00092 float best = minRadius;
00093
00094
00095
00096
00097 for(float r=minRadius; r<maxRadius; r+=step)
00098 {
00099 if(DEBUGLEVEL >= 3) cerr << "r=" << r;
00100
00101 correlation.kparams->radius=r;
00102 correlation.paramChanged = true;
00103 correlation.processKeyFrame();
00104 values[index] = correlation.correlationStrength;
00105
00106
00107
00108
00109 if(DEBUGLEVEL >= 3)
00110 cerr << " strength=" << correlation.correlationStrength << endl;
00111 if(values[mostmaxindex] < correlation.correlationStrength)
00112 {
00113 mostmaxindex = index;
00114 best = r;
00115 }
00116 index++;
00117 }
00118
00119 for(int i=1;i<maximazMAXI-1;i++)
00120 {
00121 maximazGemittelt[i] = 0.25*maximaz[i-1] + 0.5*maximaz[i] + 0.25*maximaz[i+1];
00122 }
00123
00124
00125
00126
00127 return best;
00128 }
00129
00130 };
00131
00132 }
00133
00134 #endif // RECOGNITIONMODULE_H
00135