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

void Impala::Application::Util::DoImportAnnotationsOrk (  ) 

Definition at line 883 of file mainUtil.cpp.

References Impala::Util::SimpleMapBase< IdxT, ElemT, DelT >::Add(), Impala::Core::VideoSet::Mpeg7Doc::AddAnnotation(), Impala::atol(), Impala::FileNameBase(), Impala::Core::Stream::RgbDataSrc::FrameRateDen(), Impala::Core::Stream::RgbDataSrc::FrameRateNum(), Impala::Util::SimpleMapBase< IdxT, ElemT, DelT >::Get(), Impala::CmdOptions::GetArg(), Impala::Core::Database::RawDataSet::GetFile(), Impala::Core::VideoSet::Segmentation::GetFirstShotVideo(), Impala::Core::VideoSet::Keyframes::GetFrameNr(), Impala::CmdOptions::GetInstance(), Impala::Core::Database::RawDataSet::GetLocator(), Impala::Core::VideoSet::Keyframes::GetName(), Impala::Core::VideoSet::Segmentation::GetName(), Impala::CmdOptions::GetNrArg(), Impala::Core::VideoSet::Segmentation::GetNrFramesVideo(), Impala::Core::VideoSet::Segmentation::GetNrShotsVideo(), Impala::Core::VideoSet::Keyframes::GetShotRKF(), Impala::Core::VideoSet::VideoSet::GetVideo(), Impala::Core::VideoSet::Mpeg7Doc::HasAnnotations(), 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().

