Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

int Impala::Core::VideoSet::KfrMotionExtractor::ComputeEnergy ( int  WindowLen,
int  bWidth,
int  bHeight,
BYTE *  mvseq,
double *  feature,
int  CurBufSize = 5 
) [inline]

Definition at line 376 of file KfrMotionExtractor.h.

References BYTE, CalcEnergy(), FillBuffer(), IsInShot, m_bNormalize, m_verbose, OnShotEnd(), OnShotStart(), and TPL_NUM.

Referenced by HandleNewFrame().

00377     {
00378         IsInShot = FALSE;
00379 
00380         // ZeroMemory for m_EnergyMap[] and m_EnergyBuffer[]
00381         OnShotStart(bWidth, bHeight);
00382 
00383         for (int t=0; t<2*TPL_NUM; t++)
00384         {
00385             feature[t] = 0.0;
00386         }
00387 
00388         //int CurBufSize = 5;
00389         if (WindowLen < CurBufSize)
00390         {
00391             printf("Error: WindowLen (%d) is smaller than CurBufSize (%d)\n", WindowLen, CurBufSize);
00392             return 1;
00393         }
00394         int num = WindowLen - CurBufSize;
00395         for (int index = 0; index < 1+num; index++)
00396         {
00397             // Just the fill the buffer according to the motion vector information
00398             FillBuffer(CurBufSize, bWidth, bHeight, mvseq + sizeof(BYTE)*bWidth*bHeight*2*index);
00399 
00400             int i=0;
00401             float Temp1Energy[TPL_NUM];
00402             float Temp2Energy[TPL_NUM];
00403             float diffEnergy[TPL_NUM];
00404             memset(diffEnergy,0,TPL_NUM*sizeof(float));
00405 
00406             for (i=0;i<TPL_NUM;i++)
00407             {
00408                 // Use the weight template to calculate the total energy value
00409                 float Energy = 0.0;
00410                 if (m_bNormalize)
00411                 {
00412                     Energy = CalcEnergy(i, bWidth, bHeight);
00413                 } else {
00414                     Energy = CalcEnergy(i, bWidth, bHeight, FALSE);
00415                 }
00416 
00417                 // update Temp1Energy[] and Temp2Energy[] for late compute their diffs
00418                 if (index==0)
00419                     Temp1Energy[i]=Energy;
00420                 else if (index==1)
00421                     Temp2Energy[i]=Energy;
00422                 else //index>1
00423                 {
00424                     Temp1Energy[i] = Temp2Energy[i];
00425                     Temp2Energy[i] = Energy;
00426                 }
00427 
00428                 if (m_verbose) printf("%.5f\t", Energy);
00429 
00430                 //sum up all the values, to compute averages later.
00431                 feature[i] += Energy;
00432             }
00433             //printf("\n");
00434 
00435             // Here there are TPL_NUM pairs of data, we get the diffs of them
00436             // first diff energy has been initialized as zero
00437             if (index>0)
00438             {
00439                 for (i=0;i<TPL_NUM;i++)
00440                 {
00441                     if (m_bNormalize)
00442                     {
00443                         // [-1,1] --> [0,1]
00444                         diffEnergy[i] = fabs(Temp2Energy[i] - Temp1Energy[i]);
00445                         //diffEnergy[i] = Normalization(diffEnergy[i],-1.0,1.0);
00446                     } else {
00447                         diffEnergy[i] = Temp2Energy[i] - Temp1Energy[i];
00448                     }
00449 
00450                     if (m_verbose) printf("%.5f\t", diffEnergy[i]);
00451 
00452                     //sum up all the values, to compute averages later.
00453                     feature[TPL_NUM+i] += diffEnergy[i];
00454 
00455                 }
00456                 if (m_verbose) printf("\n");
00457 
00458             } else {
00459 
00460                 //index==0
00461                 if (m_verbose) printf("diff1\tdiff2\tdiff3\n");
00462 
00463                 for (i=0;i<TPL_NUM;i++)
00464                 {
00465                     //if (m_verbose) printf("%.5f\t", diffEnergy[i]);
00466                     feature[TPL_NUM+i] = 0.0;
00467                 }
00468             }
00469         }
00470         
00471         OnShotEnd(bWidth, bHeight);
00472 
00473         // calculate the averages of the feature within current Window buffer
00474         for (int t=0; t<TPL_NUM; t++)
00475         {
00476             feature[t] /= num+1;
00477             feature[TPL_NUM+t] /= num; // one less than three original values
00478         }
00479 
00480         if (m_verbose)
00481         {
00482             printf("\nThe Average as the final feature:\n");
00483             for (int t=0; t<2*TPL_NUM; t++)
00484             {
00485                 printf("%.5f ",feature[t]);
00486             }
00487             printf("\n\n");
00488         }
00489 
00490         return 0;
00491 
00492     }

Here is the call graph for this function:


Generated on Fri Mar 19 11:30:20 2010 for ImpalaSrc by  doxygen 1.5.1