00001 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00002 #else // REPOSITORY_USED
00003 #define REPOSITORY_TODO
00004 #endif // REPOSITORY_USED
00005
00006 #include "Basis/FileName.h"
00007 #include "Core/Table/Sort.h"
00008 #include "Core/VideoSet/SelectFrames.h"
00009 #include "Core/VideoSet/ClusterFeatures.h"
00010 #include "Core/VideoSet/ExportFeatures.h"
00011 #ifndef REPOSITORY_TODO
00012 #include "Core/VideoSet/ImportAudioConcepts.h"
00013 #endif
00014 #include "Core/VideoSet/IndexAnnotation.h"
00015 #ifndef REPOSITORY_TODO
00016 #include "Core/VideoSet/CombineConcepts.h"
00017 #endif
00018 #include "Core/VideoSet/TaskTable.h"
00019 #ifndef REPOSITORY_TODO
00020 #include "Core/VideoSet/ExportConcepts.h"
00021 #include "Core/VideoSet/IndexConcepts.h"
00022 #include "Core/VideoSet/ImportConcepts.h"
00023 #include "Core/VideoSet/ApplyConcepts.h"
00024 #endif
00025 #include "Core/VideoSet/ConcatFeatures.h"
00026 #include "Link/Mpi/MpiFuncs.h"
00027 #ifndef REPOSITORY_TODO
00028 #include "Core/VideoSet/TestVideo.h"
00029 #include "Core/VideoSet/CheckNrFrames.h"
00030 #endif
00031 #include "Core/VideoSet/IndexSegmentation.h"
00032 #ifndef REPOSITORY_TODO
00033 #include "Core/VideoSet/ReadBlocksFile.h"
00034 #endif
00035 #include "Core/VideoSet/ProtoSimilarityEval.h"
00036 #include "Core/Feature/VisSem.h"
00037 #include "Core/VideoSet/ShotSegmenter.h"
00038 #include "Core/VideoSet/IndexFeatures.h"
00039 #include "Core/VideoSet/ExportKeyframes.h"
00040 #include "Core/VideoSet/ExportStills.h"
00041 #ifndef REPOSITORY_TODO
00042 #include "Core/VideoSet/TestBlocksFile.h"
00043 #include "Core/VideoSet/VisSemGaborStat.h"
00044 #include "Core/VideoSet/LabHistExtractor.h"
00045 #include "Core/VideoSet/LabHist3dExtractor.h"
00046 #include "Core/VideoSet/RgbHistExtractor.h"
00047 #endif
00048 #include "Core/VideoSet/ExportFrames.h"
00049 #include "Core/VideoSet/VisSemTrain.h"
00050 #include "Core/VideoSet/Reporter.h"
00051 #include "Core/VideoSet/Walker.h"
00052 #include "Core/VideoSet/MakeVideoSet.h"
00053 #include "Core/Array/MakeGaussian1d.h"
00054 #ifndef REPOSITORY_TODO
00055 #include "Core/VideoSet/ComputeKernelData.h"
00056 #include "Core/VideoSet/InterestPointProc.h"
00057 #include "Core/VideoSet/BlackFrameProc.h"
00058 #include "Core/VideoSet/MakeQuidLookup.h"
00059 #include "Link/DiskImage/DiskImageFuncs.h"
00060 #include "Core/VideoSet/LbpEval.h"
00061 #include "Core/VideoSet/VideoIndexValidator.h"
00062 #include "Core/VideoSet/BlackFrameDetect.h"
00063 #include "Core/VideoSet/KfrMotionExtractor.h"
00064 #endif
00065 #include "Persistency/TaskTableRepository.h"
00066
00067
00068 #include "Link/ImpalaLib.cpp"
00069 #include "Link/Svm/LinkSvm.cpp"
00070
00071 namespace Impala
00072 {
00073 namespace Application
00074 {
00075 namespace VidSet
00076 {
00077
00078 using namespace Impala::Core::Array;
00079 using namespace Impala::Core::Feature;
00080 using namespace Impala::Core::VideoSet;
00081
00082
00083 TaskTable*
00084 MakeVideoTaskTableByQuids(VideoSet* videoSet, Walker* walker)
00085 {
00086 ILOG_VAR(Impala.Application.VidSet.MakeVideoTaskTableByQuids);
00087 CmdOptions& options = CmdOptions::GetInstance();
00088 int startFile = options.GetInt("startFile");
00089 int numberFiles = options.GetInt("numberFiles");
00090 if (numberFiles == -1)
00091 numberFiles = videoSet->NrFiles();
00092 if (startFile + numberFiles >= videoSet->NrFiles())
00093 numberFiles = videoSet->NrFiles() - startFile;
00094 TaskTable* taskTable = new TaskTable();
00095 Core::Table::QuidTable* quids = walker->GetQuids();
00096 for (int i=startFile ; i<startFile+numberFiles ; i++)
00097 taskTable->Add(i, 1, quids->GetNrQuidsObject(i));
00098 Core::Table::Sort(taskTable, 3, false);
00099 for (int i=0 ; i<taskTable->Size() ; i++)
00100 taskTable->Set3(i, 0);
00101 return taskTable;
00102 }
00103
00104 TaskTable*
00105 MakeVideoTaskTableByVideoSize(VideoSet* videoSet, Walker* walker)
00106 {
00107 ILOG_VAR(Impala.Application.VidSet.MakeVideoTaskTableByVideoSize);
00108 CmdOptions& options = CmdOptions::GetInstance();
00109 int startFile = options.GetInt("startFile");
00110 int numberFiles = options.GetInt("numberFiles");
00111 Segmentation* segmentation = walker->GetSegmentation();
00112 if (segmentation == 0)
00113 {
00114 ILOG_ERROR("Need segmentation");
00115 return 0;
00116 }
00117 if (numberFiles == -1)
00118 numberFiles = videoSet->NrFiles();
00119 if (startFile + numberFiles >= videoSet->NrFiles())
00120 numberFiles = videoSet->NrFiles() - startFile;
00121 TaskTable* taskTable = new TaskTable();
00122 for (int i=startFile ; i<startFile+numberFiles ; i++)
00123 taskTable->Add(i, 1, segmentation->GetNrFramesVideo(i));
00124 Core::Table::Sort(taskTable, 3, false);
00125 for (int i=0 ; i<taskTable->Size() ; i++)
00126 taskTable->Set3(i, 0);
00127 return taskTable;
00128 }
00129
00130 TaskTable*
00131 MakeVideoTaskTableByFrames(VideoSet* videoSet, Walker* walker)
00132 {
00133 ILOG_VAR(Impala.Application.VidSet.MakeVideoTaskTableByFrames);
00134 CmdOptions& options = CmdOptions::GetInstance();
00135 int startFile = options.GetInt("startFile");
00136 int numberFiles = options.GetInt("numberFiles");
00137 int stepSize = options.GetInt("stepSize");
00138 int numberFrames = options.GetInt("numberFrames");
00139 Segmentation* segmentation = walker->GetSegmentation();
00140 if (segmentation == 0)
00141 {
00142 ILOG_ERROR("Need segmentation");
00143 return 0;
00144 }
00145 if (numberFiles == -1)
00146 numberFiles = videoSet->NrFiles();
00147 if (startFile + numberFiles >= videoSet->NrFiles())
00148 numberFiles = videoSet->NrFiles() - startFile;
00149 int curFile = startFile;
00150 int curFrame = 0;
00151 TaskTable* taskTable = new TaskTable();
00152 while (numberFiles > 0)
00153 {
00154 taskTable->Add(curFile, 1, curFrame);
00155 curFrame += numberFrames * stepSize;
00156 if (curFrame > segmentation->GetNrFramesVideo(curFile))
00157 {
00158 curFrame = 0;
00159 curFile++;
00160 numberFiles--;
00161 }
00162 }
00163 return taskTable;
00164 }
00165
00166 TaskTable*
00167 MakeVideoTaskTableByVideo(VideoSet* videoSet, Walker* walker)
00168 {
00169 CmdOptions& options = CmdOptions::GetInstance();
00170 int startFile = options.GetInt("startFile");
00171 int numberFiles = options.GetInt("numberFiles");
00172 int startFrame = options.GetInt("startFrame");
00173 int numProcs = Link::Mpi::NrProcs();
00174 if (numberFiles == -1)
00175 numberFiles = videoSet->NrFiles();
00176 if (startFile + numberFiles >= videoSet->NrFiles())
00177 numberFiles = videoSet->NrFiles() - startFile;
00178 int lastFile = startFile + numberFiles;
00179 int taskSize = numberFiles / numProcs;
00180 int restSize = numberFiles % numProcs;
00181 int curFile = startFile;
00182 TaskTable* taskTable = new TaskTable();
00183 for (int i=0 ; i<numProcs ; i++)
00184 {
00185 startFile = curFile;
00186 numberFiles = taskSize;
00187 if (--restSize >= 0)
00188 numberFiles++;
00189 if (startFile + numberFiles > lastFile)
00190 numberFiles = lastFile - startFile;
00191 curFile += numberFiles;
00192 taskTable->Add(startFile, numberFiles, startFrame);
00193 }
00194 return taskTable;
00195 }
00196
00197 TaskTable*
00198 MakeVideoTaskTable(VideoSet* videoSet, Walker* walker, String cmd, String quidFile)
00199 {
00200 CmdOptions& options = CmdOptions::GetInstance();
00201 int startTask = options.GetInt("startTask");
00202 if ((cmd == "tasktable") || (startTask != -1))
00203 {
00204 if (!quidFile.empty())
00205 return MakeVideoTaskTableByQuids(videoSet, walker);
00206 if (options.GetBool("taskByVideoSize"))
00207 return MakeVideoTaskTableByVideoSize(videoSet, walker);
00208 return MakeVideoTaskTableByFrames(videoSet, walker);
00209 }
00210 return MakeVideoTaskTableByVideo(videoSet, walker);
00211 }
00212
00213 int
00214 GetVideoTask()
00215 {
00216 CmdOptions& options = CmdOptions::GetInstance();
00217 int startTask = options.GetInt("startTask");
00218 if (startTask == -1)
00219 startTask = 0;
00220 return startTask + Link::Mpi::MyId();
00221 }
00222
00223 int
00224 mainVidSet(int argc, char* argv[])
00225 {
00226 Link::Mpi::Init(&argc, &argv);
00227
00228 CmdOptions& options = CmdOptions::GetInstance();
00229 options.Initialise(true, false, true);
00230 options.AddOption(0, "report", "perNr", "0");
00231 options.AddOption(0, "startFile", "idx", "0");
00232 options.AddOption(0, "numberFiles", "nr", "-1");
00233 options.AddOption(0, "segmentation", "", "0");
00234 options.AddOption(0, "keyframes", "", "0");
00235 options.AddOption(0, "rkfMask", "", "0");
00236 options.AddOption(0, "keyframeMask", "file", "");
00237 options.AddOption(0, "keyframeMaskAnno", "file", "");
00238 options.AddOption(0, "quidWalk", "file", "");
00239 options.AddOption(0, "startTask", "idx", "-1");
00240 options.AddOption(0, "nrTaskWalk", "nr", "1");
00241 options.AddOption(0, "taskByVideoSize", "", "0");
00242 options.AddOption(0, "maskFile", "file", "");
00243 options.AddOption(0, "precomputed", "[only works for applyconcepts] boolean: if 1 modelfiles must be for precomputed kernel", "0");
00244 options.AddOption(0, "storeKernelData", "[only works for applyconcepts] boolean: if 1 kernel data will be written to disk", "0");
00245 options.AddOption(0, "noFeatureCache", "", "0");
00246 options.AddOption(0, "msf-feature", "bool [for lbpeval]", "0");
00247
00248 WalkerConfig walkerConfig;
00249 walkerConfig.InitOptions(options);
00250
00251
00252 #ifndef REPOSITORY_TODO
00253 Impala::Core::VideoSet::InterestPointProc::AddCmdOptions();
00254 #endif
00255
00256
00257 options.AddOption(0, "SSGUI", "", "0");
00258 options.AddOption(0, "SSProbThresh", "value", "0.5");
00259
00260 if (! options.ParseArgs(argc, argv, "cmd videoSet|vxs|dbsection/file", 2))
00261 {
00262 Link::Mpi::Finalize();
00263 return 1;
00264 }
00265
00266 ILOG_VAR(Impala.Application.VidSet.mainVidSet);
00267
00268 ILOG_INFO("Disk images are " <<
00269 (Link::DiskImage::DiskImageUsed() ? "" : "not ") << "supported");
00270
00271 String cmd = options.GetArg(0);
00272 String fileName = options.GetArg(1);
00273
00274 VideoSet* videoSet = MakeVideoSet(fileName);
00275
00276 walkerConfig.RetrieveOptions(options);
00277 Walker walker(videoSet, walkerConfig);
00278 Reporter* reporter = new Reporter(0);
00279 walker.AddListener(reporter);
00280
00281 ILOG_INFO("vidset command : " << cmd);
00282
00283 #ifndef REPOSITORY_TODO
00284 if (cmd == "computekerneldata")
00285 walker.AddListener(new ComputeKernelData(reporter, options));
00286 if (cmd == "testvideo")
00287 walker.AddListener(new TestVideo(reporter, options));
00288 if (cmd == "validatevideoindex")
00289 walker.AddListener(new VideoIndexValidator(reporter, options));
00290 if (cmd == "checknrframes")
00291 walker.AddListener(new CheckNrFrames(reporter, options));
00292 if (cmd == "readblocksfile")
00293 walker.AddListener(new ReadBlocksFile(reporter, options));
00294 #endif
00295 if (cmd == "shotsegmenter")
00296 walker.AddListener(new ShotSegmenter(reporter, options));
00297 if (cmd == "selectframes")
00298 walker.AddListener(new SelectFrames(reporter, options));
00299 if (cmd == "indexsegmentation")
00300 walker.AddListener(new IndexSegmentation(reporter, options));
00301 #ifndef REPOSITORY_TODO
00302 if (cmd == "testblocksfile")
00303 walker.AddListener(new TestBlocksFile(reporter));
00304 #endif
00305 if (cmd == "indexannotation")
00306 walker.AddListener(new IndexAnnotation(reporter, options));
00307 #ifndef REPOSITORY_TODO
00308 if (cmd == "applyconcepts")
00309 walker.AddListener(new ApplyConcepts(reporter, options, videoSet));
00310 if (cmd == "combineconcepts")
00311 walker.AddListener(new CombineConcepts(reporter, options));
00312 if (cmd == "indexconcepts")
00313 walker.AddListener(new IndexConcepts(reporter, options));
00314 if (cmd == "exportconcepts")
00315 walker.AddListener(new ExportConcepts(reporter, options));
00316 if (cmd == "importconcepts")
00317 walker.AddListener(new ImportConcepts(reporter, options));
00318 if (cmd == "importaudioconcepts")
00319 walker.AddListener(new ImportAudioConcepts(reporter, options));
00320 #endif
00321
00322 if (cmd == "exportframes")
00323 walker.AddListener(new ExportFrames(reporter, options));
00324 if (cmd == "exportkeyframes")
00325 walker.AddListener(new ExportKeyframes(reporter, options, videoSet));
00326 if (cmd == "exportstills")
00327 walker.AddListener(new ExportStills(reporter, options));
00328
00329 if (cmd == "vistrain")
00330 walker.AddListener(new VisSemTrain(reporter, "vissem", options));
00331 if (cmd == "visgabortrain")
00332 walker.AddListener(new VisSemTrain(reporter, "vissemgabor", options));
00333
00334 if (cmd == "viseval")
00335 {
00336 Computor* c = new VisSem("vissem", options);
00337 walker.AddListener(new ProtoSimilarityEval(c, reporter, options));
00338 }
00339 if (cmd == "visgaboreval")
00340 {
00341 Computor* c = new VisSem("vissemgabor", options);
00342 walker.AddListener(new ProtoSimilarityEval(c, reporter, options));
00343 }
00344 #ifndef REPOSITORY_TODO
00345 if (cmd == "lbpeval")
00346 walker.AddListener(new LbpEval(reporter, options));
00347
00348 if (cmd == "visgaborstat")
00349 walker.AddListener(new VisSemGaborStat(reporter, options));
00350 #endif
00351
00352 if (cmd == "clusterfeatures")
00353 {
00354 if (options.GetNrArg() < 4)
00355 ILOG_ERROR("cluster: missing argument");
00356 String feature = options.GetArg(2);
00357 Computor* c = 0;
00358 if (feature == "weibull")
00359 c = new VisSem("vissem", options);
00360 if (feature == "gabor")
00361 c = new Core::Feature::VisSem("vissemgabor", options);
00362 String clusteror = options.GetArg(3);
00363 walker.AddListener(new ClusterFeatures(c, clusteror, reporter, options));
00364 }
00365
00366 #ifndef REPOSITORY_TODO
00367 if (cmd == "extractlab")
00368 walker.AddListener(new LabHistExtractor(reporter, options));
00369 if (cmd == "extractlab3d")
00370 walker.AddListener(new LabHist3dExtractor(reporter, options));
00371 if (cmd == "extractrgb")
00372 walker.AddListener(new RgbHistExtractor(reporter, options));
00373 #endif
00374
00375 if (cmd == "indexfeatures")
00376 walker.AddListener(new IndexFeatures(reporter, options));
00377 if (cmd == "concatfeatures")
00378 walker.AddListener(new ConcatFeatures(reporter, options));
00379 if (cmd == "exportfeatures")
00380 walker.AddListener(new ExportFeatures(reporter, options));
00381 #ifndef REPOSITORY_TODO
00382 if (cmd == "interestpointproc")
00383 walker.AddListener(new InterestPointProc(reporter, options));
00384 if (cmd == "blackframeproc")
00385 walker.AddListener(new BlackFrameProc(reporter, options));
00386 if (cmd == "makequidlookup")
00387 walker.AddListener(new MakeQuidLookup(reporter, options));
00388 if (cmd == "blackframedetect")
00389 walker.AddListener(new BlackFrameDetect(reporter, options));
00390 if (cmd == "extractkfrmotion")
00391 walker.AddListener(new KfrMotionExtractor(reporter, options));
00392 #endif
00393
00394 if ((walker.NrListeners() == 1) && !((cmd == "nop") || (cmd == "tasktable")))
00395 {
00396 ILOG_ERROR("Unknow command : " << cmd);
00397 Link::Mpi::Finalize();
00398 return 1;
00399 }
00400
00401 walker.AddListener(new Reporter(reporter));
00402 int rc = 0;
00403 if (FileNameExt(fileName) == "vxs")
00404 {
00405 walker.LoadBookmarks(fileName);
00406 reporter->SetTotalNrFramesInBookmarks(walker.TotalNrFramesInBookmarks());
00407 walker.DoWalkBookmarks();
00408 }
00409 else
00410 {
00411 if (options.GetBool("segmentation"))
00412 walker.LoadSegmentation("segmentation");
00413 String quidFile = options.GetString("quidWalk");
00414 if (!quidFile.empty())
00415 {
00416 #ifndef REPOSITORY_USED
00417 quidFile = videoSet->GetFilePath("", quidFile, false, false);
00418 #endif // REPOSITORY_USED
00419 if (!quidFile.empty())
00420 walker.LoadQuids(quidFile);
00421 }
00422
00423 TaskTable* taskTable = MakeVideoTaskTable(videoSet, &walker, cmd,
00424 quidFile);
00425 if ((Link::Mpi::MyId() == 0) && (cmd == "tasktable"))
00426 {
00427 taskTable->Dump();
00428 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00429 taskTable->Save("tasktable.tab", videoSet->GetDatabase(), false);
00430 #else // REPOSITORY_USED
00431 Persistency::TaskTableLocator loc(videoSet->GetLocator(),
00432 "tasktable.tab");
00433 Persistency::TaskTableRepository().Add(loc, taskTable);
00434 #endif // REPOSITORY_USED
00435 }
00436 int taskIdx = GetVideoTask();
00437 int startFile = taskTable->GetStartFile(taskIdx);
00438 int numberFiles = taskTable->GetNumberFiles(taskIdx);
00439 int startFrame = taskTable->GetStartFrame(taskIdx);
00440 ILOG_INFO("Process " << Link::Mpi::MyId() << " of " <<
00441 Link::Mpi::NrProcs() << " is doing file " << startFile
00442 << " till " << startFile + numberFiles << " from frame "
00443 << startFrame);
00444 if (!quidFile.empty())
00445 {
00446
00447 int nrTaskWalk = options.GetInt("nrTaskWalk");
00448 int numProcs = Link::Mpi::NrProcs();
00449 for (int walk=0 ; walk<nrTaskWalk ; walk++)
00450 {
00451 int t = taskIdx + walk*numProcs;
00452 startFile = taskTable->GetStartFile(t);
00453 numberFiles = taskTable->GetNumberFiles(t);
00454 walker.DoWalkQuids(startFile, numberFiles);
00455 }
00456 }
00457 else if (options.GetBool("keyframes"))
00458 {
00459 walker.LoadKeyframes("keyframes");
00460 if (options.GetBool("rkfMask"))
00461 walker.AddRkfMask();
00462 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00463 if (options.GetString("keyframeMask") != "")
00464 walker.AddKeyframeMaskFile(options.GetString("keyframeMask"));
00465 #endif // REPOSITORY_USED
00466 if (options.GetString("keyframeMaskAnno") != "")
00467 walker.AddKeyframeMaskAnnoFile(options.GetString("keyframeMaskAnno"));
00468 walker.DoWalkKeyframes(startFile, numberFiles);
00469 }
00470 else
00471 {
00472
00473 int nrTaskWalk = options.GetInt("nrTaskWalk");
00474 int numProcs = Link::Mpi::NrProcs();
00475 for (int walk=0 ; walk<nrTaskWalk ; walk++)
00476 {
00477 int t = taskIdx + walk*numProcs;
00478 startFile = taskTable->GetStartFile(t);
00479 numberFiles = taskTable->GetNumberFiles(t);
00480 startFrame = taskTable->GetStartFrame(t);
00481 rc += walker.DoWalk(startFile, numberFiles, startFrame);
00482 }
00483 }
00484 delete taskTable;
00485 }
00486
00487 reporter->FinalReport();
00488
00489 int nrOfErrors = ILOG_ERROR_COUNT;
00490 ILOG_DEBUG("nr of errors collected = " << nrOfErrors);
00491
00492 nrOfErrors = Link::Mpi::ReduceSum(nrOfErrors);
00493 ILOG_INFO_ONCE("Root: total nr error = " << nrOfErrors);
00494 Link::Mpi::Finalize();
00495
00496 return nrOfErrors;
00497 }
00498
00499 }
00500 }
00501 }
00502
00503 int
00504 main(int argc, char* argv[])
00505 {
00506
00507 #ifdef NO_DIALOGONCRASH
00508 #ifdef WIN32
00509 DWORD oldMode = ::SetErrorMode(SEM_NOGPFAULTERRORBOX);
00510 ::SetErrorMode(oldMode | SEM_NOGPFAULTERRORBOX);
00511 #endif
00512 #endif
00513
00514 return Impala::Application::VidSet::mainVidSet(argc, argv);
00515 }