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

mainRepository.cpp

Go to the documentation of this file.
00001 #include "Persistency/ImageSetRepository.h"
00002 #include "Persistency/AnnotationTableSetRepository.h"
00003 #include "Persistency/AnnotationTableRepository.h"
00004 #include "Persistency/FeatureTableRepository.h"
00005 #include "Persistency/ImageArchiveRepository.h"
00006 #include "Persistency/VideoSetRepository.h"
00007 #include "Persistency/SegmentationRepository.h"
00008 #include "Persistency/KeyframesRepository.h"
00009 #include "Persistency/KeywordListRepository.h"
00010 #include "Persistency/SimilarityTableSetRepository.h"
00011 #include "Core/Table/KeywordListDiff.h"
00012 
00013 
00014 
00015 // since we are not using libraries:
00016 #include "Link/ImpalaLib.cpp"
00017 
00018 namespace Impala
00019 {
00020 namespace Application
00021 {
00022 namespace Repository
00023 {
00024 
00025 
00026 using namespace Persistency;
00027 
00028 using Core::Array::ImageArchive;
00029 using Core::Database::RawDataSet;
00030 using Core::ImageSet::ImageSet;
00031 using Core::VideoSet::VideoSet;
00032 using Core::VideoSet::Segmentation;
00033 using Core::VideoSet::Keyframes;
00034 using Core::Table::AnnotationTable;
00035 using Core::Table::AnnotationTableSet;
00036 using Core::Table::KeywordList;
00037 using Core::Table::SimilarityTableSet;
00038 using Core::Feature::FeatureTable;
00039 
00040 // Convenience functions
00041 
00042 RawDataSet*
00043 GetRawDataSet(String locString, String setName, bool required)
00044 {
00045     ILOG_VAR(Impala.Application.Repository.GetRawDataSet);
00046 
00047     Locator loc(locString, setName);
00048     RawDataSet* dataSet = 0;
00049     if (VideoSetsRepository::GetInstance().Contains(setName))
00050     {
00051         dataSet = VideoSetRepository().Get(loc);
00052     }
00053     else if (ImageSetsRepository::GetInstance().Contains(setName))
00054     {
00055         ImageSetLocator imSetLoc(loc, "");
00056         dataSet = ImageSetRepository().Get(imSetLoc);
00057     }
00058     else if (required)
00059     {
00060         ILOG_ERROR("Could find " << loc);
00061     }
00062     return dataSet;
00063 }
00064 
00065 RawDataSet*
00066 GetRawDataSet(CmdOptions& options, bool required)
00067 {
00068     ILOG_VAR(Impala.Application.Repository.GetRawDataSet);
00069 
00070     int a = 1;
00071     String locString = options.GetArg(a++);
00072     String setName = options.GetArg(a++);
00073     return GetRawDataSet(locString, setName, required);
00074 }
00075 
00076 ImageSet*
00077 GetImageSet(String locString, String setName, bool required)
00078 {
00079     ILOG_VAR(Impala.Application.Repository.GetImageSet);
00080 
00081     ImageSetLocator loc(locString, setName);
00082     ImageSet* imSet = 0;
00083     if (ImageSetsRepository::GetInstance().Contains(setName))
00084     {
00085         imSet = ImageSetRepository().Get(loc);
00086     }
00087     else if (required)
00088     {
00089         ILOG_ERROR("Could find " << loc);
00090     }
00091     return imSet;
00092 }
00093 
00094 ImageSet*
00095 GetImageSet(CmdOptions& options, bool required, bool getSrcLoc = true)
00096 {
00097     ILOG_VAR(Impala.Application.Repository.GetImageSet);
00098 
00099     int nrArg = 2;
00100     if (!getSrcLoc)
00101         nrArg++;
00102     if (options.GetNrArg() < nrArg)
00103     {
00104         ILOG_ERROR("Need at least " << nrArg << " parameters");
00105     }
00106     int a = 1;
00107     String locString = options.GetArg(a++);
00108     String setName = options.GetArg(a++);
00109     if (!getSrcLoc)
00110         locString = options.GetArg(a++);
00111     return GetImageSet(locString, setName, required);
00112 }
00113 
00114 VideoSet*
00115 GetVideoSet(String locString, String setName, bool required)
00116 {
00117     ILOG_VAR(Impala.Application.Repository.GetVideoSet);
00118 
00119     Locator loc(locString, setName);
00120     VideoSet* vidSet = 0;
00121     if (VideoSetsRepository::GetInstance().Contains(setName))
00122     {
00123         vidSet = VideoSetRepository().Get(loc);
00124     }
00125     else if (required)
00126     {
00127         ILOG_ERROR("Could find " << loc);
00128     }
00129     return vidSet;
00130 }
00131 
00132 VideoSet*
00133 GetVideoSet(CmdOptions& options, bool required, bool getSrcLoc = true)
00134 {
00135     ILOG_VAR(Impala.Application.Repository.GetVideoSet);
00136 
00137     int nrArg = 2;
00138     if (!getSrcLoc)
00139         nrArg++;
00140     if (options.GetNrArg() < nrArg)
00141     {
00142         ILOG_ERROR("Need at least " << nrArg << " parameters");
00143     }
00144     int a = 1;
00145     String locString = options.GetArg(a++);
00146     String setName = options.GetArg(a++);
00147     if (!getSrcLoc)
00148         locString = options.GetArg(a++);
00149     return GetVideoSet(locString, setName, required);
00150 }
00151 
00152 // ImageSets part
00153 
00154 void
00155 DoDumpImageSets()
00156 {
00157     ImageSetsRepository::GetInstance().Dump();
00158 }
00159 
00160 // VideoSets part
00161 
00162 void
00163 DoDumpVideoSets()
00164 {
00165     VideoSetsRepository::GetInstance().Dump();
00166 }
00167 
00168 void
00169 DoCopyVideoSets()
00170 {
00171     ILOG_VAR(Impala.Application.Repository.DoCopyVideoSets);
00172     CmdOptions& options = CmdOptions::GetInstance();
00173 
00174     String locString = options.GetArg(1);
00175     Locator dstLoc(options.GetArg(1), "dummy");
00176     VideoSetsRepository::GetInstance().CopyTo(dstLoc);
00177 }
00178 
00179 // ImageSet part
00180 
00181 void
00182 DoDumpImageSet()
00183 {
00184     ILOG_VAR(Impala.Application.Repository.DoDumpImageSet);
00185     CmdOptions& options = CmdOptions::GetInstance();
00186 
00187     ImageSet* imSet = GetImageSet(options, true);
00188     imSet->Dump(0, -1, options.GetInt("start"), options.GetInt("end"));
00189     delete imSet;
00190 }
00191 
00192 void
00193 DoDiffImageSet()
00194 {
00195     ILOG_VAR(Impala.Application.Repository.DoDiffImageSet);
00196     CmdOptions& options = CmdOptions::GetInstance();
00197 
00198     ImageSet* imSet1 = GetImageSet(options, true);
00199     ImageSet* imSet2 = GetImageSet(options, true, false);
00200     imSet1->Diff(imSet2);
00201     delete imSet2;
00202     delete imSet1;
00203 }
00204 
00205 void
00206 DoCopyImageSet()
00207 {
00208     ILOG_VAR(Impala.Application.Repository.DoCopyImageSet);
00209     CmdOptions& options = CmdOptions::GetInstance();
00210 
00211     String locString1 = options.GetArg(1);
00212     String setName = options.GetArg(2);
00213     String locString2 = options.GetArg(3);
00214     ImageSet* imSet = GetImageSet(options, true);
00215     ImageSetLocator setLoc2(locString2, setName);
00216     ImageSetRepository().Add(setLoc2, imSet);
00217     delete imSet;
00218 }
00219 
00220 // VideoSet part
00221 
00222 void
00223 DoDumpVideoSet()
00224 {
00225     ILOG_VAR(Impala.Application.Repository.DoDumpVideoSet);
00226     CmdOptions& options = CmdOptions::GetInstance();
00227 
00228     VideoSet* vidSet = GetVideoSet(options, true);
00229     vidSet->Dump(0, -1, options.GetInt("start"), options.GetInt("end"));
00230     delete vidSet;
00231 }
00232 
00233 void
00234 DoDiffVideoSet()
00235 {
00236     ILOG_VAR(Impala.Application.Repository.DoDiffVideoSet);
00237     CmdOptions& options = CmdOptions::GetInstance();
00238 
00239     VideoSet* vidSet1 = GetVideoSet(options, true);
00240     VideoSet* vidSet2 = GetVideoSet(options, true, false);
00241     vidSet1->Diff(vidSet2);
00242     delete vidSet2;
00243     delete vidSet1;
00244 }
00245 
00246 void
00247 DoCopyVideoSet()
00248 {
00249     ILOG_VAR(Impala.Application.Repository.DoCopyVideoSet);
00250     CmdOptions& options = CmdOptions::GetInstance();
00251 
00252     String locString1 = options.GetArg(1);
00253     String setName = options.GetArg(2);
00254     String locString2 = options.GetArg(3);
00255     VideoSet* vidSet = GetVideoSet(options, true);
00256     Locator setLoc2(locString2, setName);
00257     VideoSetRepository().Add(setLoc2, vidSet);
00258     delete vidSet;
00259 }
00260 
00261 // Segmentation part
00262 
00263 SegmentationLocator
00264 GetSegmentationLocator(CmdOptions& options, bool getSrcLoc)
00265 {
00266     ILOG_VAR(Impala.Application.Repository.GetSegmentationLocator);
00267 
00268     int nrArg = 2;
00269     if (!getSrcLoc)
00270         nrArg++;
00271     if (options.GetNrArg() < nrArg)
00272     {
00273         ILOG_ERROR("Need at least " << nrArg << " parameters");
00274     }
00275 
00276     int a = 1;
00277     String locString = options.GetArg(a++);
00278     String setName = options.GetArg(a++);
00279     if (!getSrcLoc)
00280         locString = options.GetArg(a++);
00281     return SegmentationLocator(locString, setName, "segmentation");
00282 }
00283 
00284 void
00285 DoDumpSegmentation()
00286 {
00287     ILOG_VAR(Impala.Application.Repository.DoDumpSegmentation);
00288     CmdOptions& options = CmdOptions::GetInstance();
00289 
00290     SegmentationLocator loc = GetSegmentationLocator(options, true);
00291     VideoSet* vidSet = GetVideoSet(options, true);
00292     Segmentation* seg = SegmentationRepository().Get(loc, vidSet);
00293     ILOG_INFO("nrVideos = " << seg->GetNrVideos());
00294     ILOG_INFO("nrShots = " << seg->GetNrShots());
00295     ILOG_INFO("nrFrames = " << seg->GetTotalNrFrames());
00296     if (options.GetInt("end") == 0)
00297         return;
00298     int minNr = 10000000;
00299     int maxNr = 0;
00300     for (int i=0 ; i<seg->GetNrVideos() ; i++)
00301     {
00302         int nrFrames = seg->GetNrFramesVideo(i);
00303         std::cout << "  vid " << i << " has " << seg->GetNrShotsVideo(i)
00304                   << " shots and " << nrFrames << " frames" << std::endl;
00305         if (nrFrames < minNr)
00306             minNr = nrFrames;
00307         if (nrFrames > maxNr)
00308             maxNr = nrFrames;
00309     }
00310     std::cout << "  min nr frames = " << minNr << ", max nr = " << maxNr
00311               << std::endl;
00312     seg->Dump(options.GetInt("start"), options.GetInt("end"));
00313     delete seg;
00314     delete vidSet;
00315 }
00316 
00317 void
00318 DoDiffSegmentation()
00319 {
00320     ILOG_VAR(Impala.Application.Repository.DoDiffSegmentation);
00321     CmdOptions& options = CmdOptions::GetInstance();
00322 
00323     SegmentationLocator loc1 = GetSegmentationLocator(options, true);
00324     VideoSet* vidSet1 = GetVideoSet(options, true);
00325     Segmentation* seg1 = SegmentationRepository().Get(loc1, vidSet1);
00326 
00327     SegmentationLocator loc2 = GetSegmentationLocator(options, false);
00328     VideoSet* vidSet2 = VideoSetRepository().Get(loc2);
00329     Segmentation* seg2 = SegmentationRepository().Get(loc2, vidSet2);
00330 
00331     seg1->Diff(seg2);
00332 
00333     delete seg2;
00334     delete seg1;
00335     delete vidSet2;
00336     delete vidSet1;
00337 }
00338 
00339 void
00340 DoCopySegmentation()
00341 {
00342     ILOG_VAR(Impala.Application.Repository.DoCopySegmentation);
00343     CmdOptions& options = CmdOptions::GetInstance();
00344 
00345     SegmentationLocator loc1 = GetSegmentationLocator(options, true);
00346     VideoSet* vidSet = GetVideoSet(options, true);
00347     Segmentation* seg = SegmentationRepository().Get(loc1, vidSet);
00348 
00349     SegmentationLocator loc2 = GetSegmentationLocator(options, false);
00350     SegmentationRepository().Add(loc2, seg);
00351     delete seg;
00352     delete vidSet;
00353 }
00354 
00355 // Keyframes part
00356 
00357 KeyframesLocator
00358 GetKeyframesLocator(CmdOptions& options, bool getSrcLoc)
00359 {
00360     ILOG_VAR(Impala.Application.Repository.GetKeyframesLocator);
00361 
00362     int nrArg = 2;
00363     if (!getSrcLoc)
00364         nrArg++;
00365     if (options.GetNrArg() < nrArg)
00366     {
00367         ILOG_ERROR("Need at least " << nrArg << " parameters");
00368     }
00369 
00370     int a = 1;
00371     String locString = options.GetArg(a++);
00372     String setName = options.GetArg(a++);
00373     if (!getSrcLoc)
00374         locString = options.GetArg(a++);
00375     return KeyframesLocator(locString, setName, "keyframes");
00376 }
00377 
00378 void
00379 DoDumpKeyframes()
00380 {
00381     ILOG_VAR(Impala.Application.Repository.DoDumpKeyframes);
00382     CmdOptions& options = CmdOptions::GetInstance();
00383 
00384     KeyframesLocator loc = GetKeyframesLocator(options, true);
00385     VideoSet* vidSet = GetVideoSet(options, true);
00386     Keyframes* keys = KeyframesRepository().Get(loc, vidSet);
00387 
00388     ILOG_INFO("nrVideos = " << keys->GetNrVideos());
00389     ILOG_INFO("nrShots = " << keys->GetNrShots());
00390     ILOG_INFO("nrKeyframes = " << keys->GetNrKeyframes());
00391     if (options.GetInt("end") == 0)
00392         return;
00393     for (int i=0 ; i<keys->GetNrVideos() ; i++)
00394         std::cout << "  vid " << i << " has " << keys->GetNrKeyframesVideo(i)
00395                   << " keyframes" << std::endl;
00396     //keys.DumpGroups();
00397     keys->Dump(options.GetInt("start"), options.GetInt("end"));
00398     delete keys;
00399     delete vidSet;
00400 }
00401 
00402 void
00403 DoDiffKeyframes()
00404 {
00405     ILOG_VAR(Impala.Application.Repository.DoDiffKeyframes);
00406     CmdOptions& options = CmdOptions::GetInstance();
00407 
00408     KeyframesLocator loc1 = GetKeyframesLocator(options, true);
00409     VideoSet* vidSet1 = GetVideoSet(options, true);
00410     Keyframes* keys1 = KeyframesRepository().Get(loc1, vidSet1);
00411 
00412     KeyframesLocator loc2 = GetKeyframesLocator(options, false);
00413     VideoSet* vidSet2 = VideoSetRepository().Get(loc2);
00414     Keyframes* keys2 = KeyframesRepository().Get(loc2, vidSet2);
00415 
00416     keys1->Diff(keys2);
00417 
00418     delete keys2;
00419     delete keys1;
00420     delete vidSet2;
00421     delete vidSet1;
00422 }
00423 
00424 void
00425 DoCopyKeyframes()
00426 {
00427     ILOG_VAR(Impala.Application.Repository.DoCopyKeyframes);
00428     CmdOptions& options = CmdOptions::GetInstance();
00429 
00430     KeyframesLocator loc1 = GetKeyframesLocator(options, true);
00431     VideoSet* vidSet = GetVideoSet(options, true);
00432     Keyframes* keys = KeyframesRepository().Get(loc1, vidSet);
00433 
00434     KeyframesLocator loc2 = GetKeyframesLocator(options, false);
00435     KeyframesRepository().Add(loc2, keys);
00436     delete keys;
00437     delete vidSet;
00438 }
00439 
00440 // ImageArchive part
00441 
00442 ImageArchiveLocator
00443 GetImageArchiveLocator(CmdOptions& options, bool getSrcLoc)
00444 {
00445     ILOG_VAR(Impala.Application.Repository.GetImageArchiveLocator);
00446 
00447     int nrArg = 6;
00448     if (!getSrcLoc)
00449         nrArg++;
00450     if (options.GetNrArg() < nrArg)
00451     {
00452         ILOG_ERROR("Need at least " << nrArg << " parameters");
00453     }
00454 
00455     int a = 1;
00456     String locString = options.GetArg(a++);
00457     String setName = options.GetArg(a++);
00458     bool frames = StringToBool(options.GetArg(a++));
00459     String container = options.GetArg(a++);
00460     String name = options.GetArg(a++);
00461     if (!getSrcLoc)
00462         locString = options.GetArg(a++);
00463     return ImageArchiveLocator(locString, setName, frames, container, name, 0);
00464 }
00465 
00466 void
00467 DoDumpImageArchive()
00468 {
00469     ILOG_VAR(Impala.Application.Repository.DoDumpImageArchive);
00470     CmdOptions& options = CmdOptions::GetInstance();
00471 
00472     ImageArchiveLocator loc = GetImageArchiveLocator(options, true);
00473     VideoSet* vidSet = GetVideoSet(options, true);
00474     String container = loc.GetContainer();
00475     int nrArchives = (container == "ALL") ? vidSet->NrFiles() : 1;
00476     for (int i=0 ; i<nrArchives ; i++)
00477     {
00478         String cur = (container == "ALL") ? vidSet->GetFile(i) : container;
00479         loc.SetContainer(cur);
00480         int v = vidSet->GetFileId(cur);
00481         Quid quid = (v != -1) ? vidSet->GetQuidVideo(v, false) : 0;
00482         loc.SetQuid(quid);
00483         ImageArchive* archive = ImageArchiveRepository().Get(loc);
00484         std::cout << loc << " has " << archive->NrImages() << " images"
00485                   << std::endl;
00486         if (archive->NrImages() > 0)
00487         {
00488             Core::Array::Array2dVec3UInt8* im = archive->ReadImage(0);
00489             std::cout << "ImageSize = " << im->CW() << "x" << im->CH()
00490                       << std::endl;
00491             delete im;
00492         }
00493         delete archive;
00494     }
00495     delete vidSet;
00496 }
00497 
00498 void
00499 DoDiffImageArchive()
00500 {
00501     ILOG_VAR(Impala.Application.Repository.DoDiffImageArchive);
00502     CmdOptions& options = CmdOptions::GetInstance();
00503 
00504     ImageArchiveLocator loc1 = GetImageArchiveLocator(options, true);
00505     ImageArchiveLocator loc2 = GetImageArchiveLocator(options, false);
00506     VideoSet* vidSet = GetVideoSet(options, true);
00507     String container = loc1.GetContainer();
00508     int nrArchives = (container == "ALL") ? vidSet->NrFiles() : 1;
00509     for (int i=0 ; i<nrArchives ; i++)
00510     {
00511         String cur = (container == "ALL") ? vidSet->GetFile(i) : container;
00512         ILOG_INFO("Checking " << i << " = " << cur);
00513         int v = vidSet->GetFileId(cur);
00514         Quid quid = (v != -1) ? vidSet->GetQuidVideo(v, false) : 0;
00515         loc1.SetContainer(cur);
00516         loc1.SetQuid(quid);
00517         ImageArchive* archive1 = ImageArchiveRepository().Get(loc1);
00518         loc2.SetContainer(cur);
00519         loc2.SetQuid(quid);
00520         ImageArchive* archive2 = ImageArchiveRepository().Get(loc2);
00521         archive1->Diff(archive2);
00522         delete archive2;
00523         delete archive1;
00524     }
00525     delete vidSet;
00526 }
00527 
00528 void
00529 DoCopyImageArchive()
00530 {
00531     ILOG_VAR(Impala.Application.Repository.DoCopyImageArchive);
00532     CmdOptions& options = CmdOptions::GetInstance();
00533 
00534     ImageArchiveLocator loc1 = GetImageArchiveLocator(options, true);
00535     ImageArchiveLocator loc2 = GetImageArchiveLocator(options, false);
00536     VideoSet* vidSet = GetVideoSet(options, true);
00537     String container = loc1.GetContainer();
00538     int nrArchives = (container == "ALL") ? vidSet->NrFiles() : 1;
00539     for (int i=0 ; i<nrArchives ; i++)
00540     {
00541         String cur = (container == "ALL") ? vidSet->GetFile(i) : container;
00542         int v = vidSet->GetFileId(cur);
00543         Quid quid = (v != -1) ? vidSet->GetQuidVideo(v, false) : 0;
00544         loc1.SetContainer(cur);
00545         loc1.SetQuid(quid);
00546         ImageArchive* archive = ImageArchiveRepository().Get(loc1);
00547         loc2.SetContainer(cur);
00548         loc2.SetQuid(quid);
00549         ImageArchiveRepository().Add(loc2, archive);
00550         delete archive;
00551     }
00552     delete vidSet;
00553 }
00554 
00555 // FeatureTable part
00556 
00557 FeatureLocator
00558 GetFeatureLocator(CmdOptions& options, bool getSrcLoc)
00559 {
00560     ILOG_VAR(Impala.Application.Repository.GetFeatureLocator);
00561 
00562     int nrArg = 8;
00563     if (!getSrcLoc)
00564         nrArg++;
00565     if (options.GetNrArg() < nrArg)
00566     {
00567         ILOG_ERROR("Need at least " << nrArg << " parameters");
00568     }
00569 
00570     int a = 1;
00571     String locString = options.GetArg(a++);
00572     String setName = options.GetArg(a++);
00573     bool isCodebook = StringToBool(options.GetArg(a++));
00574     bool isIndex = StringToBool(options.GetArg(a++));
00575     String walkType = options.GetArg(a++);
00576     String feature = options.GetArg(a++);
00577     String container = options.GetArg(a++);
00578     if (!getSrcLoc)
00579         locString = options.GetArg(a++);
00580     return FeatureLocator(locString, setName, isCodebook, isIndex, walkType,
00581                           feature, container);
00582 }
00583 
00584 void
00585 DoDumpFeatureTable()
00586 {
00587     ILOG_VAR(Impala.Application.Repository.DoDumpFeatureTable);
00588     CmdOptions& options = CmdOptions::GetInstance();
00589 
00590     FeatureLocator loc = GetFeatureLocator(options, true);
00591     VideoSet* vidSet = GetVideoSet(options, true);
00592     String container = loc.GetContainer();
00593     int nrFiles = (container == "ALL") ? vidSet->NrFiles() : 1;
00594     for (int i=0 ; i<nrFiles ; i++)
00595     {
00596         String cur = (container == "ALL") ? vidSet->GetFile(i) : container;
00597         loc.SetContainer(cur);
00598         FeatureTable* tab = FeatureTableRepository().Get(loc);
00599         std::cout << "loc = " << loc << std::endl;
00600         tab->Dump(0, options.GetInt("start"), options.GetInt("end"));
00601         delete tab;
00602     }
00603 }
00604 
00605 void
00606 DoDiffFeatureTable()
00607 {
00608     ILOG_VAR(Impala.Application.Repository.DoDiffFeatureTable);
00609     CmdOptions& options = CmdOptions::GetInstance();
00610 
00611     FeatureLocator loc1 = GetFeatureLocator(options, true);
00612     FeatureLocator loc2 = GetFeatureLocator(options, false);
00613     VideoSet* vidSet = GetVideoSet(options, true);
00614     String container = loc1.GetContainer();
00615     int nrFiles = (container == "ALL") ? vidSet->NrFiles() : 1;
00616     for (int i=0 ; i<nrFiles ; i++)
00617     {
00618         String cur = (container == "ALL") ? vidSet->GetFile(i) : container;
00619         loc1.SetContainer(cur);
00620         FeatureTable* tab1 = FeatureTableRepository().Get(loc1);
00621         loc2.SetContainer(cur);
00622         FeatureTable* tab2 = FeatureTableRepository().Get(loc2);
00623         tab1->Diff(tab2);
00624         delete tab2;
00625         delete tab1;
00626     }
00627 }
00628 
00629 void
00630 DoCopyFeatureTable()
00631 {
00632     ILOG_VAR(Impala.Application.Repository.DoCopyFeatureTable);
00633     CmdOptions& options = CmdOptions::GetInstance();
00634 
00635     FeatureLocator loc1 = GetFeatureLocator(options, true);
00636     FeatureLocator loc2 = GetFeatureLocator(options, false);
00637     VideoSet* vidSet = GetVideoSet(options, true);
00638     String container = loc1.GetContainer();
00639     int nrFiles = (container == "ALL") ? vidSet->NrFiles() : 1;
00640     for (int i=0 ; i<nrFiles ; i++)
00641     {
00642         String cur = (container == "ALL") ? vidSet->GetFile(i) : container;
00643         loc1.SetContainer(cur);
00644         FeatureTable* tab = FeatureTableRepository().Get(loc1);
00645         loc2.SetContainer(cur);
00646         FeatureTableRepository().Add(loc2, tab);
00647         delete tab;
00648     }
00649 }
00650 
00651 // KeywordList part
00652 
00653 KeywordListLocator
00654 GetKeywordListLocator(CmdOptions& options, bool getSrcLoc)
00655 {
00656     ILOG_VAR(Impala.Application.Repository.GetKeywordListLocator);
00657 
00658     int nrArg = 3;
00659     if (!getSrcLoc)
00660         nrArg++;
00661     if (options.GetNrArg() < nrArg)
00662     {
00663         ILOG_ERROR("Need at least " << nrArg << " parameters");
00664     }
00665 
00666     int a = 1;
00667     String locString = options.GetArg(a++);
00668     String setName = options.GetArg(a++);
00669     String conceptSet = options.GetArg(a++);
00670     if (!getSrcLoc)
00671         locString = options.GetArg(a++);
00672     return KeywordListLocator(locString, setName, conceptSet);
00673 }
00674 
00675 void
00676 DoDumpKeywordList()
00677 {
00678     ILOG_VAR(Impala.Application.Repository.DoDumpKeywordList);
00679     CmdOptions& options = CmdOptions::GetInstance();
00680 
00681     KeywordListLocator loc = GetKeywordListLocator(options, true);
00682     KeywordList keyList = *(KeywordListRepository().Get(loc));
00683     for (int i=0 ; i<keyList.size() ; i++)
00684         std::cout << keyList[i] << std::endl;
00685 }
00686 
00687 void
00688 DoDiffKeywordList()
00689 {
00690     ILOG_VAR(Impala.Application.Repository.DoDiffKeywordList);
00691     CmdOptions& options = CmdOptions::GetInstance();
00692 
00693     KeywordListLocator loc1 = GetKeywordListLocator(options, true);
00694     KeywordList keyList1 = *(KeywordListRepository().Get(loc1));
00695     KeywordListLocator loc2 = GetKeywordListLocator(options, false);
00696     KeywordList keyList2 = *(KeywordListRepository().Get(loc2));
00697     Core::Table::KeywordListDiff(keyList1, keyList2);    
00698 }
00699 
00700 void
00701 DoCopyKeywordList()
00702 {
00703     ILOG_VAR(Impala.Application.Repository.DoCopyKeywordList);
00704     CmdOptions& options = CmdOptions::GetInstance();
00705 
00706     KeywordListLocator loc1 = GetKeywordListLocator(options, true);
00707     KeywordList* keyList = KeywordListRepository().Get(loc1);
00708     KeywordListLocator loc2 = GetKeywordListLocator(options, false);
00709     KeywordListRepository().Add(loc2, keyList);
00710     delete keyList;
00711 }
00712 
00713 // AnnotationTable part
00714 
00715 AnnotationTableLocator
00716 GetAnnotationTableLocator(CmdOptions& options, bool getSrcLoc)
00717 {
00718     ILOG_VAR(Impala.Application.Repository.GetAnnotationTableLocator);
00719 
00720     int nrArg = 6;
00721     if (!getSrcLoc)
00722         nrArg++;
00723     if (options.GetNrArg() < nrArg)
00724     {
00725         ILOG_ERROR("Need at least " << nrArg << " parameters");
00726     }
00727 
00728     int a = 1;
00729     String locString = options.GetArg(a++);
00730     String setName = options.GetArg(a++);
00731     int quidClass = StringToQuidClass(options.GetArg(a++));
00732     String conceptSet = options.GetArg(a++);
00733     String keyword = options.GetArg(a++);
00734     if (!getSrcLoc)
00735         locString = options.GetArg(a++);
00736     return AnnotationTableLocator(locString, setName, quidClass, conceptSet,
00737                                   keyword);
00738 }
00739 
00740 void
00741 DoDumpAnnotationTable()
00742 {
00743     ILOG_VAR(Impala.Application.Repository.DoDumpAnnotationTable);
00744     CmdOptions& options = CmdOptions::GetInstance();
00745 
00746     AnnotationTableLocator loc = GetAnnotationTableLocator(options, true);
00747     AnnotationTable* tab = AnnotationTableRepository().Get(loc);
00748     if (tab == 0)
00749         return;
00750     RawDataSet* dataSet = GetRawDataSet(options, false);
00751     tab->Dump(dataSet, options.GetInt("start"), options.GetInt("end"));
00752     tab->DumpSummary();
00753     delete tab;
00754     if (dataSet)
00755         delete dataSet;
00756 }
00757 
00758 void
00759 DoDiffAnnotationTable()
00760 {
00761     ILOG_VAR(Impala.Application.Repository.DoDiffAnnotationTable);
00762     CmdOptions& options = CmdOptions::GetInstance();
00763 
00764     AnnotationTableLocator loc1 = GetAnnotationTableLocator(options, true);
00765     AnnotationTable* tab1 = AnnotationTableRepository().Get(loc1);
00766     if (tab1 == 0)
00767         return;
00768     AnnotationTableLocator loc2 = GetAnnotationTableLocator(options, false);
00769     AnnotationTable* tab2 = AnnotationTableRepository().Get(loc2);
00770     tab1->Diff(tab2);
00771     delete tab2;
00772     delete tab1;
00773 }
00774 
00775 void
00776 DoCopyAnnotationTable()
00777 {
00778     ILOG_VAR(Impala.Application.Repository.DoCopyAnnotationTable);
00779     CmdOptions& options = CmdOptions::GetInstance();
00780 
00781     AnnotationTableLocator loc1 = GetAnnotationTableLocator(options, true);
00782     AnnotationTable* tab = AnnotationTableRepository().Get(loc1);
00783     if (tab == 0)
00784         return;
00785     AnnotationTableLocator loc2 = GetAnnotationTableLocator(options, false);
00786     AnnotationTableRepository().Add(loc2, tab);
00787     delete tab;
00788 }
00789 
00790 // AnnotationTableSet part
00791 
00792 AnnotationTableSetLocator
00793 GetAnnotationTableSetLocator(CmdOptions& options, bool getSrcLoc)
00794 {
00795     ILOG_VAR(Impala.Application.Repository.GetAnnotationTableSetLocator);
00796 
00797     int nrArg = 5;
00798     if (!getSrcLoc)
00799         nrArg++;
00800     if (options.GetNrArg() < nrArg)
00801     {
00802         ILOG_ERROR("Need at least " << nrArg << " parameters");
00803     }
00804 
00805     int a = 1;
00806     String locString = options.GetArg(a++);
00807     String setName = options.GetArg(a++);
00808     int quidClass = StringToQuidClass(options.GetArg(a++));
00809     String conceptSet = options.GetArg(a++);
00810     if (!getSrcLoc)
00811         locString = options.GetArg(a++);
00812     return AnnotationTableSetLocator(locString, setName, quidClass, conceptSet);
00813 }
00814 
00815 void
00816 DoDumpAnnotationTableSet()
00817 {
00818     ILOG_VAR(Impala.Application.Repository.DoDumpAnnotationTableSet);
00819     CmdOptions& options = CmdOptions::GetInstance();
00820 
00821     int a = 5;
00822     bool dumpTable = atol(options.GetArg(a++));
00823     int maxV = -1;
00824     if (options.GetNrArg() > a)
00825         maxV = atol(options.GetArg(a++));
00826     int maxP = -1;
00827     if (options.GetNrArg() > a)
00828         maxP = atol(options.GetArg(a++));
00829     int maxN = -1;
00830     if (options.GetNrArg() > a)
00831         maxN = atol(options.GetArg(a++));
00832 
00833     AnnotationTableSetLocator loc = GetAnnotationTableSetLocator(options, true);
00834     AnnotationTableSet* tSet = AnnotationTableSetRepository().Get(loc);
00835     if (tSet == 0)
00836         return;
00837     RawDataSet* dataSet = GetRawDataSet(options, false);
00838 
00839     for (int i=0 ; i<tSet->Size() ; i++)
00840     {
00841         AnnotationTable* tab = tSet->GetTable(i);
00842         tab->DumpSummary();
00843         tab->DumpSummaryObject();
00844         if (dumpTable)
00845             tab->Dump(dataSet, options.GetInt("start"), options.GetInt("end"));
00846         if (maxV != -1)
00847         {
00848             tab->SelectQuidObjectMaxId(maxV);
00849             tab->SetLabel(tab->GetLabel() + "_maxV_" + MakeString(maxV));
00850             tab->DumpSummary();
00851             tab->DumpSummaryObject();
00852         }
00853         if (maxP != -1)
00854         {
00855             tab->SelectQuidObjectMaxPositive(maxP);
00856             tab->SetLabel(tab->GetLabel() + "_maxP_" + MakeString(maxP));
00857             tab->DumpSummary();
00858             tab->DumpSummaryObject();
00859         }
00860         if (maxN != -1)
00861         {
00862             tab->SelectQuidObjectMaxNegative(maxN);
00863             tab->SetLabel(tab->GetLabel() + "_maxN_" + MakeString(maxN));
00864             tab->DumpSummary();
00865             tab->DumpSummaryObject();
00866         }
00867     }
00868 
00869     delete tSet;
00870     if (dataSet)
00871         delete dataSet;
00872 }
00873 
00874 void
00875 DoDiffAnnotationTableSet()
00876 {
00877     ILOG_VAR(Impala.Application.Repository.DoDiffAnnotationTableSet);
00878     CmdOptions& options = CmdOptions::GetInstance();
00879 
00880     AnnotationTableSetLocator loc1 = GetAnnotationTableSetLocator(options, true);
00881     AnnotationTableSet* tSet1 = AnnotationTableSetRepository().Get(loc1);
00882     if (tSet1 == 0)
00883         return;
00884     AnnotationTableSetLocator loc2 = GetAnnotationTableSetLocator(options, false);
00885     AnnotationTableSet* tSet2 = AnnotationTableSetRepository().Get(loc2);
00886     tSet1->Diff(tSet2);
00887     delete tSet2;
00888     delete tSet1;
00889 }
00890 
00891 void
00892 DoCopyAnnotationTableSet()
00893 {
00894     ILOG_VAR(Impala.Application.Repository.DoCopyAnnotationTableSet);
00895     CmdOptions& options = CmdOptions::GetInstance();
00896 
00897     AnnotationTableSetLocator loc1 = GetAnnotationTableSetLocator(options, true);
00898     AnnotationTableSet* tSet = AnnotationTableSetRepository().Get(loc1);
00899     if (tSet == 0)
00900         return;
00901     AnnotationTableSetLocator loc2 = GetAnnotationTableSetLocator(options, false);
00902     AnnotationTableSetRepository().Add(loc2, tSet);
00903     delete tSet;
00904 }
00905 
00906 // SimilarityTableSet part
00907 
00908 SimilarityTableSetLocator
00909 GetSimilarityTableSetLocator(CmdOptions& options, bool getSrcLoc)
00910 {
00911     ILOG_VAR(Impala.Application.Repository.GetSimilarityTableSetLocator);
00912 
00913     int nrArg = 9;
00914     if (!getSrcLoc)
00915         nrArg++;
00916     if (options.GetNrArg() < nrArg)
00917     {
00918         ILOG_ERROR("Need at least " << nrArg << " parameters");
00919     }
00920 
00921     int a = 1;
00922     String locString = options.GetArg(a++);
00923     String setName = options.GetArg(a++);
00924     bool inIndex = StringToBool(options.GetArg(a++));
00925     String walkType = options.GetArg(a++);
00926     String conceptSet = options.GetArg(a++);
00927     String model = options.GetArg(a++);
00928     String feature = options.GetArg(a++);
00929     String container = options.GetArg(a++);
00930     if (!getSrcLoc)
00931         locString = options.GetArg(a++);
00932     return SimilarityTableSetLocator(locString, setName, inIndex, walkType,
00933                                      conceptSet, model, feature, container);
00934 }
00935 
00936 void
00937 DoDumpSimilarityTableSet()
00938 {
00939     ILOG_VAR(Impala.Application.Repository.DoDumpSimilarityTableSet);
00940     CmdOptions& options = CmdOptions::GetInstance();
00941 
00942     SimilarityTableSetLocator loc = GetSimilarityTableSetLocator(options, true);
00943     VideoSet* vidSet = GetVideoSet(options, true);
00944     String container = loc.GetContainer();
00945     int nrFiles = (container == "ALL") ? vidSet->NrFiles() : 1;
00946     for (int i=0 ; i<nrFiles ; i++)
00947     {
00948         String cur = (container == "ALL") ? vidSet->GetFile(i) : container;
00949         loc.SetContainer(cur);
00950         SimilarityTableSet* simSet = SimilarityTableSetRepository().Get(loc);
00951         simSet->DumpRanking(0, options.GetInt("start"), options.GetInt("end"));
00952         delete simSet;
00953     }
00954 }
00955 
00956 void
00957 DoDiffSimilarityTableSet()
00958 {
00959     ILOG_VAR(Impala.Application.Repository.DoDiffSimilarityTableSet);
00960     CmdOptions& options = CmdOptions::GetInstance();
00961 
00962     SimilarityTableSetLocator loc1 = GetSimilarityTableSetLocator(options, true);
00963     SimilarityTableSetLocator loc2 = GetSimilarityTableSetLocator(options, false);
00964     VideoSet* vidSet = GetVideoSet(options, true);
00965     String container = loc1.GetContainer();
00966     int nrFiles = (container == "ALL") ? vidSet->NrFiles() : 1;
00967     for (int i=0 ; i<nrFiles ; i++)
00968     {
00969         String cur = (container == "ALL") ? vidSet->GetFile(i) : container;
00970         loc1.SetContainer(cur);
00971         SimilarityTableSet* simSet1 = SimilarityTableSetRepository().Get(loc1);
00972 
00973         loc2.SetContainer(cur);
00974         SimilarityTableSet* simSet2 = SimilarityTableSetRepository().Get(loc2);
00975         simSet1->Diff(simSet2);
00976         delete simSet2;
00977         delete simSet1;
00978     }
00979 }
00980 
00981 void
00982 DoCopySimilarityTableSet()
00983 {
00984     ILOG_VAR(Impala.Application.Repository.DoCopySimilarityTableSet);
00985     CmdOptions& options = CmdOptions::GetInstance();
00986 
00987     SimilarityTableSetLocator loc1 = GetSimilarityTableSetLocator(options, true);
00988     SimilarityTableSetLocator loc2 = GetSimilarityTableSetLocator(options, false);
00989     VideoSet* vidSet = GetVideoSet(options, true);
00990     String container = loc1.GetContainer();
00991     int nrFiles = (container == "ALL") ? vidSet->NrFiles() : 1;
00992     for (int i=0 ; i<nrFiles ; i++)
00993     {
00994         String cur = (container == "ALL") ? vidSet->GetFile(i) : container;
00995         loc1.SetContainer(cur);
00996         SimilarityTableSet* simSet = SimilarityTableSetRepository().Get(loc1);
00997 
00998         loc2.SetContainer(cur);
00999         SimilarityTableSetRepository().Add(loc2, simSet);
01000         delete simSet;
01001     }
01002 }
01003 
01004 int
01005 mainRepository(int argc, char* argv[])
01006 {
01007     CmdOptions& options = CmdOptions::GetInstance();
01008     options.Initialise(false, false, true);
01009     options.AddOption(0, "start", "nr", "0");
01010     options.AddOption(0, "end", "nr", "-1");
01011     String usageStr = "cmd = \n\n";
01012     usageStr += "  dumpimagesets\n";
01013     usageStr += "  dumpvideosets\n";
01014     usageStr += "  copyvideosets dstLocation\n";
01015     usageStr += "  dumpimageset location imageset.txt\n";
01016     usageStr += "  diffimageset location1 imageset.txt location2\n";
01017     usageStr += "  copyimageset location1 imageset.txt location2\n";
01018     usageStr += "  dumpvideoset location videoset.txt\n";
01019     usageStr += "  diffvideoset location1 videoset.txt location2\n";
01020     usageStr += "  copyvideoset location1 videoset.txt location2\n";
01021     usageStr += "  dumpsegmentation location videoset.txt\n";
01022     usageStr += "  diffsegmentation location1 videoset.txt location2\n";
01023     usageStr += "  copysegmentation location1 videoset.txt location2\n";
01024     usageStr += "  dumpkeyframes location videoset.txt\n";
01025     usageStr += "  diffkeyframes location1 videoset.txt location2\n";
01026     usageStr += "  copykeyframes location1 videoset.txt location2\n";
01027     usageStr += "  dumpstills location videoset.txt\n";
01028     usageStr += "  dumpimagearchive location dataset.txt isFrames container name.raw\n";
01029     usageStr += "  diffimagearchive location1 dataset.txt isFrames container name.raw location2\n";
01030     usageStr += "  copyimagearchive location1 dataset.txt isFrames container name.raw location2\n";
01031     usageStr += "  dumpfeaturetable location dataset.txt isCodebook isIndex walkType feature container\n";
01032     usageStr += "  difffeaturetable location1 dataset.txt isCodebook isIndex walkType feature container location2\n";
01033     usageStr += "  copyfeaturetable location1 dataset.txt isCodebook isIndex walkType feature container location2\n";
01034     usageStr += "  dumpkeywordlist location videoset.txt concepts.txt\n";
01035     usageStr += "  diffkeywordlist location1 videoset.txt concepts.txt location2\n";
01036     usageStr += "  copykeywordlist location1 videoset.txt concepts.txt location2\n";
01037     usageStr += "  dumpannotationtable location dataset.txt quidClass concepts.txt keyword\n";
01038     usageStr += "  diffannotationtable location1 dataset.txt quidClass concepts.txt keyword location2\n";
01039     usageStr += "  copyannotationtable location1 dataset.txt quidClass concepts.txt keyword location2\n";
01040     usageStr += "  dumpannotationtableset location dataset.txt quidClass concepts.txt doTable [maxVidId maxPos maxNeg]\n";
01041     usageStr += "  diffannotationtableset location1 dataset.txt quidClass concepts.txt location2\n";
01042     usageStr += "  copyannotationtableset location1 dataset.txt quidClass concepts.txt location2\n";
01043     usageStr += "  dumpsimilaritytableset location dataset.txt isIndex walkType conceptSet.txt model feature container\n";
01044     usageStr += "  diffsimilaritytableset location1 dataset.txt isIndex walkType conceptSet.txt model feature container location2\n";
01045     usageStr += "  copysimilaritytableset location1 dataset.txt isIndex walkType conceptSet.txt model feature container location2\n";
01046     if (! options.ParseArgs(argc, argv, usageStr, 1))
01047         return 1;
01048 
01049     ILOG_VAR(Impala.Application.Repository.mainRepository);
01050 
01051     String cmd = options.GetArg(0);
01052     ILOG_DEBUG("cmd = " << cmd);
01053     if (cmd == "dumpimagesets")
01054         DoDumpImageSets();
01055     else if (cmd == "dumpvideosets")
01056         DoDumpVideoSets();
01057     else if (cmd == "copyvideosets")
01058         DoCopyVideoSets();
01059     else if (cmd == "dumpimageset")
01060         DoDumpImageSet();
01061     else if (cmd == "diffimageset")
01062         DoDiffImageSet();
01063     else if (cmd == "copyimageset")
01064         DoCopyImageSet();
01065     else if (cmd == "dumpvideoset")
01066         DoDumpVideoSet();
01067     else if (cmd == "diffvideoset")
01068         DoDiffVideoSet();
01069     else if (cmd == "copyvideoset")
01070         DoCopyVideoSet();
01071     else if (cmd == "dumpsegmentation")
01072         DoDumpSegmentation();
01073     else if (cmd == "diffsegmentation")
01074         DoDiffSegmentation();
01075     else if (cmd == "copysegmentation")
01076         DoCopySegmentation();
01077     else if (cmd == "dumpkeyframes")
01078         DoDumpKeyframes();
01079     else if (cmd == "diffkeyframes")
01080         DoDiffKeyframes();
01081     else if (cmd == "copykeyframes")
01082         DoCopyKeyframes();
01083     else if (cmd == "dumpimagearchive")
01084         DoDumpImageArchive();
01085     else if (cmd == "diffimagearchive")
01086         DoDiffImageArchive();
01087     else if (cmd == "copyimagearchive")
01088         DoCopyImageArchive();
01089     else if (cmd == "dumpfeaturetable")
01090         DoDumpFeatureTable();
01091     else if (cmd == "difffeaturetable")
01092         DoDiffFeatureTable();
01093     else if (cmd == "copyfeaturetable")
01094         DoCopyFeatureTable();
01095     else if (cmd == "dumpkeywordlist")
01096         DoDumpKeywordList();
01097     else if (cmd == "diffkeywordlist")
01098         DoDiffKeywordList();
01099     else if (cmd == "copykeywordlist")
01100         DoCopyKeywordList();
01101     else if (cmd == "dumpannotationtable")
01102         DoDumpAnnotationTable();
01103     else if (cmd == "diffannotationtable")
01104         DoDiffAnnotationTable();
01105     else if (cmd == "copyannotationtable")
01106         DoCopyAnnotationTable();
01107     else if (cmd == "dumpannotationtableset")
01108         DoDumpAnnotationTableSet();
01109     else if (cmd == "diffannotationtableset")
01110         DoDiffAnnotationTableSet();
01111     else if (cmd == "copyannotationtableset")
01112         DoCopyAnnotationTableSet();
01113     else if (cmd == "dumpsimilaritytableset")
01114         DoDumpSimilarityTableSet();
01115     else if (cmd == "diffsimilaritytableset")
01116         DoDiffSimilarityTableSet();
01117     else if (cmd == "copysimilaritytableset")
01118         DoCopySimilarityTableSet();
01119     else ILOG_ERROR("Unknown cmd : " << cmd);
01120 
01121     return 0;
01122 }
01123 
01124 } // namespace Repository
01125 } // namespace Application
01126 } // namespace Impala
01127 
01128 int
01129 main(int argc, char* argv[])
01130 {
01131     return Impala::Application::Repository::mainRepository(argc, argv);
01132 }

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