00884 {
00885     typedef Core::VideoSet::VideoSet VideoSet;
00886     typedef Core::VideoSet::Segmentation Segmentation;
00887     typedef Core::VideoSet::Keyframes Keyframes;
00888     typedef Core::VideoSet::Mpeg7Doc Mpeg7Doc;
00889 
00890     ILOG_VAR(Impala.Application.Util.DoImportAnnotations);
00891     CmdOptions& options = CmdOptions::GetInstance();
00892     if (options.GetNrArg() < 6)
00893     {
00894         ILOG_ERROR("Need more parameters");
00895         return;
00896     }
00897     String videoSetName = options.GetArg(1);
00898     int fractions = Impala::atol(options.GetArg(2));
00899     if ((fractions != 25) && (fractions != 30000))
00900         ILOG_WARN("Never tried fractions = " << fractions);
00901     String conceptSet = options.GetArg(3);
00902     String mappingName = options.GetArg(4);
00903     String inputPath = options.GetArg(5);
00904 
00905     VideoSet* vidSet = Core::VideoSet::MakeVideoSet(videoSetName);
00906     SegmentationLocator sLoc(videoSetName, "segmentation", options);
00907     Segmentation* segmentation = SegmentationRepository().Get(sLoc, vidSet);
00908     KeyframesLocator kLoc(videoSetName, "keyframes", options);
00909     Keyframes* keyframes = KeyframesRepository().Get(kLoc, vidSet);
00910 
00911     Persistency::KeywordListLocator loc(vidSet->GetLocator(), conceptSet);
00912     Core::Table::KeywordList concepts =
00913         *(Persistency::KeywordListRepository().Get(loc));
00914 
00915     std::vector<String> lines;
00916     Impala::Util::SimpleMap<String, String> conceptMapping;
00917     FileLocator fLoc(mappingName);
00918     typedef Persistency::RepositoryInFileSystem FS;
00919     Persistency::File file = FS::GetInstance().GetFile(fLoc, false, false);
00920     file.ReadStrings(lines);
00921 
00922     for (int i=0 ; i<lines.size() ; i++)
00923     {
00924         Impala::Util::StringParser p(lines[i]);
00925         String topic = p.GetString(' ');
00926         String concept = p.GetString(' ', false);
00927         std::cout << topic << " = " << concept << std::endl;
00928         conceptMapping.Add(concept, topic);
00929     }
00930     for (int c=0 ; c<concepts.size() ; c++)
00931     {
00932         ILOG_INFO("doing concept " << concepts[c]);
00933         ILOG_NDC_PUSH(concepts[c]);
00934 
00935         String topic;
00936         if (!conceptMapping.Get(concepts[c], topic))
00937         {
00938             ILOG_ERROR("no topic for " << concepts[c]);
00939             ILOG_NDC_POP;
00940             continue;
00941         }
00942 
00943         std::vector<String> posAnnos;
00944         String fName = inputPath + "." + topic + ".1";
00945         FileLocator posLoc(vidSet->GetLocator(), fName);
00946         file = FS::GetInstance().GetFile(posLoc, false, false);
00947         file.ReadStrings(posAnnos);
00948 
00949         std::vector<String> negAnnos;
00950         fName = inputPath + "." + topic + ".0";
00951         FileLocator negLoc(vidSet->GetLocator(), fName);
00952         file = FS::GetInstance().GetFile(negLoc, false, false);
00953         file.ReadStrings(negAnnos);
00954         if ((posAnnos.size() == 0) || (negAnnos.size() == 0))
00955         {
00956             ILOG_ERROR("missing input for " << concepts[c]);
00957             ILOG_NDC_POP;
00958             continue;
00959         }
00960 
00961         std::sort(posAnnos.begin(), posAnnos.end());
00962         std::sort(negAnnos.begin(), negAnnos.end());
00963         for (int v=0 ; v<vidSet->NrFiles() ; v++)
00964         {
00965             String vidFile = vidSet->GetFile(v);
00966             int nrFrames = segmentation->GetNrFramesVideo(v);
00967             int frameRateNum = 0;
00968             int frameRateDen = 0;
00969             if (fractions == 0)
00970             {
00971                 Core::Stream::RgbDataSrc* rgbSrc = vidSet->GetVideo(v);
00972                 if ((!rgbSrc) || (rgbSrc->FrameRateNum() < 0)
00973                     || (rgbSrc->FrameRateDen() < 0))
00974                 {
00975                     ILOG_ERROR("Need src with known frame rate");
00976                     continue;
00977                 }
00978                 frameRateNum = rgbSrc->FrameRateNum();
00979                 frameRateDen = rgbSrc->FrameRateDen();
00980                 if (rgbSrc)
00981                     delete rgbSrc;
00982             }
00983             Mpeg7Doc mp7(vidFile, vidFile, nrFrames, fractions, false,
00984                          conceptSet, concepts[c], frameRateNum, frameRateDen);
00985 
00986             for (int s=0 ; s<segmentation->GetNrShotsVideo(v) ; s++)
00987             {
00988                 int shotId = segmentation->GetFirstShotVideo(v) + s;
00989                 String shotName = segmentation->GetName(shotId);
00990                 double relevance = -1;
00991                 if (find(posAnnos.begin(), posAnnos.end(), shotName) !=
00992                     posAnnos.end())
00993                 {
00994                     relevance = 1;
00995                 }
00996                 else if (find(negAnnos.begin(), negAnnos.end(), shotName) !=
00997                          negAnnos.end())
00998                 {
00999                     relevance = 0;
01000                 }
01001                 if (relevance < 0)
01002                     continue;
01003                 int key = keyframes->GetShotRKF(shotId);
01004 
01005                 String keyName = FileNameBase(keyframes->GetName(key));
01006                 int frameNr = keyframes->GetFrameNr(key);
01007                 mp7.AddAnnotation(concepts[c], keyName, frameNr, frameNr,
01008                                   relevance, 1);
01009             }
01010             if (mp7.HasAnnotations())
01011                 Core::VideoSet::Mpeg7DocWrite(&mp7, vidSet, v);
01012         }
01013         ILOG_NDC_POP;
01014     }
01015 }

Here is the call graph for this function:


Generated on Thu Jan 13 09:16:28 2011 for ImpalaSrc by  doxygen 1.5.1