00001 #include "Util/Channel.h"
00002 #include "Core/Database/MakeRawDataSet.h"
00003 #include "Core/VideoSet/TaskTable.h"
00004 #include "Core/Table/AnnotationTableSet.h"
00005 #include "Core/Vector/Norm1Dist.h"
00006 #include "Core/Vector/Similarity.h"
00007 #include "Core/Vector/VectorTem.h"
00008 #include "Core/Vector/SubAssign.h"
00009 #include "Core/Vector/DivAssign.h"
00010 #include "Core/Vector/Max.h"
00011 #include "Core/Vector/Min.h"
00012 #include "Core/Column/MakeFilter.h"
00013 #include "Core/Column/CopyUnique.h"
00014 #include "Core/Table/Select.h"
00015 #include "Core/Table/TableVxs.h"
00016 #include "Core/Table/Write.h"
00017 #include "Core/Table/Copy.h"
00018 #include "Core/Feature/FeatureTableSet.h"
00019 #include "Core/Feature/VisSem.h"
00020 #include "Core/Table/SimilarityTableSet.h"
00021 #include "Basis/CmdOptions.h"
00022 #include "Basis/FileExists.h"
00023 #include "Basis/FileName.h"
00024 #include "Core/VideoSet/MakeVideoSet.h"
00025 #include "Core/VideoSet/Keyframes.h"
00026 #include "Core/ImageSet/MakeImageSet.h"
00027 #include "Core/Array/Percentile.h"
00028 #include "Core/Array/Dilation.h"
00029 #include "Core/Array/Erosion.h"
00030 #include "Core/Array/Equals.h"
00031 #include "Core/Array/Mul.h"
00032 #include "Core/Matrix/MatSet.h"
00033
00034
00035
00036 #include "Link/ImpalaLib.cpp"
00037
00038 namespace Impala
00039 {
00040 namespace Application
00041 {
00042 namespace Table
00043 {
00044
00045 template <class ColElemT>
00046 void
00047 DoDump(String fName)
00048 {
00049 typedef Core::Column::ColumnTem<ColElemT> ColumnType;
00050 typedef Core::Table::TableTem<ColumnType> TableType;
00051
00052 CmdOptions& options = CmdOptions::GetInstance();
00053 Util::Database* db = &Util::Database::GetInstance();
00054 TableType table(0);
00055 Core::Table::Read(&table, fName, db);
00056 table.Dump(options.GetInt("start"), options.GetInt("end"));
00057 }
00058
00059 template <class ColElemT>
00060 void
00061 DoDiff(String fName1, String fName2)
00062 {
00063 typedef Core::Column::ColumnTem<ColElemT> ColumnType;
00064 typedef Core::Table::TableTem<ColumnType> TableType;
00065
00066 ILOG_VAR(Impala.Application.Table.DoDiff);
00067 CmdOptions& options = CmdOptions::GetInstance();
00068 Util::Database* db = &Util::Database::GetInstance();
00069 TableType table1(0);
00070 Core::Table::Read(&table1, fName1, db);
00071 TableType table2(0);
00072 Core::Table::Read(&table2, fName2, db);
00073 if (table1.Size() != table2.Size())
00074 {
00075 ILOG_INFO("Different table sizes: " << table1.Size() << " vs "
00076 << table2.Size());
00077 return;
00078 }
00079 int verb = options.GetInt("verb");
00080 int nDiff = 0;
00081 for (int i=0 ; i<table1.Size() ; i++)
00082 {
00083
00084 if ((table1.Get1(i) - table2.Get1(i)) > 0.00001)
00085 {
00086 nDiff++;
00087 if (verb)
00088 ILOG_INFO("diff elem " << i << ": " << table1.Get1(i)
00089 << " vs " << table2.Get1(i));
00090 }
00091 }
00092 if (nDiff > 0)
00093 ILOG_INFO("Found " << nDiff << " differences");
00094 }
00095
00096 void
00097 DoVxsTable()
00098 {
00099 ILOG_VAR(Impala.Application.Table.DoVxsTable);
00100 CmdOptions& options = CmdOptions::GetInstance();
00101 String fName = options.GetArg(1);
00102 Core::Table::TableVxs table;
00103 table.ReadVxsFile(fName);
00104
00105
00106 Core::Column::ColumnTem<String> concept(table.Size());
00107 int nr = Core::Column::CopyUnique(&concept, table.GetColumn3(), 0, 0,
00108 table.Size());
00109 concept.Reserve(nr, true);
00110
00111 for (int i=0 ; i<concept.Capacity() ; i++)
00112 {
00113 ILOG_INFO("concept: " << concept.Get(i));
00114 bool* filter = 0;
00115 Core::Column::MakeFilterEqual(filter, table.GetColumn3(), false,
00116 concept.Get(i));
00117 Core::Table::TableVxs t;
00118 Core::Table::Select(&t, &table, filter, true);
00119
00120 t.WriteVxsFile(concept.Get(i) + ".vxs");
00121 delete filter;
00122 ILOG_INFO(" size: " << t.Size());
00123 }
00124 }
00125
00126 void
00127 DoScaleFeatureTable()
00128 {
00129 typedef Core::Feature::FeatureTable FeatureTable;
00130 typedef Core::Vector::VectorTem<Real64> VectorReal64;
00131
00132 CmdOptions& options = CmdOptions::GetInstance();
00133 String tablename = options.GetArg(1);
00134 String scaledtablename = options.GetArg(2);
00135 String minmaxtablename = options.GetArg(3);
00136
00137 Core::Database::RawDataSet* dataSet = 0;
00138 String setName = options.GetString("videoSet");
00139 if (! setName.empty())
00140 dataSet = Core::VideoSet::MakeVideoSet(setName);
00141 setName = options.GetString("imageSet");
00142 if (! setName.empty())
00143 dataSet = Core::ImageSet::MakeImageSet(setName);
00144 Util::Database* db = &Util::Database::GetInstance();
00145 if (dataSet)
00146 db = dataSet->GetDatabase();
00147
00148 FeatureTable tableIn(tablename);
00149 Core::Table::Read(&tableIn, tablename, db);
00150
00151
00152 FeatureTable tableMinMax(tableIn.GetFeatureDefinition(), 2, tableIn.GetFeatureVectorLength());
00153 FeatureTable tableOut(tableIn.GetFeatureDefinition(), tableIn.Size(), tableIn.GetFeatureVectorLength());
00154
00155 VectorReal64 vMax;
00156 VectorReal64 vMin;
00157
00158 if(FileExists(minmaxtablename))
00159 {
00160
00161 std::cout << "read minmax from file: " << minmaxtablename << std::endl;
00162 Core::Table::Read(&tableMinMax, minmaxtablename, db);
00163 vMax = tableMinMax.Get2(0);
00164 vMin = tableMinMax.Get2(1);
00165 }
00166 else
00167 {
00168
00169 Core::Vector::Max(&vMax, tableIn.GetColumn2(), tableIn.Size(), 0);
00170 tableMinMax.Add(0, vMax);
00171
00172 Core::Vector::Min(&vMin, tableIn.GetColumn2(), tableIn.Size(), 0);
00173 tableMinMax.Add(1, vMin);
00174
00175 std::cout << "write minmax to file: " << minmaxtablename << std::endl;
00176 Core::Table::Write(&tableMinMax, minmaxtablename, db, true);
00177 }
00178
00179 std::cout << "max: " << vMax << std::endl;
00180 std::cout << "min: " << vMin << std::endl;
00181
00182
00183 VectorReal64 vMaxMinMin = vMax;
00184 Core::Vector::SubAssign(vMaxMinMin,vMin);
00185
00186
00187 VectorReal64 v;
00188 for(int i=0;i<tableIn.Size();i++)
00189 {
00190 v = tableIn.Get2(i);
00191 Core::Vector::SubAssign(v, vMin);
00192 Core::Vector::DivAssign(v, vMaxMinMin);
00193 tableOut.Add(tableIn.Get1(i), v);
00194 }
00195
00196
00197 std::string path = FileNamePath(scaledtablename);
00198 db->MakeDir(path);
00199
00200 Core::Table::Write(&tableOut, scaledtablename, db, true);
00201 }
00202
00203
00204 void
00205 DoAppendFeatureTable()
00206 {
00207 typedef Core::Feature::FeatureDefinition FeatureDef;
00208 typedef Core::Feature::FeatureTable FeatureTable;
00209
00210 ILOG_VAR(Impala.Application.Table.DoAppendFeatureTable);
00211 CmdOptions& options = CmdOptions::GetInstance();
00212 String dstName = options.GetArg(1);
00213 String srcName = options.GetArg(2);
00214 int nr = atol(options.GetArg(3));
00215
00216 Util::Database* db = &Util::Database::GetInstance();
00217 FeatureTable srcTable(srcName);
00218 Core::Table::Read(&srcTable, srcName, db);
00219
00220 FeatureTable dstTable(dstName, nr*srcTable.Size(),
00221 srcTable.GetFeatureVectorLength());
00222 for (int i=0 ; i<nr ; i++)
00223 dstTable.Append(&srcTable);
00224
00225 Core::Table::Write(&dstTable, dstName, db, true);
00226 }
00227
00228 void
00229 DoConcatFeatureTable()
00230 {
00231 typedef Core::Feature::FeatureDefinition FeatureDef;
00232 typedef Core::Feature::FeatureTable FeatureTable;
00233 typedef Core::Feature::FeatureTableSet FeatureTableSet;
00234
00235 ILOG_VAR(Impala.Application.Table.DoConcatFeatureTable);
00236 CmdOptions& options = CmdOptions::GetInstance();
00237 String dir = options.GetArg(1);
00238 bool useName = StringToBool(options.GetArg(2));
00239 FeatureDef resultDef(options.GetArg(3));
00240 String srcDefs = options.GetArg(4);
00241 for (int i=5 ; i<options.GetNrArg() ; i++)
00242 srcDefs += ";" + options.GetArg(i);
00243
00244 Util::Database* db = &Util::Database::GetInstance();
00245 FeatureTableSet* fSet = FeatureTableSet::MakeFromFile(dir, useName, srcDefs);
00246 FeatureTable* res = fSet->ConcatTables(resultDef);
00247 String fName = dir + "/";
00248 if (useName)
00249 fName += resultDef.GetName() + "/";
00250 fName += resultDef.AsString();
00251 Core::Table::Write(res, fName, db, true);
00252 fSet->Delete();
00253 delete fSet;
00254 delete res;
00255 }
00256
00257 void
00258 DoFeatureTable2Svm()
00259 {
00260 typedef Core::Feature::FeatureTable FeatureTable;
00261 typedef Core::Table::AnnotationTable AnnotationTable;
00262
00263 ILOG_VAR(Impala.Application.Table.DoFeatureTable2Svm);
00264 CmdOptions& options = CmdOptions::GetInstance();
00265 Util::Database* db = &Util::Database::GetInstance();
00266 if (options.GetNrArg() < 3)
00267 {
00268 ILOG_ERROR("Need more arguments");
00269 return;
00270 }
00271 String fName = options.GetArg(1);
00272 String svmName = options.GetArg(2);
00273 AnnotationTable* truth = 0;
00274 if (options.GetNrArg() > 3)
00275 {
00276 truth = AnnotationTable::MakeFromFile("", options.GetArg(3), db);
00277 }
00278 FeatureTable table(fName);
00279 Core::Table::Read(&table, fName, db);
00280 table.WriteSvmFile(svmName, db, truth);
00281 }
00282
00283 void
00284 DoFeatureTableReadAscii()
00285 {
00286 typedef Core::Feature::FeatureTable FeatureTable;
00287
00288 ILOG_VAR(Impala.Application.Table.DoFeatureTableReadAscii);
00289 CmdOptions& options = CmdOptions::GetInstance();
00290 Util::Database* db = &Util::Database::GetInstance();
00291 if (options.GetNrArg() < 3)
00292 {
00293 ILOG_ERROR("Need more arguments");
00294 return;
00295 }
00296 String tabName = options.GetArg(1);
00297 String asciiName = options.GetArg(2);
00298 FeatureTable table(tabName);
00299 table.ReadPlainAsciiFile(asciiName, db);
00300 Core::Table::Write(&table, tabName, db, true);
00301 }
00302
00303 void
00304 DoFeatureTableWriteAscii()
00305 {
00306 typedef Core::Feature::FeatureTable FeatureTable;
00307
00308 ILOG_VAR(Impala.Application.Table.DoFeatureTableWriteAscii);
00309 CmdOptions& options = CmdOptions::GetInstance();
00310 Util::Database* db = &Util::Database::GetInstance();
00311 if (options.GetNrArg() < 3)
00312 {
00313 ILOG_ERROR("Need more arguments");
00314 return;
00315 }
00316 String tabName = options.GetArg(1);
00317 String asciiName = options.GetArg(2);
00318 FeatureTable table(tabName);
00319 Core::Table::Read(&table, tabName, db);
00320 table.WritePlainAsciiFile(asciiName, db);
00321 }
00322
00323 void
00324 DoSimFeatureTable()
00325 {
00326 typedef Core::Feature::FeatureTable FeatureTable;
00327 typedef Core::Table::SimilarityTableSet SimilarityTableSet;
00328 typedef Core::Table::SimilarityTableSet::SimTableType SimTableType;
00329
00330 ILOG_VAR(Impala.Application.Table.DoSimFeatureTable);
00331 CmdOptions& options = CmdOptions::GetInstance();
00332 Util::Database* db = &Util::Database::GetInstance();
00333 if (options.GetNrArg() < 4)
00334 {
00335 ILOG_ERROR("Need more arguments");
00336 return;
00337 }
00338 String outDir = options.GetArg(1);
00339 String fName1 = options.GetArg(2);
00340 FeatureTable table1(fName1);
00341 ILOG_INFO("Reading " << fName1);
00342 Core::Table::Read(&table1, fName1, db);
00343 String fName2 = options.GetArg(3);
00344 FeatureTable table2(fName2);
00345 ILOG_INFO("Reading " << fName2);
00346 Core::Table::Read(&table2, fName2, db);
00347
00348 std::vector<String> names;
00349 for (int i=0 ; i<table1.Size() ; i++)
00350 names.push_back(QuidObj(table1.Get1(i)).ToString());
00351 ILOG_INFO("nrNames = " << names.size());
00352 SimilarityTableSet simSet(names, table2.Size());
00353 String outPath = outDir + "/";
00354 simSet.SaveNames(outPath, db);
00355 Core::Table::Copy(simSet.GetQuidTable(), &table2);
00356 simSet.SaveQuids(outPath, db, true);
00357 for (int i=0 ; i<names.size() ; i++)
00358 {
00359 ILOG_INFO("i = " << i);
00360 SimTableType* simTable = simSet.GetSimTable(i);
00361 Real64* sim = simTable->GetColumn1()->GetData();
00362 Core::Vector::Similarity(sim, table1.Get2(i),
00363 table2.GetColumn2(), 0, 1,
00364 Core::Vector::Norm1Dist<Real64>);
00365 simTable->SetSize(table2.Size());
00366 ILOG_INFO(" compute rank");
00367 simSet.ComputeRank(i, false);
00368 simSet.Save(i, outPath, db, true);
00369 }
00370 }
00371
00372 void
00373 DoSelectFeatureTableSet()
00374 {
00375 typedef Core::Feature::FeatureTableSet FeatureTableSet;
00376 typedef Core::Feature::FeatureTable FeatureTable;
00377
00378 ILOG_VAR(Impala.Application.Table.DoSelectFeatureTableSet);
00379 CmdOptions& options = CmdOptions::GetInstance();
00380 if (options.GetNrArg() < 5)
00381 {
00382 ILOG_ERROR("Need more parameters");
00383 return;
00384 }
00385
00386 String setName = options.GetArg(1);
00387 String resName = options.GetArg(2);
00388 int optimalSize = atol(options.GetArg(3));
00389 String feature = options.GetArg(4);
00390 Core::Database::RawDataSet* ds = Core::Database::MakeRawDataSet(setName);
00391
00392 Core::Feature::Computor* c = 0;
00393 if (feature == "weibull")
00394 c = new Core::Feature::VisSem("vissem", options);
00395 else if (feature == "gabor")
00396 c = new Core::Feature::VisSem("vissemgabor", options);
00397 else
00398 ILOG_ERROR("unknown feature : " << feature);
00399 c->ReadPrototypes(setName, "", -1);
00400
00401 std::vector<String> res;
00402 std::vector<int> resVal;
00403 for (int p=0 ; p<c->GetNrPixelFeatureSets() ; p++)
00404 {
00405 for (int r=0 ; r<c->GetNrRegionFeatureSets() ; r++)
00406 {
00407 std::cout << "p=" << p << " r=" << r << std::endl;
00408 std::vector<FeatureTable*> tabs = c->GetProtoFeatureTables(p, r);
00409 int bestIdx = -1;
00410 int bestVal = 0;
00411 for (int t=0 ; t<tabs.size() ; t++)
00412 {
00413 FeatureTable* tab = tabs[t];
00414 std::cout << " " << tab->GetFeatureDefinition().AsString()
00415 << " = " << tab->Size() << std::endl;
00416 int s = tab->Size();
00417 if (bestIdx == -1)
00418 {
00419 bestIdx = t;
00420 bestVal = s;
00421 continue;
00422 }
00423 if (s >= optimalSize)
00424 {
00425 if ((bestVal < optimalSize) || (s < bestVal))
00426 {
00427 bestIdx = t;
00428 bestVal = s;
00429 }
00430 }
00431 else
00432 {
00433 if ((bestVal < optimalSize) && (s > bestVal))
00434 {
00435 bestIdx = t;
00436 bestVal = s;
00437 }
00438 }
00439 }
00440 std::cout << " bestVal = " << bestVal << std::endl;
00441 String def = tabs[bestIdx]->GetFeatureDefinition().AsString();
00442 res.push_back(def);
00443 resVal.push_back(bestVal);
00444 }
00445 }
00446
00447 std::cout << std::endl << "Selection: " << std::endl;
00448 for (int i=0 ; i<res.size() ; i++)
00449 {
00450 std::cout << resVal[i] << " from " << res[i] << std::endl;
00451 }
00452 String fName = ds->GetFilePathPrototype(c->GetProtoDataFile(), c->GetName(),
00453 resName, true, false);
00454 if (!fName.empty())
00455 {
00456 std::cout << "Writing to " << fName << std::endl;
00457 Util::DatabaseWriteString(fName, ds->GetDatabase(), res.begin(),
00458 res.end());
00459 }
00460 }
00461
00462 void
00463 DoDumpSimilarityTableSetTrec()
00464 {
00465 typedef Core::Table::SimilarityTableSet SimilarityTableSet;
00466
00467 ILOG_VAR(Impala.Application.Table.DoDumpSimilarityTableSetTrec);
00468 CmdOptions& options = CmdOptions::GetInstance();
00469 if (options.GetNrArg() < 3)
00470 {
00471 ILOG_ERROR("Need more parameters");
00472 return;
00473 }
00474
00475 String setName = options.GetArg(1);
00476 Core::VideoSet::VideoSet* vidSet = Core::VideoSet::MakeVideoSet(setName);
00477 Core::VideoSet::Keyframes keyframes(vidSet, "keyframes");
00478 String path = options.GetArg(2);
00479 SimilarityTableSet* simSet =
00480 Core::Table::SimilarityTableSet::MakeFromFile(path,
00481 vidSet->GetDatabase());
00482
00483 Core::Table::QuidTable* qTable = simSet->GetQuidTable();
00484 int start = options.GetInt("start");
00485 int end = options.GetInt("end");
00486 if ((end == -1) || (end > qTable->Size()))
00487 end = qTable->Size();
00488
00489 std::cout << "SimilarityTableSet " << simSet->GetDescription() << std::endl;
00490 for (int t=0 ; t<simSet->NrTables() ; t++)
00491 {
00492 SimilarityTableSet::SimTableType* simTable = simSet->GetSimTable(t);
00493 std::cout << "table " << t << ", name = " << simSet->GetName(t)
00494 << std::endl;
00495 if (simTable->Size() != qTable->Size())
00496 {
00497 ILOG_ERROR("DumpRanking: simtable size doesn't match");
00498 continue;
00499 }
00500 String concept = simSet->GetName(t);
00501 for (int i=start ; i<end ; i++)
00502 {
00503 Quid quid = qTable->Get1(i);
00504
00505 std::cout << concept << ", ";
00506 int keyId = keyframes.GetFrameId(quid);
00507 if (keyId != -1)
00508 std::cout << FileNameBase(keyframes.GetName(keyId)) << ", ";
00509 else
00510 std::cout << vidSet->QuidToString(quid, true) << ", ";
00511 std::cout << simTable->Get1(i) << std::endl;
00512 }
00513 std::cout << std::endl;
00514 }
00515 delete simSet;
00516 }
00517
00518 void
00519 DoImportSimilarityTableSet()
00520 {
00521 typedef Core::Table::SimilarityTableSet SimilarityTableSet;
00522 typedef Core::Table::SimilarityTableSet::SimTableType SimTableType;
00523
00524 ILOG_VAR(Impala.Application.Table.DoImportSimilarityTableSet);
00525 ILOG_ERROR("Will fail because doesn't have Quids (yet)");
00526 CmdOptions& options = CmdOptions::GetInstance();
00527 if (options.GetNrArg() < 5)
00528 {
00529 ILOG_ERROR("Need more arguments");
00530 return;
00531 }
00532 String outDir = options.GetArg(1);
00533 String conceptFile = options.GetArg(2);
00534 String inDir = options.GetArg(3);
00535 int nrIds = atol(options.GetArg(4));
00536 String fileExt("");
00537 if (options.GetNrArg() > 5)
00538 fileExt = options.GetArg(5);
00539 Util::Database* db = &Util::Database::GetInstance();
00540
00541 std::vector<String> concepts;
00542 Util::DatabaseReadString(std::back_inserter(concepts), conceptFile, db, true);
00543 ILOG_INFO("nrConcepts = " << concepts.size());
00544 SimilarityTableSet simSet(concepts, nrIds);
00545 String outPath = outDir + "/" + FileNameTail(conceptFile) + "/";
00546 simSet.SaveNames(outPath, db);
00547 for (int c=0 ; c<concepts.size() ; c++)
00548 {
00549 String fName = inDir + "/" + concepts[c] + fileExt;
00550 ILOG_INFO("importing " << concepts[c] << " from " << fName);
00551 std::vector<String> lines;
00552 Util::DatabaseReadString(std::back_inserter(lines), fName, db, true);
00553 if (lines.size() != nrIds)
00554 {
00555 ILOG_ERROR("wrong number of lines : " << lines.size() <<
00556 " instead of " << nrIds);
00557 continue;
00558 }
00559 SimTableType* simTable = simSet.GetSimTable(c);
00560 simTable->SetSize(0);
00561 for (int i=0 ; i<lines.size() ; i++)
00562 simTable->Add(atof(lines[i]));
00563 simSet.ComputeRank(c, true);
00564 simSet.Save(c, outPath, db, true);
00565 }
00566 }
00567
00568 void
00569 DoProcSimilarityTableSet()
00570 {
00571 typedef Core::Table::SimilarityTableSet SimilarityTableSet;
00572 typedef Core::Table::SimilarityTableSet::SimTableType SimTableType;
00573 typedef Core::Table::SimilarityTableSet::RankTableType RankTableType;
00574 typedef Core::Array::Array2dScalarReal64 ArrayType;
00575
00576 ILOG_VAR(Impala.Application.Table.DoProcSimilarityTableSet);
00577 CmdOptions& options = CmdOptions::GetInstance();
00578 if (options.GetNrArg() < 7)
00579 {
00580 ILOG_ERROR("Need more parameters");
00581 return;
00582 }
00583
00584 String setName = options.GetArg(1);
00585 Core::VideoSet::VideoSet* vidSet = Core::VideoSet::MakeVideoSet(setName);
00586 String walkType = options.GetArg(2);
00587 String conceptSet = options.GetArg(3);
00588 String model = options.GetArg(4);
00589 String feature = options.GetArg(5);
00590 int fileId = Impala::atol(options.GetArg(6));
00591
00592 SimilarityTableSet* srcSet = Core::Table::SimilarityTableSet::MakeFromFile
00593 (vidSet, walkType, conceptSet, model, feature, fileId);
00594
00595
00596 std::vector<String> srcNames = srcSet->GetNames();
00597 std::vector<String> dstNames;
00598 for (int i=0 ; i<srcNames.size() ; i++)
00599 {
00600 dstNames.push_back(srcNames[i]);
00601 dstNames.push_back(srcNames[i] + "_proc");
00602 }
00603 SimilarityTableSet* dstSet =
00604 new SimilarityTableSet(dstNames, srcSet->TableSize());
00605
00606
00607 Core::Table::Copy(dstSet->GetQuidTable(), srcSet->GetQuidTable());
00608 for (int t=0 ; t<srcSet->NrTables() ; t++)
00609 {
00610 SimTableType* srcTable = srcSet->GetSimTable(t);
00611 Core::Table::Copy(dstSet->GetSimTable(2*t), srcTable);
00612
00613 SimTableType* dstTable = dstSet->GetSimTable(2*t+1);
00614 Core::Table::Copy(dstTable, srcTable);
00615 ArrayType srcWrap(srcTable->Size(), 1, 0, 0,
00616 srcTable->GetColumn1()->GetData(), true);
00617 ArrayType* tmp = 0;
00618
00619
00620
00621 Core::Array::Percentile(tmp, &srcWrap, 5, 0.5);
00622 ArrayType* ker = Core::Array::ArrayCreate<ArrayType>(101, 1);
00623 Core::Matrix::MatSet(ker, 0);
00624 Core::Array::Erosion(tmp, tmp, ker);
00625 Core::Array::Dilation(tmp, tmp, ker);
00626 delete ker;
00627
00628 Real64* tmpPtr = tmp->CPB(0, 0);
00629 for (int i=tmp->CW()-1 ; i>=1 ; i--)
00630 {
00631 if (tmpPtr[i] == tmpPtr[i-1])
00632 tmpPtr[i] = 0;
00633 }
00634
00635 ker = Core::Array::ArrayCreate<ArrayType>(501, 1);
00636 Core::Matrix::MatSet(ker, 0);
00637 ArrayType* localMax = 0;
00638 Core::Array::Dilation(localMax, tmp, ker);
00639 Core::Array::Equals(localMax, localMax, tmp);
00640 Core::Array::Mul(tmp, localMax, tmp);
00641 delete ker;
00642 delete localMax;
00643
00644 ArrayType* dstWrap = new ArrayType(dstTable->Size(), 1, 0, 0,
00645 dstTable->GetColumn1()->GetData(), true);
00646 Core::Array::Set(dstWrap, tmp);
00647 delete dstWrap;
00648 delete tmp;
00649
00650 }
00651 dstSet->ComputeRanks(true);
00652 String con = FileNameBase(conceptSet) + "_proc." + FileNameExt(conceptSet);
00653 dstSet->Save(vidSet, walkType, con, model, feature, fileId, true);
00654 }
00655
00656 void
00657 DoMakeRandomSimilarityTableSet()
00658 {
00659 typedef Core::Table::SimilarityTableSet SimilarityTableSet;
00660 typedef Core::Table::SimilarityTableSet::SimTableType SimTableType;
00661
00662 ILOG_VAR(Impala.Application.Table.DoSimFeatureTable);
00663
00664
00665
00666 CmdOptions& options = CmdOptions::GetInstance();
00667 if (options.GetNrArg() < 2)
00668 {
00669 ILOG_ERROR("Need more arguments");
00670 return;
00671 }
00672 String setName = options.GetArg(1);
00673 Core::VideoSet::VideoSet* vidSet = Core::VideoSet::MakeVideoSet(setName);
00674 Core::VideoSet::Keyframes keyframes(vidSet, "keyframes");
00675
00676 std::vector<String> names;
00677 names.push_back("RandomKeyframes");
00678
00679
00680 for (int v=0 ; v<vidSet->NrFiles() ; v++)
00681 {
00682 int nrKeys = keyframes.GetNrKeyframesVideo(v);
00683 SimilarityTableSet simSet(names, nrKeys);
00684 int idx = 0;
00685 SimTableType* simTable = simSet.GetSimTable(idx);
00686 Core::Table::QuidTable* qTable = simSet.GetQuidTable();
00687 int firstKey = keyframes.GetFirstKeyframeVideo(v);
00688 for (int k=0 ; k<nrKeys ; k++)
00689 {
00690 Quid q = keyframes.GetQuidFrame(firstKey + k);
00691 qTable->Add(q);
00692 Real64 sim = (Real64) rand() / RAND_MAX;
00693 simTable->Add(sim);
00694 }
00695 simSet.ComputeRank(0, true);
00696 simSet.Save(vidSet, "Keyframes", "artificialConcepts.txt", "no_model",
00697 "Random", v, true);
00698 }
00699
00700 }
00701
00702 void
00703 DoDumpTaskTable()
00704 {
00705 typedef Core::VideoSet::TaskTable TaskTable;
00706
00707 CmdOptions& options = CmdOptions::GetInstance();
00708 Util::Database* db = &Util::Database::GetInstance();
00709 String fName = options.GetArg(1);
00710 TaskTable table(fName, db);
00711
00712 table.Dump(options.GetInt("start"), options.GetInt("end"));
00713 }
00714
00715 void
00716 DoDumpTableReal()
00717 {
00718 CmdOptions& options = CmdOptions::GetInstance();
00719 DoDump<Real64>(options.GetArg(1));
00720 }
00721
00722 void
00723 DoDumpTableInt()
00724 {
00725 CmdOptions& options = CmdOptions::GetInstance();
00726 DoDump<Int32>(options.GetArg(1));
00727 }
00728
00729 void
00730 DoDiffTableReal()
00731 {
00732 CmdOptions& options = CmdOptions::GetInstance();
00733 DoDiff<Real64>(options.GetArg(1), options.GetArg(2));
00734 }
00735
00736 void
00737 DoDiffTableInt()
00738 {
00739 CmdOptions& options = CmdOptions::GetInstance();
00740 DoDiff<Int32>(options.GetArg(1), options.GetArg(2));
00741 }
00742
00743 void
00744 DoDiffTableUInt64()
00745 {
00746 CmdOptions& options = CmdOptions::GetInstance();
00747 DoDiff<UInt64>(options.GetArg(1), options.GetArg(2));
00748 }
00749
00750 int
00751 mainTable(int argc, char* argv[])
00752 {
00753 CmdOptions& options = CmdOptions::GetInstance();
00754 options.Initialise(false, false, true);
00755 options.AddOption(0, "start", "nr", "0");
00756 options.AddOption(0, "end", "nr", "-1");
00757 options.AddOption(0, "order", "", "false");
00758 String usageStr = "cmd = \n\n";
00759 usageStr += " vxstable file.vxs\n";
00760 usageStr += " scalefeaturetable tablename scaledtablename minmaxtablename\n";
00761 usageStr += " concatfeaturetable dir useName resultDef tableDefs\n";
00762 usageStr += " featuretable2svm tablename svmname [concept.truth]\n";
00763 usageStr += " featuretablereadascii tablename asciiname\n";
00764 usageStr += " featuretablewriteascii tablename asciiname\n";
00765 usageStr += " simfeaturetable outDir tablename1 tablename2\n";
00766 usageStr += " selectfeaturetableset dataset.txt feature output.txt\n";
00767 usageStr += " dumpsimilaritytablesettrec videoset.txt names.txt\n";
00768 usageStr += " importsimilaritytableset outdir concepts indir nrIds [fileext]\n";
00769 usageStr += " procsimilaritytableset videoset.txt walkType concepts.txt model feature fileId\n";
00770 usageStr += " makerandomsimilaritytableset videoset.txt\n";
00771 usageStr += " dumptasktable tablename\n";
00772 usageStr += " dumptablereal tablename\n";
00773 usageStr += " dumptableint tablename\n";
00774 usageStr += " difftablereal tablename1 tablename2\n";
00775 usageStr += " difftableint tablename1 tablename2\n";
00776 usageStr += " difftableuint64 tablename1 tablename2\n";
00777 if (! options.ParseArgs(argc, argv, usageStr, 1))
00778 return 1;
00779
00780 ILOG_VAR(Impala.Application.mainTable);
00781
00782 String cmd = options.GetArg(0);
00783 ILOG_DEBUG("table command : " << cmd);
00784
00785 if (cmd == "vxstable")
00786 DoVxsTable();
00787 else if (cmd == "scalefeaturetable")
00788 DoScaleFeatureTable();
00789 else if (cmd == "append")
00790 DoAppendFeatureTable();
00791 else if (cmd == "concatfeaturetable")
00792 DoConcatFeatureTable();
00793 else if (cmd == "featuretable2svm")
00794 DoFeatureTable2Svm();
00795 else if (cmd == "featuretablereadascii")
00796 DoFeatureTableReadAscii();
00797 else if (cmd == "featuretablewriteascii")
00798 DoFeatureTableWriteAscii();
00799 else if (cmd == "simfeaturetable")
00800 DoSimFeatureTable();
00801 else if (cmd == "selectfeaturetableset")
00802 DoSelectFeatureTableSet();
00803 else if (cmd == "dumpsimilaritytablesettrec")
00804 DoDumpSimilarityTableSetTrec();
00805 else if (cmd == "importsimilaritytableset")
00806 DoImportSimilarityTableSet();
00807 else if (cmd == "procsimilaritytableset")
00808 DoProcSimilarityTableSet();
00809 else if (cmd == "makerandomsimilaritytableset")
00810 DoMakeRandomSimilarityTableSet();
00811 else if (cmd == "dumptasktable")
00812 DoDumpTaskTable();
00813 else if (cmd == "dumptablereal")
00814 DoDumpTableReal();
00815 else if (cmd == "dumptableint")
00816 DoDumpTableInt();
00817 else if (cmd == "difftablereal")
00818 DoDiffTableReal();
00819 else if (cmd == "difftableint")
00820 DoDiffTableInt();
00821 else if (cmd == "difftableuint64")
00822 DoDiffTableUInt64();
00823
00824 else ILOG_ERROR("Unknown cmd : " << cmd);
00825
00826 return 0;
00827 }
00828
00829 }
00830 }
00831 }
00832
00833 int
00834 main(int argc, char* argv[])
00835 {
00836 return Impala::Application::Table::mainTable(argc, argv);
00837 }