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

virtual void Impala::Core::VideoSet::KfrMotionExtractor::HandleNewFrame ( VideoSet vs,
int  fileId,
Stream::RgbDataSrc src 
) [inline, virtual]

Arrived at a new frame in a "normal" walk.

Reimplemented from Impala::Core::VideoSet::Listener.

Definition at line 108 of file KfrMotionExtractor.h.

References Impala::Core::Table::TableTem< Col1T, Col2T, Col3T, Col4T, Col5T, Col6T, Col7T, Col8T, Col9T >::Add(), Impala::Core::Array::Array2dTem< StorT, elemSize, ArithT >::BH(), Impala::Core::Array::Array2dTem< StorT, elemSize, ArithT >::BW(), BYTE, CalcMotionVectors(), CalcTPLMean(), ComputeEnergy(), Impala::Core::Array::Array2dTem< StorT, elemSize, ArithT >::CPB(), Impala::Core::Stream::RgbDataSrc::DataPtr(), DumpMVF(), DumpWeightMatrix(), Impala::Core::Stream::RgbDataSrc::FrameHeight(), Impala::Core::Stream::RgbDataSrc::FrameNr(), Impala::Core::Stream::RgbDataSrc::FrameWidth(), ILOG_DEBUG, ILOG_ERROR, LoadEnergyTemplate(), m_Buffer, m_EnergyBuffer, m_EnergyMap, m_MVseq, m_verbose, m_verbose2, m_Weight, mHistogramTable, MVBLOCKSIZE, Impala::Core::Array::RGB2Gray(), Impala::Core::Feature::Bitmap::SaveRgb2BitmapFile(), and TPL_NUM.

