Home || Architecture || Video Search || Visual Search || Scripts || Applications || 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 100 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.

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

Here is the call graph for this function:


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