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

void Impala::Core::VideoSet::KfrMotionExtractor::FillBuffer ( int  WindowLen,
int  bWidth,
int  bHeight,
BYTE *  mvseq 
) [inline]

Definition at line 705 of file KfrMotionExtractor.h.

References Impala::Core::Array::Add(), BYTE, DumpEnergyMap(), IsInShot, m_Buffer, m_EnergyBuffer, m_EnergyMap, m_verbose2, MVBLOCKSIZE, and UINT.

Referenced by ComputeEnergy().

00706     {
00707         double * Add = new double[bWidth * bHeight];
00708         if (IsInShot)
00709         {
00710             UINT BufferLen = bWidth * bHeight;
00711             double * Temp = new double[BufferLen];
00712             if (Temp == NULL || Add == NULL)
00713             {
00714                 if (Temp != NULL) delete[] Temp;
00715                 if (Add != NULL) delete[] Add;
00716                 printf("Not Enough Memory! No Map Generated!");
00717                 return;
00718             }
00719 
00720             // Initialize the map value to 1.0
00721             for (int i = 0; i < BufferLen; i++)
00722             {
00723                 m_EnergyMap[i] = 1.0;
00724                 Add[i] = 0.0;
00725             }
00726 
00727             //DumpEnergyMap(bWidth, bHeight, "Initialization");
00728 
00729             for (int w = 0; w < WindowLen; w ++)
00730             {
00731                 memset(Temp, 0, BufferLen * sizeof(double));
00732 
00733                 // read the motion vectors from the "mvseq" buffer
00734                 memcpy(m_Buffer, mvseq + sizeof(BYTE)*bWidth*bHeight*2* w, BufferLen * 2);
00735 
00736                 // loop for the energy map :(20*15, for example)
00737                 for (int i = 0; i < bWidth; i++)
00738                     for (int j = 0; j < bHeight; j++)
00739                     {
00740                         double CurValue = m_EnergyMap[j * bWidth + i];
00741                         
00742                         int cx, cy;
00743                         long Ptr = 2 * (j * bWidth + i);
00744 
00745                         // (cx,cy) is the motion vector
00746                         cx = (char)m_Buffer[Ptr];
00747                         cy = (char)m_Buffer[Ptr + 1];    
00748                         
00749                         char SignX, SignY;
00750                         SignX = (cx >= 0)? 1:-1;
00751                         SignY = (cy >= 0)? 1:-1;
00752                         
00753                         int BaseX,BaseY;
00754                         BaseX = i + (int)(cx / MVBLOCKSIZE);
00755                         BaseY = j + (int)(cy / MVBLOCKSIZE);
00756                         
00757                         double Factor;
00758                         if (BaseX >= bWidth || BaseY >= bHeight || BaseX < 0 || BaseY < 0) 
00759                         {
00760                             if (abs(cx) >= abs(cy))
00761                             {
00762                                 Factor = (double)(cy) / (double)(cx);
00763                                 cx = ((SignX > 0)?bWidth:0) * MVBLOCKSIZE - MVBLOCKSIZE / 2;
00764                                 cy = Factor * cx + j * MVBLOCKSIZE - Factor * i * MVBLOCKSIZE;
00765                                 if (cy <= -MVBLOCKSIZE || cy >= bHeight * MVBLOCKSIZE)
00766                                 {
00767                                     cy = ((SignY > 0)?bHeight:0) * MVBLOCKSIZE - MVBLOCKSIZE / 2;
00768                                     cx = (cy - j * MVBLOCKSIZE + Factor * i * MVBLOCKSIZE) / Factor;
00769                                 }
00770                             }
00771                             else
00772                             {
00773                                 Factor = (double)(cx) / (double)(cy);
00774                                 cy = ((SignY > 0)?bHeight:0) * MVBLOCKSIZE - MVBLOCKSIZE / 2;
00775                                 cx = Factor * cy + i * MVBLOCKSIZE - Factor * j * MVBLOCKSIZE;
00776                                 if (cx <= - MVBLOCKSIZE || cx >= bWidth * MVBLOCKSIZE)
00777                                 {
00778                                     cx = ((SignX > 0)?bWidth:0) * MVBLOCKSIZE - MVBLOCKSIZE / 2;
00779                                     cy = (cx - i * MVBLOCKSIZE + Factor * j * MVBLOCKSIZE) / Factor;
00780                                 }
00781                             }
00782                             cx -= i * MVBLOCKSIZE;
00783                             cy -= j * MVBLOCKSIZE;
00784                             BaseX = i + (int)(cx / MVBLOCKSIZE);
00785                             BaseY = j + (int)(cy / MVBLOCKSIZE);
00786                         }
00787                         
00788                         double mX, mY;
00789                         mX = (double)(abs(cx % MVBLOCKSIZE))/MVBLOCKSIZE;
00790                         mY = (double)(abs(cy % MVBLOCKSIZE))/MVBLOCKSIZE;
00791                         if (BaseX + SignX >= bWidth || BaseX + SignX < 0) mX = 0.0;
00792                         if (BaseY + SignY >= bHeight || BaseY + SignY < 0) mY = 0.0;
00793                         
00794                         Temp[BaseY * bWidth + BaseX] += (1 - mX) * (1 - mY) * CurValue;
00795                         
00796                         if (BaseX + SignX < bWidth && BaseX + SignX >= 0)
00797                             Temp[BaseY * bWidth + BaseX + SignX] += mX * (1 - mY) * CurValue;
00798                         if (BaseY + SignY < bHeight && BaseY + SignY >= 0)
00799                         {
00800                             Temp[(BaseY + SignY) * bWidth + BaseX] += (1 - mX) * mY * CurValue;
00801                             if (BaseX + SignX < bWidth && BaseX + SignX >= 0)
00802                                 Temp[(BaseY + SignY) * bWidth + BaseX + SignX] += mX * mY * CurValue;
00803                         }
00804                         
00805                     }
00806 
00807                 double * Exch;
00808                 Exch = Temp;
00809                 Temp = m_EnergyMap;
00810                 m_EnergyMap = Exch;
00811 
00812                 for (int k = 0; k < bWidth * bHeight; k ++)
00813                     Add[k] += m_EnergyMap[k];
00814 
00815                 //char strWinLen[256];
00816                 //_itoa(w,strWinLen,10);
00817                 //DumpEnergyMap(bWidth, bHeight, strWinLen);
00818 
00819             }
00820             delete[] Temp;
00821 
00822         }
00823 
00824         // Average the energy map within the window length
00825         for (int i = 0; i < bWidth * bHeight; i ++)
00826         {
00827             m_EnergyMap[i] = Add[i] / WindowLen;
00828             m_EnergyBuffer[i] = (BYTE)(m_EnergyMap[i] * 255);
00829         }
00830         delete[] Add;
00831 
00832         // dump out the final energy map within current sliding window
00833         if (m_verbose2)
00834         {
00835             DumpEnergyMap(bWidth, bHeight, "Average within Window (size=4)");
00836             //DumpEnergyBuffer(bWidth, bHeight);
00837         }
00838 
00839     }

Here is the call graph for this function:


Generated on Thu Jan 13 09:22:01 2011 for ImpalaSrc by  doxygen 1.5.1