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