00001 #ifdef MPI_USED
00002 #include "mpi.h"
00003 #endif
00004
00005 #include "Core/VideoSet/ShotSegmenter.h"
00006 #ifndef MPI_USED
00007 #include "Visualization/ShotSegmenterGUI.h"
00008 #include "OglGui/OglLib.cpp"
00009 #endif
00010 #include "Core/VideoSet/Reporter.h"
00011 #include "Core/VideoSet/Walker.h"
00012 #include "Core/VideoSet/MakeVideoSet.h"
00013
00014 #include "Link/ImpalaLib.cpp"
00015 #include "Basis/ILog.h"
00016
00017 namespace Impala
00018 {
00019 namespace Application
00020 {
00021
00022
00023 using namespace Impala::Core::Array;
00024 using namespace Impala::Core::VideoSet;
00025
00026 int
00027 mainShotSegmentation(int argc, char* argv[])
00028 {
00029 #ifdef MPI_USED
00030 int numProcs;
00031 int myId;
00032 MPI_Init(&argc, &argv);
00033 MPI_Comm_rank(MPI_COMM_WORLD, &myId);
00034 MPI_Comm_size(MPI_COMM_WORLD, &numProcs);
00035 #else
00036 OglInit(&argc, &argv[0]);
00037 #endif
00038 ILOG_VAR(Impala.Application);
00039 ILOG_INFO("LOGGER STARTED!");
00040
00041 CmdOptions& options = CmdOptions::GetInstance();
00042 options.Initialise(true, false, true);
00043 options.AddOption(0, "report", "perNr", "0");
00044 options.AddOption(0, "startFile", "idx", "0");
00045 options.AddOption(0, "numberFiles", "nr", "-1");
00046
00047
00048 options.AddOption(0, "SSVerbose", "Verbosity", "0");
00049 options.AddOption(0, "SSThreshold", "Threshold for scores", "3.4");
00050 options.AddOption(0, "SSRadius","Radius of frames to consider", "6");
00051 options.AddOption(0, "SSSigma", "Decay coefficient for computation window", "18");
00052 options.AddOption(0, "SSBinCount", "Histogram bin count", "32");
00053 options.AddOption(0, "SSHistEq", "Histogram equalization before similarity", "0");
00054 options.AddOption(0, "SSHistNorm", "Histogram normalization before similarity", "1");
00055 options.AddOption(0, "SSNormW", "Normalize Weight Matrix", "0");
00056 options.AddOption(0, "SSCentered", "Center the frame of decision", "0");
00057 options.AddOption(0, "SSBlurSigma", "Sigma for Gaussian Blurring", "1.");
00058 options.AddOption(0, "SSBlur", "Blur the image before processing?", "1");
00059 options.AddOption(0, "SSBlurDer", "Nth derivative when blurring", "0");
00060 options.AddOption(0, "SSHistSim", "Histogram similarity method : Intersection or Kullback", "Intersection");
00061 options.AddOption(0, "SSSimType", "Similarity Method:[Hist|CM]","Hist");
00062 options.AddOption(0, "SSSim", "Similarity or Dissimilarity[+|-]","+");
00063 options.AddOption(0, "SSSymmetry", "Type of symmetry for prediction [None|Avg|And|Or] ","None");
00064 options.AddOption(0, "SSCMSim", "CM similarity method [Euc|Int|Sqrd]","Euc");
00065 options.AddOption(0, "SSPyrL", "Min level in the pyramid", "1");
00066 options.AddOption(0, "SSPyrU", "Max level in the pyramid", "2");
00067 options.AddOption(0, "SSProbThresh", "Threshold for prediction probabilities", "0.5");
00068 options.AddOption(0, "SSShortGrad", "Short Grads with N frames considered as CUT", "3");
00069 options.AddOption(0, "SSServer", "The server address to get fileIds from", "xurban.xs4all.nl");
00070 options.AddOption(0, "SSPort", "Port to connect", "9410");
00071 options.AddOption(0, "SSIsServer", "Current Node is in the server mode", "0");
00072 options.AddOption(0, "SSIsClient", "Current Node is in the client mode", "0");
00073
00074
00075 options.AddOption(0, "SSMode", "Mode for vidseg - Run, Train, Test, EvalTrain, EvalTest", "Run");
00076 options.AddOption(0, "SSGUI", "Display GUI", "yes");
00077 options.AddOption(0, "SSThresholdOnly", "Scores Exist, threshold the scores", "0");
00078 options.AddOption(0, "SSRunName", "Name of the Run", "NoRunName");
00079 options.AddOption(0, "SSRefDir",
00080 "Directory to retrieve the ground truth","");
00081 options.AddOption(0, "SSModelFile",
00082 "Svm Model file to use for prediction","");
00083 options.AddOption(0, "SSRefPrefix", "Prefix for Ground Truth XML files", "/ref_");
00084 WalkerConfig walkerConfig;
00085 walkerConfig.InitOptions(options);
00086
00087 std::string UsageStr = "[--ini IniFile | VideoFile ]";
00088 if (! options.ParseArgs(argc, argv,UsageStr, 0))
00089 {
00090
00091 #ifdef MPI_USED
00092 MPI_Finalize();
00093 #endif
00094 return 1;
00095 }
00096
00097
00098 #ifndef MPI_USED
00099 bool SSGUI = options.GetBool("SSGUI",true);
00100 if(SSGUI){
00101 std::string srcName = options.GetArg(0);
00102 RgbDataSrcFactory& factory = RgbDataSrcFactory::Instance();
00103 RgbDataSrc* src = factory.Construct(srcName, options.GetString("src"));
00104 if(!src->Valid()){
00105 options.ParseArgs(0, argv,UsageStr, 1);
00106 ILOG_ERROR("RgbDataSrc failed, you should supply a video file!");
00107 return 0;
00108 }
00109 ILOG_INFO("Creating GUI..");
00110 ShotSegmenterGUI* oglWnd = new ShotSegmenterGUI(0, 0, true, true, true, src);
00111 if (! oglWnd->Valid())
00112 {
00113 ILOG_ERROR("WindowVidseg failed");
00114 return 0;
00115 }
00116 ILOG_INFO("Destroying oglWnd");
00117 delete oglWnd;
00118 }else{
00119 #endif
00120
00121 std::string fileName = options.GetString("SSMode")+".txt";
00122 VideoSet* videoSet = MakeVideoSet(fileName);
00123 bool SSIsServer=options.GetBool("SSIsServer",false);
00124 walkerConfig.RetrieveOptions(options);
00125 Walker walker(videoSet, walkerConfig);
00126 Reporter* reporter = new Reporter(0);
00127 walker.AddListener(reporter);
00128 walker.AddListener(new ShotSegmenter(reporter, options));
00129 walker.AddListener(new Reporter(reporter));
00130 int startFile = options.GetInt("startFile");
00131 int numberFiles = options.GetInt("numberFiles");
00132 #ifdef MPI_USED
00133 if (numberFiles == -1)
00134 numberFiles = videoSet->NrFiles();
00135 if (startFile + numberFiles >= videoSet->NrFiles())
00136 numberFiles = videoSet->NrFiles() - startFile;
00137 int lastFile = startFile + numberFiles;
00138 int taskSize = numberFiles / numProcs;
00139 if (numberFiles % numProcs != 0)
00140 taskSize++;
00141 startFile = startFile + myId * taskSize;
00142 numberFiles = taskSize;
00143 if (myId == numProcs - 1)
00144 numberFiles = lastFile - startFile;
00145 std::cout << "Process " << myId << " of " << numProcs
00146 << " is doing dirs " << startFile << " till "
00147 << startFile + numberFiles << std::endl;
00148 #endif
00149 walker.DoWalk(startFile, numberFiles);
00150 reporter->FinalReport();
00151
00152 #ifdef MPI_USED
00153 MPI_Finalize();
00154 #else
00155 }
00156
00157 #endif
00158
00159 return 0;
00160 }
00161 }
00162 }
00163 int
00164 main(int argc, char* argv[])
00165 {
00166 return Impala::Application::mainShotSegmentation(argc, argv);
00167 }