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

CameraMovementReader.h

Go to the documentation of this file.
00001 #ifndef Impala_Application_SDash_CameraMovementReader_h
00002 #define Impala_Application_SDash_CameraMovementReader_h
00003 
00004 #include <string>
00005 #include <map>
00006 #include <vector>
00007 
00008 #include "Util/StringParser.h"
00009 #include "Basis/FileExists.h"
00010 #include "Util/IOBufferFile.h"
00011 
00012 #include "Visualization/Video.h"
00013 
00014 #include "Application/sdash/CameraEvent.h"
00015 
00016 namespace Impala {
00017 namespace Application {
00018 namespace SDash {
00019 
00020 class CameraMovementReader
00021 {
00022 
00023 public:
00024 
00025     // reads from the base path camera movements from files, for the video's specified;
00026     // adds as a side effect every frame nr involved in movement, to the video's movement annotations
00027     void Read(
00028         const std::string& basePath, 
00029         std::vector<Visualization::Video>& videos, 
00030         std::map<int, std::vector<CameraEvent> >& camEventSchedule)
00031     {
00032 
00033         int totalEventsFound = 0;
00034         int totalFramesFound = 0;
00035         std::vector<Visualization::Video>::iterator videoIter = videos.begin();
00036         while (videoIter != videos.end())
00037         {
00038             int videoId = videoIter->mId;
00039             int eventsFound = 0;
00040             int framesFound = 0;
00041             std::string filePath = basePath + "cam_moving_" + MakeString(videoId) + ".csv";
00042             if (FileExists(filePath))
00043             {
00044                 // open the file
00045                 Util::IOBufferFile file(filePath, true, true);
00046 
00047                 int prevFrameNr = -2;
00048                 int frameNr = -1;
00049                 CameraEvent camEvent;
00050                 do
00051                 {
00052                     // read a line, parse into frame nr
00053                     std::string line = file.ReadLine();
00054                     if (line.empty())
00055                     {
00056                         if (prevFrameNr >= 0)
00057                         {
00058                             // end last sequence
00059                             int firstFrameOfSeq = camEvent.FrameNr();
00060                             int eventTimeSec = firstFrameOfSeq * videoIter->GetTimePerFrame();
00061                             camEvent.SetComments(MakeString(2 + prevFrameNr - firstFrameOfSeq) + " frames");
00062                             camEventSchedule[eventTimeSec].push_back(camEvent);
00063                         }
00064 
00065                         break;
00066                     }
00067 
00068                     Util::StringParser parser(line);
00069                     frameNr = parser.GetInt(';');
00070                     if (frameNr > prevFrameNr + 1)
00071                     {
00072                         if (prevFrameNr >= 0)
00073                         {
00074                             // end previous sequence
00075                             int firstFrameOfSeq = camEvent.FrameNr();
00076                             int eventTimeSec = firstFrameOfSeq * videoIter->GetTimePerFrame();
00077                             camEvent.SetComments(MakeString(2 + prevFrameNr - firstFrameOfSeq) + " frames");
00078                             camEventSchedule[eventTimeSec].push_back(camEvent);
00079                         }
00080 
00081                         // start of a movement sequence
00082                         int camNr = videoId + 1;
00083                         camEvent = CameraEvent(camNr, 3, frameNr);
00084                         eventsFound++;
00085                         videoIter->AddMovementFrame(frameNr); // first frame of seq.
00086                         framesFound++;
00087                     }
00088                     //lastCamEventP->SetComments(MakeString(frameNr - lastCamEventP->FrameNr()) + " frames");
00089                     videoIter->AddMovementFrame(frameNr + 1); // movement ends at earliest at this frame
00090                     framesFound++;
00091                     prevFrameNr = frameNr;
00092                 } while (true);
00093             }
00094 
00095             std::cout << eventsFound << " camera movements found for video #" << videoId << std::endl;
00096             std::cout << framesFound << " camera movement frames found for video #" << videoId << std::endl;
00097             totalEventsFound += eventsFound;
00098             totalFramesFound += framesFound;
00099             videoIter++;
00100         }
00101 
00102         std::cout << totalEventsFound << " camera movements found in total" << std::endl;
00103         std::cout << totalFramesFound << " camera movement frames found in total" << std::endl;
00104         //return 0;
00105     }
00106 
00107 private:
00108 
00109 
00110 }; //class
00111 
00112 }
00113 }
00114 }
00115 
00116 #endif

Generated on Fri Mar 19 09:30:38 2010 for ImpalaSrc by  doxygen 1.5.1