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

void Impala::Application::Util::DoExportAnnoMpeg7 (  ) 

Definition at line 294 of file mainUtil.cpp.

References Impala::Core::VideoSet::Mpeg7Doc::AddAnnotation(), Impala::atol(), Impala::Util::DatabaseReadStrings(), Impala::FileNameBase(), Impala::CmdOptions::GetArg(), Impala::Core::Database::RawDataSet::GetDatabase(), Impala::Core::Database::RawDataSet::GetFile(), Impala::Core::Database::RawDataSet::GetFilePathAnnotation(), Impala::Core::Database::RawDataSet::GetFilePathGroundTruth(), Impala::Core::VideoSet::Keyframes::GetFirstKeyframeShot(), Impala::Core::VideoSet::Keyframes::GetFirstKeyframeVideo(), Impala::Core::VideoSet::Segmentation::GetFirstShotVideo(), Impala::Core::VideoSet::Keyframes::GetFrameNr(), Impala::CmdOptions::GetInstance(), Impala::Core::Database::RawDataSet::GetLocator(), Impala::Core::VideoSet::Segmentation::GetName(), Impala::Core::VideoSet::Keyframes::GetName(), Impala::CmdOptions::GetNrArg(), Impala::Core::VideoSet::Segmentation::GetNrFramesVideo(), Impala::Core::VideoSet::Keyframes::GetNrKeyframesShot(), Impala::Core::VideoSet::Keyframes::GetNrKeyframesVideo(), Impala::Core::VideoSet::Segmentation::GetNrShotsVideo(), ILOG_ERROR, ILOG_INFO, ILOG_NDC_POP, ILOG_NDC_PUSH, ILOG_VAR, ILOG_WARN, Impala::Core::VideoSet::MakeVideoSet(), Impala::Core::VideoSet::Mpeg7DocWrite(), Impala::Core::Database::RawDataSet::NrFiles(), and Impala::Persistency::File::ReadStrings().

Referenced by mainUtil().