00109     {
00110         if (!src)
00111         {
00112             ILOG_ERROR("Not a valid source for fileId " << fileId);
00113             return;
00114         }
00115 
00116         Array::Array2dVec3UInt8* im = Array::ArrayCreate<Array::Array2dVec3UInt8>
00117             (src->FrameWidth(), src->FrameHeight(), 0, 0, src->DataPtr(), true);
00118         if (!im)
00119         {
00120             ILOG_ERROR("Couldn't load image for fileId " << fileId);
00121             return;
00122         }
00123 
00124         if (m_verbose)
00125         {
00126             std::cout << "Current Frame No. = " << src->FrameNr() << std::endl;
00127         }
00128 
00129 #ifdef __BITMAP_FUNC__
00130         Core::Feature::Bitmap bitmap;
00131         bitmap.SaveRgb2BitmapFile("test_rgb_00.bmp",src->DataPtr(), src->FrameWidth(), src->FrameHeight() );
00132 #endif
00133 
00134         /*VectorReal64 histogram = ComputeHistogram(im);
00135         Quid quid = vs->GetQuidFrame(fileId, src->FrameNr());
00136         mHistogramTable->Add(quid, histogram);*/
00137 
00138         double feature[2*TPL_NUM];
00139         memset(feature,0,sizeof(double)*2*TPL_NUM);
00140 
00141         // For temporal filtering use something like this instead:
00142         // (requires --srcWindow "size;5;rgb2ooo")
00143         typedef Stream::RgbDataSrcWindow<Stream::WindowPrepRgb2Ooo> WindowType;
00144         //WindowType* window = dynamic_cast<WindowType*>(src);
00145         WindowType* window = (WindowType*)src;
00146         if (window)
00147         {
00148             if (m_verbose)
00149             {
00150                 std::cout << "window size = " << window->WindowSize() << std::endl;
00151             }
00152 
00153             //Array::Array2dScalarReal64* tGauss = 0;
00154             //double temporalSigma = 0.75;
00155             //tGauss = Array::MakeGaussian1d(temporalSigma, 0, 3.0, 100);
00156             //Array::Array2dVec3Real64* res = 0;
00157             //SeqConvKernel(res, window, tGauss);
00159             //Array::Array2dVec3UInt8* src;
00160             //Array::InvWiccest(res, src, false, false, 0.75, 3, true);
00161 
00162 
00163             // test looping for all frames within the window
00164             //for (int i=0 ; i<window->WindowSize(); i++)
00165             //{
00166             //    Array::Array2dVec3UInt8* cur = Array::ArrayCreate<Array::Array2dVec3UInt8>
00167             //        (window->FrameWidth(), window->FrameHeight(), 0, 0, window->DataPtrWindow(i), true);
00168             //    if (!cur)
00169             //    {
00170             //        ILOG_ERROR("Couldn't load image for fileId " << fileId);
00171             //        return;
00172             //    }
00173 
00174             //    VectorReal64 cur_histogram = ComputeHistogram(cur);
00175             //    Quid quid = vs->GetQuidFrame(fileId, window->FrameNr() - window->WindowSize()/2 + i);
00176             //    mHistogramTable->Add(quid, cur_histogram);
00177             //}
00178             
00179 
00180             int bWidth = window->FrameWidth()/MVBLOCKSIZE;
00181             int bHeight = window->FrameHeight()/MVBLOCKSIZE;
00182             
00183             // Note: we have tested these pairs: (10,7) (7,10) (10,8) (8,10) (22,18) (20,15)
00184             //int bWidth = 10;
00185             //int bHeight = 7;
00186 
00187             for (int t=0;t<TPL_NUM;t++)
00188             {
00189                 m_Weight[t] = new double[bWidth * bHeight];
00190                 memset(m_Weight[t], 0, sizeof(double)* bWidth * bHeight);
00191 
00192                 if (m_verbose2)
00193                 {
00194                     DumpWeightMatrix(m_Weight[t], bWidth, bHeight, t);
00195                 }
00196             }
00197 
00198             m_EnergyBuffer = new BYTE[bWidth * bHeight];
00199             m_EnergyMap = new double[bWidth * bHeight];
00200             m_Buffer = new BYTE[bWidth * bHeight * 2];
00201 
00202             // Initialization
00203             LoadEnergyTemplate(bWidth, bHeight);
00204 
00205             // calculate the mean of weight for all templates
00206             CalcTPLMean(bWidth, bHeight);
00207 
00208             m_MVseq = new BYTE[bWidth * bHeight * 2 * (window->WindowSize()-1)];
00209             memset(m_MVseq, 0, sizeof(BYTE)*bWidth * bHeight * 2 * (window->WindowSize()-1) );
00210             //DumpMVFseq(m_MVseq, bWidth, bHeight, window->WindowSize()-1);
00211 
00212             // compute motion features between adjacent frames
00213             // if window size as 9: 0-1,1-2,2-3,3-4,4-5,5-6,6-7,7-8,8-9
00214             // based on these motion vectors field, we compute the energy distribution
00215             for (int i=1 ; i<window->WindowSize() ; i++)
00216             {
00217                 // previous frame: pre
00218                 Array::Array2dVec3UInt8* pre_rgb = Array::ArrayCreate<Array::Array2dVec3UInt8>
00219                     (window->FrameWidth(), window->FrameHeight(), 0, 0, window->DataPtrWindow(i-1), true);
00220                 if (!pre_rgb)
00221                 {
00222                     ILOG_ERROR("Couldn't load image for fileId " << fileId);
00223                     return;
00224                 }
00225 
00226                 // current frame: cur
00227                 Array::Array2dVec3UInt8* cur_rgb = Array::ArrayCreate<Array::Array2dVec3UInt8>
00228                     (window->FrameWidth(), window->FrameHeight(), 0, 0, window->DataPtrWindow(i), true);
00229                 if (!cur_rgb)
00230                 {
00231                     ILOG_ERROR("Couldn't load image for fileId " << fileId);
00232                     return;
00233                 }
00234 
00235 #ifdef __BITMAP_FUNC__
00236                 //Core::Feature::Bitmap bitmap;
00237                 //bitmap.SaveRgb2BitmapFile("test_rgb_0.bmp",cur_rgb->CPB(), cur_rgb->CW(), cur_rgb->CH() );
00238 #endif
00239                 //Array2dScalarReal64* pre = 0;
00240                 //Array2dScalarReal64* cur = 0;
00241                 Array::Array2dScalarUInt8* pre = 0;
00242                 Array::Array2dScalarUInt8* cur = 0;
00243                 RGB2Gray(pre,pre_rgb);
00244                 RGB2Gray(cur,cur_rgb);
00245 
00246                 // motion vector computing between (pre,cur)
00247                 Int64 body = pre->BW() + pre->BH();
00248 
00249 #ifdef __BITMAP_FUNC__
00250                 //Core::Feature::Bitmap bitmap;
00251                 //bitmap.SaveGray2BitmapFile("test_gray_0.bmp",cur->CPB(), cur->CW(), cur->CH() );
00252 #endif
00253                 CalcMotionVectors((unsigned char*)pre->CPB(),(unsigned char*)cur->CPB(),window->FrameWidth(),window->FrameHeight(),m_MVseq, i-1);
00254 
00255                 if (m_verbose2) DumpMVF(m_MVseq, bWidth, bHeight, i-1);
00256 
00257                 // DO remember: release the memory
00258                 delete pre_rgb;
00259                 delete cur_rgb;
00260                 delete pre;
00261                 delete cur;
00262 
00263             }
00264             //DumpMVFseq(m_MVseq, bWidth, bHeight, window->WindowSize()-1);
00265 
00266             // -----------------------------------------------------
00267             // #frame within the window:  window->WindowSize()
00268             // Motion Vector Field:       window->WindowSize() - 1
00269             // Energy Distribution Curve: window->WindowSize() - 2
00270             // -----------------------------------------------------
00271 
00272             // compute energy based on weighted templates
00273             // using a sliding buffer within a window
00274             int result = ComputeEnergy(window->WindowSize()-1, bWidth, bHeight, m_MVseq, feature);
00275 
00276             if (0 !=  result) return;
00277 
00278             for (int i=0;i<TPL_NUM;i++)
00279                 delete []m_Weight[i];
00280             delete []m_EnergyBuffer;
00281             delete []m_EnergyMap;
00282             delete []m_Buffer;
00283             delete []m_MVseq;
00284      
00285         }
00286         delete im;
00287 
00288         VectorReal64 mvfeature(2*TPL_NUM);
00289         for (int x=0; x<2*TPL_NUM; x++)
00290         {
00291             mvfeature[x] = feature[x];
00292         }
00293         Quid quid = vs->GetQuidFrame(fileId, src->FrameNr());
00294         mHistogramTable->Add(quid, mvfeature);
00295 
00296         ILOG_DEBUG("... done keyframe " << src->FrameNr());
00297 
00298     }

Here is the call graph for this function:


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