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

void Impala::Application::Util::DoImportAnnotations (  ) 

Definition at line 772 of file mainUtil.cpp.

References Impala::Core::VideoSet::Mpeg7Doc::AddAnnotation(), Impala::atol(), Impala::FileNameBase(), Impala::FileNamePath(), Impala::FileNameTail(), Impala::Core::Stream::RgbDataSrc::FrameRateDen(), Impala::Core::Stream::RgbDataSrc::FrameRateNum(), Impala::CmdOptions::GetArg(), Impala::Core::Database::RawDataSet::GetFile(), Impala::Core::VideoSet::Keyframes::GetFrameId(), Impala::Core::VideoSet::Keyframes::GetFrameNr(), Impala::CmdOptions::GetInstance(), Impala::Core::VideoSet::Keyframes::GetName(), Impala::CmdOptions::GetNrArg(), Impala::Core::VideoSet::Segmentation::GetNrFramesVideo(), Impala::Core::VideoSet::VideoSet::GetVideo(), Impala::Core::VideoSet::Keyframes::GetVideoId(), ILOG_ERROR, ILOG_INFO, ILOG_NDC_POP, ILOG_NDC_PUSH, ILOG_VAR, ILOG_WARN, Impala::Core::VideoSet::MakeVideoSet(), Impala::Core::VideoSet::Mpeg7DocWrite(), and Impala::Persistency::File::ReadStrings().

Referenced by mainUtil().

00773 {
00774     typedef Core::VideoSet::VideoSet VideoSet;
00775     typedef Core::VideoSet::Segmentation Segmentation;
00776     typedef Core::VideoSet::Keyframes Keyframes;
00777     typedef Core::VideoSet::Mpeg7Doc Mpeg7Doc;
00778 
00779     ILOG_VAR(Impala.Application.Util.DoImportAnnotations);
00780     CmdOptions& options = CmdOptions::GetInstance();
00781     if (options.GetNrArg() < 4)
00782     {
00783         ILOG_ERROR("Need more parameters");
00784         return;
00785     }
00786     String videoSetName = options.GetArg(1);
00787     int fractions = Impala::atol(options.GetArg(2));
00788     if ((fractions != 25) && (fractions != 30000))
00789         ILOG_WARN("Never tried fractions = " << fractions);
00790     String conceptSet = options.GetArg(3);
00791 
00792     VideoSet* vidSet = Core::VideoSet::MakeVideoSet(videoSetName);
00793     SegmentationLocator sLoc(videoSetName, "segmentation", options);
00794     Segmentation* segmentation = SegmentationRepository().Get(sLoc, vidSet);
00795     KeyframesLocator kLoc(videoSetName, "keyframes", options);
00796     Keyframes* keyframes = KeyframesRepository().Get(kLoc, vidSet);
00797     FileLocator fLoc(conceptSet);
00798     typedef Persistency::RepositoryInFileSystem FS;
00799     Persistency::File file = FS::GetInstance().GetFile(fLoc, false, false);
00800     std::vector<String> concepts;
00801     file.ReadStrings(concepts);
00802     String path = FileNamePath(conceptSet) + "/";
00803     conceptSet = FileNameTail(conceptSet);
00804     for (int c=0 ; c<concepts.size() ; c++)
00805     {
00806         ILOG_INFO("doing concept " << concepts[c]);
00807         ILOG_NDC_PUSH(concepts[c]);
00808         String fName = path + concepts[c] + ".ann";
00809         std::vector<String> lines;
00810         fLoc = FileLocator(fName);
00811         file = FS::GetInstance().GetFile(fLoc, false, false);
00812         file.ReadStrings(lines);
00813         int curVidId = -1;
00814         Mpeg7Doc* curDoc = 0;
00815         for (int l=0 ; l<lines.size() ; l++)
00816         {
00817             Impala::Util::StringParser p(lines[l]);
00818             String s = p.GetString(' '); // Person
00819             s = p.GetString(' '); // Organizer
00820             s = p.GetString(' '); // Concept
00821             s = p.GetString(' '); // Videoname
00822             s = Impala::FileNameTail(p.GetString(' ')); // Keyframename
00823             int key = keyframes->GetFrameId(s + ".jpg");
00824             if (key == -1)
00825             {
00826                 ILOG_ERROR("Unable to find keyframe " << s);
00827                 continue;
00828             }
00829             double relevance = (p.GetString(' ', false) == "P") ? 1.0 : 0.0;
00830             double confidence = 1.0;
00831             if (!p.TheEnd() && (p.GetString(' ', false) == "S"))
00832                 relevance = 0.5; // open for debate :-)
00833             
00834             if (keyframes->GetVideoId(key) != curVidId)
00835             {   // new video
00836                 if (curDoc)
00837                 {
00838                     Core::VideoSet::Mpeg7DocWrite(curDoc, vidSet, curVidId);
00839                     delete curDoc;
00840                     curDoc = 0;
00841                 }
00842                 curVidId = keyframes->GetVideoId(key);
00843                 String vidFile = vidSet->GetFile(curVidId);
00844                 int nrFrames = segmentation->GetNrFramesVideo(curVidId);
00845                 int frameRateNum = 0;
00846                 int frameRateDen = 0;
00847                 if (fractions == 0)
00848                 {
00849                     Core::Stream::RgbDataSrc* rgbSrc = vidSet->GetVideo(curVidId);
00850                     if ((!rgbSrc) || (rgbSrc->FrameRateNum() < 0)
00851                         || (rgbSrc->FrameRateDen() < 0))
00852                     {
00853                         ILOG_ERROR("Need src with known frame rate");
00854                         continue;
00855                     }
00856                     frameRateNum = rgbSrc->FrameRateNum();
00857                     frameRateDen = rgbSrc->FrameRateDen();
00858                     if (rgbSrc)
00859                         delete rgbSrc;
00860                 }
00861                 curDoc = new Mpeg7Doc(vidFile, vidFile, nrFrames, fractions,
00862                                       false, conceptSet, concepts[c],
00863                                       frameRateNum, frameRateDen);
00864             }
00865             String name = FileNameBase(keyframes->GetName(key));
00866             int frameNr = keyframes->GetFrameNr(key);
00867             curDoc->AddAnnotation(concepts[c], name, frameNr, frameNr,
00868                                   relevance, confidence);
00869         }
00870         if (curDoc)
00871         {
00872             Core::VideoSet::Mpeg7DocWrite(curDoc, vidSet, curVidId);
00873             delete curDoc;
00874         }
00875         ILOG_NDC_POP;
00876     }
00877 }

Here is the call graph for this function:


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