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

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

Definition at line 698 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().

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

Here is the call graph for this function:


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