00295 {
00296     typedef Core::VideoSet::VideoSet VideoSet;
00297     typedef Core::VideoSet::Segmentation Segmentation;
00298     typedef Core::VideoSet::Keyframes Keyframes;
00299     typedef Core::VideoSet::Mpeg7Doc Mpeg7Doc;
00300 
00301     ILOG_VAR(Impala.Application.Util.DoExportAnnoMpeg7);
00302     CmdOptions& options = CmdOptions::GetInstance();
00303     if (options.GetNrArg() < 5)
00304     {
00305         ILOG_ERROR("Need more parameters");
00306         return;
00307     }
00308     String videoSetName = options.GetArg(1);
00309     int fractions = Impala::atol(options.GetArg(2));
00310     if ((fractions != 25) && (fractions != 30000))
00311         ILOG_WARN("Never tried fractions = " << fractions);
00312     String conceptSet = options.GetArg(3);
00313     String anno = options.GetArg(4);
00314     bool hasKeyframes = false;
00315     if (anno == "hasKeyframes")
00316     {
00317         hasKeyframes = true;
00318     }
00319     else if (anno != "hasShots")
00320     {
00321         ILOG_ERROR("Argument should be hasShots or hasKeyframes");
00322         return;
00323     }
00324 
00325     VideoSet* vidSet = Core::VideoSet::MakeVideoSet(videoSetName);
00326     SegmentationLocator sLoc(videoSetName, "segmentation", options);
00327     Segmentation* segmentation = SegmentationRepository().Get(sLoc, vidSet);
00328     KeyframesLocator kLoc(videoSetName, "keyframes", options);
00329     Keyframes* keyframes = KeyframesRepository().Get(kLoc, vidSet);
00330 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00331     String fName = vidSet->GetFilePathAnnotation(conceptSet, false, false);
00332     if (fName.empty())
00333     {
00334         ILOG_ERROR("unable to read conceptSet");
00335         return;
00336     }
00337     std::vector<String> concepts;
00338     Impala::Util::Database* db = vidSet->GetDatabase();
00339     Impala::Util::DatabaseReadStrings(concepts, fName, db);
00340 #else // REPOSITORY_USED
00341     Persistency::KeywordListLocator loc(vidSet->GetLocator(), conceptSet);
00342     Core::Table::KeywordList concepts =
00343         *(Persistency::KeywordListRepository().Get(loc));
00344 #endif // REPOSITORY_USED
00345     for (int c=0 ; c<concepts.size() ; c++)
00346     {
00347         ILOG_INFO("doing concept " << concepts[c]);
00348         ILOG_NDC_PUSH(concepts[c]);
00349 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00350         fName = vidSet->GetFilePathGroundTruth(concepts[c] + ".truth", false,
00351                                                false);
00352         if (fName.empty())
00353         {
00354             ILOG_INFO("no annotations found for " << concepts[c]);
00355             ILOG_NDC_POP;
00356             continue;
00357         }
00358         std::vector<String> annos;
00359         Impala::Util::DatabaseReadStrings(annos, fName, db);
00360 #else // REPOSITORY_USED
00361         String fName = "Annotations/groundtruth/" + concepts[c] + ".truth";
00362         Persistency::FileLocator fLoc(vidSet->GetLocator(), fName);
00363         typedef Persistency::RepositoryInFileSystem FS;
00364         Persistency::File file = FS::GetInstance().GetFile(fLoc, false, false);
00365         std::vector<String> annos;
00366         file.ReadStrings(annos);
00367 #endif // REPOSITORY_USED
00368         std::sort(annos.begin(), annos.end());
00369         for (int v=0 ; v<vidSet->NrFiles() ; v++)
00370         {
00371             String vidFile = vidSet->GetFile(v);
00372             int nrFrames = segmentation->GetNrFramesVideo(v);
00373             Mpeg7Doc mp7(vidFile, vidFile, nrFrames, fractions, false,
00374                          conceptSet, concepts[c]);
00375             if (hasKeyframes)
00376             {
00377                 for (int k=0 ; k<keyframes->GetNrKeyframesVideo(v) ; k++)
00378                 {
00379                     int keyId = keyframes->GetFirstKeyframeVideo(v) + k;
00380                     String keyName = FileNameBase(keyframes->GetName(keyId));
00381                     int frameNr = keyframes->GetFrameNr(keyId);
00382                     double relevance = 0;
00383                     if (find(annos.begin(),annos.end(),keyName) != annos.end())
00384                         relevance = 1;
00385                     mp7.AddAnnotation(concepts[c], keyName, frameNr, frameNr,
00386                                       relevance, 1);
00387                 }
00388             }
00389             else
00390             {
00391                 for (int s=0 ; s<segmentation->GetNrShotsVideo(v) ; s++)
00392                 {
00393                     int shotId = segmentation->GetFirstShotVideo(v) + s;
00394                     String shotName = segmentation->GetName(shotId);
00395                     double relevance = 0;
00396                     if (find(annos.begin(),annos.end(),shotName) != annos.end())
00397                         relevance = 1;
00398                     int firstKey = keyframes->GetFirstKeyframeShot(shotId);
00399                     int nrKey = keyframes->GetNrKeyframesShot(shotId);
00400                     for (int k=firstKey ; k<firstKey+nrKey ; k++)
00401                     {
00402                         String keyName = FileNameBase(keyframes->GetName(k));
00403                         int frameNr = keyframes->GetFrameNr(k);
00404                         mp7.AddAnnotation(concepts[c], keyName, frameNr,
00405                                           frameNr, relevance, 1);
00406                     }
00407                 }
00408             }
00409             Core::VideoSet::Mpeg7DocWrite(&mp7, vidSet, v);
00410         }
00411         ILOG_NDC_POP;
00412     }
00413 }

Here is the call graph for this function:


Generated on Fri Mar 19 10:52:04 2010 for ImpalaSrc by  doxygen 1.5.1