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/Segmentation.h"
00026 #include "Core/VideoSet/Keyframes.h"
00027 #include "Core/VideoSet/Stills.h"
00028 #include "Core/ImageSet/MakeImageSet.h"
00029 #include "Core/Array/Percentile.h"
00030 #include "Core/Array/Dilation.h"
00031 #include "Core/Array/Erosion.h"
00032 #include "Core/Array/Equals.h"
00033 #include "Core/Array/Mul.h"
00034 #include "Core/Matrix/MatSet.h"
00035
00036
00037
00038 #include "Link/ImpalaLib.cpp"
00039
00040 namespace Impala
00041 {
00042 namespace Application
00043 {
00044 namespace Table
00045 {
00046
00047 template <class ColElemT>
00048 void
00049 DoDump(String fName)
00050 {
00051 typedef Core::Column::ColumnTem<ColElemT> ColumnType;
00052 typedef Core::Table::TableTem<ColumnType> TableType;
00053
00054 CmdOptions& options = CmdOptions::GetInstance();
00055 Util::Database* db = &Util::Database::GetInstance();
00056 TableType table(0);
00057 Core::Table::Read(&table, fName, db);
00058 table.Dump(options.GetInt("start"), options.GetInt("end"));
00059 }
00060
00061 template <class ColElemT>
00062 void
00063 DoDiff(String fName1, String fName2)
00064 {
00065 typedef Core::Column::ColumnTem<ColElemT> ColumnType;
00066 typedef Core::Table::TableTem<ColumnType> TableType;
00067
00068 ILOG_VAR(Impala.Application.Table.DoDiff);
00069 CmdOptions& options = CmdOptions::GetInstance();
00070 Util::Database* db = &Util::Database::GetInstance();
00071 TableType table1(0);
00072 Core::Table::Read(&table1, fName1, db);
00073 TableType table2(0);
00074 Core::Table::Read(&table2, fName2, db);
00075 if (table1.Size() != table2.Size())
00076 {
00077 ILOG_INFO("Different table sizes: " << table1.Size() << " vs "
00078 << table2.Size());
00079 return;
00080 }
00081 int verb = options.GetInt("verb");
00082 int nDiff = 0;
00083 for (int i=0 ; i<table1.Size() ; i++)
00084 {
00085
00086 if ((table1.Get1(i) - table2.Get1(i)) > 0.00001)
00087 {
00088 nDiff++;
00089 if (verb)
00090 ILOG_INFO("diff elem " << i << ": " << table1.Get1(i)
00091 << " vs " << table2.Get1(i));
00092 }
00093 }
00094 if (nDiff > 0)
00095 ILOG_INFO("Found " << nDiff << " differences");
00096 }
00097
00098 void
00099 DoVxsTable()
00100 {
00101 ILOG_VAR(Impala.Application.Table.DoVxsTable);
00102 CmdOptions& options = CmdOptions::GetInstance();
00103 String fName = options.GetArg(1);
00104 Core::Table::TableVxs table;
00105 table.ReadVxsFile(fName);
00106
00107
00108 Core::Column::ColumnTem<String> concept(table.Size());
00109 int nr = Core::Column::CopyUnique(&concept, table.GetColumn3(), 0, 0,
00110 table.Size());
00111 concept.Reserve(nr, true);
00112
00113 for (int i=0 ; i<concept.Capacity() ; i++)
00114 {
00115 ILOG_INFO("concept: " << concept.Get(i));
00116 bool* filter = 0;
00117 Core::Column::MakeFilterEqual(filter, table.GetColumn3(), false,
00118 concept.Get(i));
00119 Core::Table::TableVxs t;
00120 Core::Table::Select(&t, &table, filter, true);
00121
00122 t.WriteVxsFile(concept.Get(i) + ".vxs");
00123 delete filter;
00124 ILOG_INFO(" size: " << t.Size());
00125 }
00126 }
00127
00128 void
00129 DoDiffSegmentation()
00130 {
00131 typedef Core::VideoSet::SegmentationBaseType SegmentationBaseType;
00132
00133 ILOG_VAR(Impala.Application.Table.DoDiffSegmentation);
00134 CmdOptions& options = CmdOptions::GetInstance();
00135 Util::Database* db = &Util::Database::GetInstance();
00136 String fName1 = options.GetArg(1);
00137 SegmentationBaseType table1(0);
00138 Core::Table::Read(&table1, fName1, db);
00139 String fName2 = options.GetArg(2);
00140 SegmentationBaseType table2(0);
00141 Core::Table::Read(&table2, fName2, db);
00142 if (table1.Size() != table2.Size())
00143 {
00144 ILOG_INFO("Different table sizes: " << table1.Size() << " vs "
00145 << table2.Size());
00146 return;
00147 }
00148 int verb = options.GetInt("verb");
00149 int nDiff = 0;
00150 for (int i=0 ; i<table1.Size() ; i++)
00151 {
00152 if (table1.Get1(i) != table2.Get1(i))
00153 {
00154 nDiff++;
00155 if (verb)
00156 ILOG_INFO("diff col1 " << i << ": " << table1.Get1(i)
00157 << " vs " << table2.Get1(i));
00158 }
00159 else if (table1.Get2(i) != table2.Get2(i))
00160 {
00161 nDiff++;
00162 if (verb)
00163 ILOG_INFO("diff col2 " << i << ": " << table1.Get2(i)
00164 << " vs " << table2.Get2(i));
00165 }
00166 else if (table1.Get3(i) != table2.Get3(i))
00167 {
00168 nDiff++;
00169 if (verb)
00170 ILOG_INFO("diff col3 " << i << ": " << table1.Get3(i)
00171 << " vs " << table2.Get3(i));
00172 }
00173 else if (table1.Get4(i) != table2.Get4(i))
00174 {
00175 nDiff++;
00176 if (verb)
00177 ILOG_INFO("diff col4 " << i << ": " << table1.Get4(i)
00178 << " vs " << table2.Get4(i));
00179 }
00180 }
00181 if (nDiff > 0)
00182 ILOG_INFO("Found " << nDiff << " differences");
00183 }
00184
00185 void
00186 DoDiffKeyframes()
00187 {
00188 typedef Core::VideoSet::KeyframesBaseType KeyframesBaseType;
00189
00190 ILOG_VAR(Impala.Application.Table.DoDiffKeyframes);
00191 CmdOptions& options = CmdOptions::GetInstance();
00192 Util::Database* db = &Util::Database::GetInstance();
00193 String fName1 = options.GetArg(1);
00194 KeyframesBaseType table1(0);
00195 Core::Table::Read(&table1, fName1, db);
00196 String fName2 = options.GetArg(2);
00197 KeyframesBaseType table2(0);
00198 Core::Table::Read(&table2, fName2, db);
00199 if (table1.Size() != table2.Size())
00200 {
00201 ILOG_INFO("Different table sizes: " << table1.Size() << " vs "
00202 << table2.Size());
00203 return;
00204 }
00205 int verb = options.GetInt("verb");
00206 int nDiff = 0;
00207 for (int i=0 ; i<table1.Size() ; i++)
00208 {
00209 if (table1.Get1(i) != table2.Get1(i))
00210 {
00211 nDiff++;
00212 if (verb)
00213 ILOG_INFO("diff col1 " << i << ": " << table1.Get1(i)
00214 << " vs " << table2.Get1(i));
00215 }
00216 if (table1.Get2(i) != table2.Get2(i))
00217 {
00218 nDiff++;
00219 if (verb)
00220 ILOG_INFO("diff col2 " << i << ": " << table1.Get2(i)
00221 << " vs " << table2.Get2(i));
00222 }
00223 if (table1.Get3(i) != table2.Get3(i))
00224 {
00225 nDiff++;
00226 if (verb)
00227 ILOG_INFO("diff col3 " << i << ": " << table1.Get3(i)
00228 << " vs " << table2.Get3(i));
00229 }
00230 if (table1.Get4(i) != table2.Get4(i))
00231 {
00232 nDiff++;
00233 if (verb)
00234 ILOG_INFO("diff col4 " << i << ": " << table1.Get4(i)
00235 << " vs " << table2.Get4(i));
00236 }
00237 }
00238 if (nDiff > 0)
00239 ILOG_INFO("Found " << nDiff << " differences");
00240 }
00241
00242 void
00243 DoDiffStills()
00244 {
00245 typedef Core::VideoSet::StillsBaseType StillsBaseType;
00246
00247 ILOG_VAR(Impala.Application.Table.DoDiffStills);
00248 CmdOptions& options = CmdOptions::GetInstance();
00249 Util::Database* db = &Util::Database::GetInstance();
00250 String fName1 = options.GetArg(1);
00251 StillsBaseType table1(0);
00252 Core::Table::Read(&table1, fName1, db);
00253 String fName2 = options.GetArg(2);
00254 StillsBaseType table2(0);
00255 Core::Table::Read(&table2, fName2, db);
00256 if (table1.Size() != table2.Size())
00257 {
00258 ILOG_INFO("Different table sizes: " << table1.Size() << " vs "
00259 << table2.Size());
00260 return;
00261 }
00262 int verb = options.GetInt("verb");
00263 int nDiff = 0;
00264 for (int i=0 ; i<table1.Size() ; i++)
00265 {
00266 if (table1.Get1(i) != table2.Get1(i))
00267 {
00268 nDiff++;
00269 if (verb)
00270 ILOG_INFO("diff col1 " << i << ": " << table1.Get1(i)
00271 << " vs " << table2.Get1(i));
00272 }
00273 if (table1.Get2(i) != table2.Get2(i))
00274 {
00275 nDiff++;
00276 if (verb)
00277 ILOG_INFO("diff col2 " << i << ": " << table1.Get2(i)
00278 << " vs " << table2.Get2(i));
00279 }
00280 if (table1.Get3(i) != table2.Get3(i))
00281 {
00282 nDiff++;
00283 if (verb)
00284 ILOG_INFO("diff col3 " << i << ": " << table1.Get3(i)
00285 << " vs " << table2.Get3(i));
00286 }
00287 if (table1.Get4(i) != table2.Get4(i))
00288 {
00289 nDiff++;
00290 if (verb)
00291 ILOG_INFO("diff col4 " << i << ": " << table1.Get4(i)
00292 << " vs " << table2.Get4(i));
00293 }
00294 }
00295 if (nDiff > 0)
00296 ILOG_INFO("Found " << nDiff << " differences");
00297 }
00298
00299 void
00300 DoDumpQuidTable()
00301 {
00302 typedef Core::Table::QuidTable QuidTable;
00303
00304 CmdOptions& options = CmdOptions::GetInstance();
00305 String fName = options.GetArg(1);
00306 bool doGroup = (options.GetNrArg() > 2);
00307
00308 Core::Database::RawDataSet* dataSet = 0;
00309 String setName = options.GetString("videoSet");
00310 if (! setName.empty())
00311 dataSet = Core::VideoSet::MakeVideoSet(setName);
00312 setName = options.GetString("imageSet");
00313 if (! setName.empty())
00314 dataSet = Core::ImageSet::MakeImageSet(setName);
00315 Util::Database* db = &Util::Database::GetInstance();
00316 if (dataSet)
00317 db = dataSet->GetDatabase();
00318 QuidTable table;
00319 if (FileNameExt(fName) == "tab")
00320 {
00321 Core::Table::Read(&table, fName, db);
00322 }
00323 else
00324 {
00325 std::vector<String> quids;
00326 Util::DatabaseReadString(std::back_inserter(quids), fName, db, true);
00327 for (int i=0 ; i<quids.size() ; i++)
00328 {
00329 Quid q = atoull(quids[i]);
00330 table.Add(q);
00331 }
00332 }
00333 table.Dump(dataSet, options.GetInt("start"), options.GetInt("end"));
00334
00335 if (doGroup)
00336 {
00337 table.UpdateGroups();
00338 table.DumpGroup();
00339 }
00340 }
00341
00342 void
00343 DoDumpFeatureTable()
00344 {
00345 ILOG_VAR(Impala.Application.Table.DoDumpFeatureTable);
00346 typedef Core::Feature::FeatureTable FeatureTable;
00347
00348 CmdOptions& options = CmdOptions::GetInstance();
00349 String fName = options.GetArg(1);
00350 bool doWrite = false;
00351 if (options.GetNrArg() > 2)
00352 doWrite = atol(options.GetArg(2));
00353
00354 Core::Database::RawDataSet* dataSet = 0;
00355 String setName = options.GetString("videoSet");
00356 if (! setName.empty())
00357 dataSet = Core::VideoSet::MakeVideoSet(setName);
00358 setName = options.GetString("imageSet");
00359 if (! setName.empty())
00360 dataSet = Core::ImageSet::MakeImageSet(setName);
00361 Util::Database* db = &Util::Database::GetInstance();
00362 if (dataSet)
00363 db = dataSet->GetDatabase();
00364 FeatureTable table(fName);
00365 Core::Table::Read(&table, fName, db);
00366 table.Dump(dataSet, options.GetInt("start"), options.GetInt("end"));
00367 if (doWrite)
00368 {
00369 ILOG_INFO("Rewriting " << fName);
00370 Core::Table::Write(&table, fName, db, true);
00371 }
00372 }
00373
00374 void
00375 DoScaleFeatureTable()
00376 {
00377 typedef Core::Feature::FeatureTable FeatureTable;
00378 typedef Core::Vector::VectorTem<Real64> VectorReal64;
00379
00380 CmdOptions& options = CmdOptions::GetInstance();
00381 String tablename = options.GetArg(1);
00382 String scaledtablename = options.GetArg(2);
00383 String minmaxtablename = options.GetArg(3);
00384
00385 Core::Database::RawDataSet* dataSet = 0;
00386 String setName = options.GetString("videoSet");
00387 if (! setName.empty())
00388 dataSet = Core::VideoSet::MakeVideoSet(setName);
00389 setName = options.GetString("imageSet");
00390 if (! setName.empty())
00391 dataSet = Core::ImageSet::MakeImageSet(setName);
00392 Util::Database* db = &Util::Database::GetInstance();
00393 if (dataSet)
00394 db = dataSet->GetDatabase();
00395
00396 FeatureTable tableIn(tablename);
00397 Core::Table::Read(&tableIn, tablename, db);
00398
00399
00400 FeatureTable tableMinMax(tableIn.GetFeatureDefinition(), 2, tableIn.GetFeatureVectorLength());
00401 FeatureTable tableOut(tableIn.GetFeatureDefinition(), tableIn.Size(), tableIn.GetFeatureVectorLength());
00402
00403 VectorReal64 vMax;
00404 VectorReal64 vMin;
00405
00406 if(FileExists(minmaxtablename))
00407 {
00408
00409 std::cout << "read minmax from file: " << minmaxtablename << std::endl;
00410 Core::Table::Read(&tableMinMax, minmaxtablename, db);
00411 vMax = tableMinMax.Get2(0);
00412 vMin = tableMinMax.Get2(1);
00413 }
00414 else
00415 {
00416
00417 Core::Vector::Max(&vMax, tableIn.GetColumn2(), tableIn.Size(), 0);
00418 tableMinMax.Add(0, vMax);
00419
00420 Core::Vector::Min(&vMin, tableIn.GetColumn2(), tableIn.Size(), 0);
00421 tableMinMax.Add(1, vMin);
00422
00423 std::cout << "write minmax to file: " << minmaxtablename << std::endl;
00424 Core::Table::Write(&tableMinMax, minmaxtablename, db, true);
00425 }
00426
00427 std::cout << "max: " << vMax << std::endl;
00428 std::cout << "min: " << vMin << std::endl;
00429
00430
00431 VectorReal64 vMaxMinMin = vMax;
00432 Core::Vector::SubAssign(vMaxMinMin,vMin);
00433
00434
00435 VectorReal64 v;
00436 for(int i=0;i<tableIn.Size();i++)
00437 {
00438 v = tableIn.Get2(i);
00439 Core::Vector::SubAssign(v, vMin);
00440 Core::Vector::DivAssign(v, vMaxMinMin);
00441 tableOut.Add(tableIn.Get1(i), v);
00442 }
00443
00444
00445 std::string path = FileNamePath(scaledtablename);
00446 db->MakeDir(path);
00447
00448 Core::Table::Write(&tableOut, scaledtablename, db, true);
00449 }
00450
00451
00452 void
00453 DoAppendFeatureTable()
00454 {
00455 typedef Core::Feature::FeatureDefinition FeatureDef;
00456 typedef Core::Feature::FeatureTable FeatureTable;
00457
00458 ILOG_VAR(Impala.Application.Table.DoAppendFeatureTable);
00459 CmdOptions& options = CmdOptions::GetInstance();
00460 String dstName = options.GetArg(1);
00461 String srcName = options.GetArg(2);
00462 int nr = atol(options.GetArg(3));
00463
00464 Util::Database* db = &Util::Database::GetInstance();
00465 FeatureTable srcTable(srcName);
00466 Core::Table::Read(&srcTable, srcName, db);
00467
00468 FeatureTable dstTable(dstName, nr*srcTable.Size(),
00469 srcTable.GetFeatureVectorLength());
00470 for (int i=0 ; i<nr ; i++)
00471 dstTable.Append(&srcTable);
00472
00473 Core::Table::Write(&dstTable, dstName, db, true);
00474 }
00475
00476 void
00477 DoConcatFeatureTable()
00478 {
00479 typedef Core::Feature::FeatureDefinition FeatureDef;
00480 typedef Core::Feature::FeatureTable FeatureTable;
00481 typedef Core::Feature::FeatureTableSet FeatureTableSet;
00482
00483 ILOG_VAR(Impala.Application.Table.DoConcatFeatureTable);
00484 CmdOptions& options = CmdOptions::GetInstance();
00485 String dir = options.GetArg(1);
00486 bool useName = StringToBool(options.GetArg(2));
00487 FeatureDef resultDef(options.GetArg(3));
00488 String srcDefs = options.GetArg(4);
00489 for (int i=5 ; i<options.GetNrArg() ; i++)
00490 srcDefs += ";" + options.GetArg(i);
00491
00492 Util::Database* db = &Util::Database::GetInstance();
00493 FeatureTableSet* fSet = FeatureTableSet::MakeFromFile(dir, useName, srcDefs);
00494 FeatureTable* res = fSet->ConcatTables(resultDef);
00495 String fName = dir + "/";
00496 if (useName)
00497 fName += resultDef.GetName() + "/";
00498 fName += resultDef.AsString();
00499 Core::Table::Write(res, fName, db, true);
00500 fSet->Delete();
00501 delete fSet;
00502 delete res;
00503 }
00504
00505 void
00506 DoFeatureTable2Svm()
00507 {
00508 typedef Core::Feature::FeatureTable FeatureTable;
00509 typedef Core::Table::AnnotationTable AnnotationTable;
00510
00511 ILOG_VAR(Impala.Application.Table.DoFeatureTable2Svm);
00512 CmdOptions& options = CmdOptions::GetInstance();
00513 Util::Database* db = &Util::Database::GetInstance();
00514 if (options.GetNrArg() < 3)
00515 {
00516 ILOG_ERROR("Need more arguments");
00517 return;
00518 }
00519 String fName = options.GetArg(1);
00520 String svmName = options.GetArg(2);
00521 AnnotationTable* truth = 0;
00522 if (options.GetNrArg() > 3)
00523 {
00524 truth = AnnotationTable::MakeFromFile("", options.GetArg(3), db);
00525 }
00526 FeatureTable table(fName);
00527 Core::Table::Read(&table, fName, db);
00528 table.WriteSvmFile(svmName, db, truth);
00529 }
00530
00531 void
00532 DoFeatureTableReadAscii()
00533 {
00534 typedef Core::Feature::FeatureTable FeatureTable;
00535
00536 ILOG_VAR(Impala.Application.Table.DoFeatureTableReadAscii);
00537 CmdOptions& options = CmdOptions::GetInstance();
00538 Util::Database* db = &Util::Database::GetInstance();
00539 if (options.GetNrArg() < 3)
00540 {
00541 ILOG_ERROR("Need more arguments");
00542 return;
00543 }
00544 String tabName = options.GetArg(1);
00545 String asciiName = options.GetArg(2);
00546 FeatureTable table(tabName);
00547 table.ReadPlainAsciiFile(asciiName, db);
00548 Core::Table::Write(&table, tabName, db, true);
00549 }
00550
00551 void
00552 DoFeatureTableWriteAscii()
00553 {
00554 typedef Core::Feature::FeatureTable FeatureTable;
00555
00556 ILOG_VAR(Impala.Application.Table.DoFeatureTableWriteAscii);
00557 CmdOptions& options = CmdOptions::GetInstance();
00558 Util::Database* db = &Util::Database::GetInstance();
00559 if (options.GetNrArg() < 3)
00560 {
00561 ILOG_ERROR("Need more arguments");
00562 return;
00563 }
00564 String tabName = options.GetArg(1);
00565 String asciiName = options.GetArg(2);
00566 FeatureTable table(tabName);
00567 Core::Table::Read(&table, tabName, db);
00568 table.WritePlainAsciiFile(asciiName, db);
00569 }
00570
00571 void
00572 DoDiffFeatureTable()
00573 {
00574 typedef Core::Feature::FeatureTable FeatureTable;
00575
00576 ILOG_VAR(Impala.Application.Table.DoDiffFeatureTable);
00577 CmdOptions& options = CmdOptions::GetInstance();
00578 Util::Database* db = &Util::Database::GetInstance();
00579 String fName1 = options.GetArg(1);
00580 FeatureTable table1(fName1);
00581 Core::Table::Read(&table1, fName1, db);
00582 String fName2 = options.GetArg(2);
00583 FeatureTable table2(fName2);
00584 Core::Table::Read(&table2, fName2, db);
00585 if (table1.Size() != table2.Size())
00586 {
00587 ILOG_INFO("Different table sizes: " << table1.Size() << " vs "
00588 << table2.Size());
00589 return;
00590 }
00591 if (table1.GetFeatureVectorLength() != table2.GetFeatureVectorLength())
00592 {
00593 ILOG_INFO("Different vector length: " << table1.GetFeatureVectorLength()
00594 << " vs " << table2.GetFeatureVectorLength());
00595 return;
00596 }
00597 int verb = options.GetInt("verb");
00598 int nDiff = 0;
00599 for (int i=0 ; i<table1.Size() ; i++)
00600 {
00601 if (table1.Get1(i) != table2.Get1(i))
00602 {
00603 nDiff++;
00604 if (verb)
00605 ILOG_INFO("diff elem " << i << ": " << table1.Get1(i)
00606 << " vs " << table2.Get1(i));
00607 }
00608 FeatureTable::VectorReal64 v1(table1.Get2(i));
00609 FeatureTable::VectorReal64 v2(table2.Get2(i));
00610 Real64 dist = Core::Vector::Norm1Dist(v1, v2);
00611 if (IsNan(dist) || (dist > 0.00001))
00612 {
00613 nDiff++;
00614 if (verb)
00615 ILOG_INFO("diff elem " << i << ": " << table1.Get2(i)
00616 << " vs " << table2.Get2(i));
00617 }
00618 }
00619 if (nDiff > 0)
00620 ILOG_INFO("Found " << nDiff << " differences");
00621 }
00622
00623 void
00624 DoSimFeatureTable()
00625 {
00626 typedef Core::Feature::FeatureTable FeatureTable;
00627 typedef Core::Table::SimilarityTableSet SimilarityTableSet;
00628 typedef Core::Table::SimilarityTableSet::SimTableType SimTableType;
00629
00630 ILOG_VAR(Impala.Application.Table.DoSimFeatureTable);
00631 CmdOptions& options = CmdOptions::GetInstance();
00632 Util::Database* db = &Util::Database::GetInstance();
00633 if (options.GetNrArg() < 4)
00634 {
00635 ILOG_ERROR("Need more arguments");
00636 return;
00637 }
00638 String outDir = options.GetArg(1);
00639 String fName1 = options.GetArg(2);
00640 FeatureTable table1(fName1);
00641 ILOG_INFO("Reading " << fName1);
00642 Core::Table::Read(&table1, fName1, db);
00643 String fName2 = options.GetArg(3);
00644 FeatureTable table2(fName2);
00645 ILOG_INFO("Reading " << fName2);
00646 Core::Table::Read(&table2, fName2, db);
00647
00648 std::vector<String> names;
00649 for (int i=0 ; i<table1.Size() ; i++)
00650 names.push_back(QuidObj(table1.Get1(i)).ToString());
00651 ILOG_INFO("nrNames = " << names.size());
00652 SimilarityTableSet simSet(names, table2.Size());
00653 String outPath = outDir + "/";
00654 simSet.SaveNames(outPath, db);
00655 Core::Table::Copy(simSet.GetQuidTable(), &table2);
00656 simSet.SaveQuids(outPath, db, true);
00657 for (int i=0 ; i<names.size() ; i++)
00658 {
00659 ILOG_INFO("i = " << i);
00660 SimTableType* simTable = simSet.GetSimTable(i);
00661 Real64* sim = simTable->GetColumn1()->GetData();
00662 Core::Vector::Similarity(sim, table1.Get2(i),
00663 table2.GetColumn2(), 0, 1,
00664 Core::Vector::Norm1Dist<Real64>);
00665 simTable->SetSize(table2.Size());
00666 ILOG_INFO(" compute rank");
00667 simSet.ComputeRank(i, false);
00668 simSet.Save(i, outPath, db, true);
00669 }
00670 }
00671
00672 void
00673 DoSelectFeatureTableSet()
00674 {
00675 typedef Core::Feature::FeatureTableSet FeatureTableSet;
00676 typedef Core::Feature::FeatureTable FeatureTable;
00677
00678 ILOG_VAR(Impala.Application.Table.DoSelectFeatureTableSet);
00679 CmdOptions& options = CmdOptions::GetInstance();
00680 if (options.GetNrArg() < 5)
00681 {
00682 ILOG_ERROR("Need more parameters");
00683 return;
00684 }
00685
00686 String setName = options.GetArg(1);
00687 String resName = options.GetArg(2);
00688 int optimalSize = atol(options.GetArg(3));
00689 String feature = options.GetArg(4);
00690 Core::Database::RawDataSet* ds = Core::Database::MakeRawDataSet(setName);
00691
00692 Core::Feature::Computor* c = 0;
00693 if (feature == "weibull")
00694 c = new Core::Feature::VisSem("vissem", options);
00695 else if (feature == "gabor")
00696 c = new Core::Feature::VisSem("vissemgabor", options);
00697 else
00698 ILOG_ERROR("unknown feature : " << feature);
00699 c->ReadPrototypes(setName, "", -1);
00700
00701 std::vector<String> res;
00702 std::vector<int> resVal;
00703 for (int p=0 ; p<c->GetNrPixelFeatureSets() ; p++)
00704 {
00705 for (int r=0 ; r<c->GetNrRegionFeatureSets() ; r++)
00706 {
00707 std::cout << "p=" << p << " r=" << r << std::endl;
00708 std::vector<FeatureTable*> tabs = c->GetProtoFeatureTables(p, r);
00709 int bestIdx = -1;
00710 int bestVal = 0;
00711 for (int t=0 ; t<tabs.size() ; t++)
00712 {
00713 FeatureTable* tab = tabs[t];
00714 std::cout << " " << tab->GetFeatureDefinition().AsString()
00715 << " = " << tab->Size() << std::endl;
00716 int s = tab->Size();
00717 if (bestIdx == -1)
00718 {
00719 bestIdx = t;
00720 bestVal = s;
00721 continue;
00722 }
00723 if (s >= optimalSize)
00724 {
00725 if ((bestVal < optimalSize) || (s < bestVal))
00726 {
00727 bestIdx = t;
00728 bestVal = s;
00729 }
00730 }
00731 else
00732 {
00733 if ((bestVal < optimalSize) && (s > bestVal))
00734 {
00735 bestIdx = t;
00736 bestVal = s;
00737 }
00738 }
00739 }
00740 std::cout << " bestVal = " << bestVal << std::endl;
00741 String def = tabs[bestIdx]->GetFeatureDefinition().AsString();
00742 res.push_back(def);
00743 resVal.push_back(bestVal);
00744 }
00745 }
00746
00747 std::cout << std::endl << "Selection: " << std::endl;
00748 for (int i=0 ; i<res.size() ; i++)
00749 {
00750 std::cout << resVal[i] << " from " << res[i] << std::endl;
00751 }
00752 String fName = ds->GetFilePathPrototype(c->GetProtoDataFile(), c->GetName(),
00753 resName, true, false);
00754 if (!fName.empty())
00755 {
00756 std::cout << "Writing to " << fName << std::endl;
00757 Util::DatabaseWriteString(fName, ds->GetDatabase(), res.begin(),
00758 res.end());
00759 }
00760 }
00761
00762 void
00763 DoDumpAnnotationTable()
00764 {
00765 typedef Core::Table::AnnotationTable AnnotationTable;
00766
00767 CmdOptions& options = CmdOptions::GetInstance();
00768 String fName = options.GetArg(1);
00769 Core::Database::RawDataSet* dataSet = 0;
00770 String setName = options.GetString("videoSet");
00771 if (! setName.empty())
00772 dataSet = Core::VideoSet::MakeVideoSet(setName);
00773 setName = options.GetString("imageSet");
00774 if (! setName.empty())
00775 dataSet = Core::ImageSet::MakeImageSet(setName);
00776 Util::Database* db = &Util::Database::GetInstance();
00777 if (dataSet)
00778 db = dataSet->GetDatabase();
00779 AnnotationTable table;
00780 Core::Table::Read(&table, fName, db);
00781 table.Dump(dataSet, options.GetInt("start"), options.GetInt("end"));
00782 table.DumpSummary();
00783 }
00784
00785 void
00786 DoDumpAnnotationTableSet()
00787 {
00788 typedef Core::Table::AnnotationTableSet AnnotationTableSet;
00789 typedef Core::Table::AnnotationTable AnnotationTable;
00790
00791 ILOG_VAR(Impala.Application.Table.DoDumpAnnotationTableSet);
00792 CmdOptions& options = CmdOptions::GetInstance();
00793 if (options.GetNrArg() < 5)
00794 {
00795 ILOG_ERROR("Need more arguments");
00796 return;
00797 }
00798
00799 String setName = options.GetArg(1);
00800 Core::VideoSet::VideoSet* vidSet = Core::VideoSet::MakeVideoSet(setName);
00801 String conceptSet = options.GetArg(2);
00802 String quid = options.GetArg(3);
00803 bool dumpTable = atol(options.GetArg(4));
00804 int maxV = -1;
00805 if (options.GetNrArg() > 5)
00806 maxV = atol(options.GetArg(5));
00807 int maxP = -1;
00808 if (options.GetNrArg() > 6)
00809 maxP = atol(options.GetArg(6));
00810 int maxN = -1;
00811 if (options.GetNrArg() > 7)
00812 maxN = atol(options.GetArg(7));
00813
00814 AnnotationTableSet* tSet =
00815 Core::Table::AnnotationTableSet::MakeFromFile(vidSet, conceptSet, true,
00816 StringToQuidClass(quid));
00817 for (int i=0 ; i<tSet->Size() ; i++)
00818 {
00819 AnnotationTable* tab = tSet->GetTable(i);
00820 if (dumpTable)
00821 tab->Dump(vidSet, options.GetInt("start"), options.GetInt("end"));
00822 tab->DumpSummary();
00823 tab->DumpSummaryObject();
00824 if (maxV != -1)
00825 {
00826 tab->SelectQuidObjectMaxId(maxV);
00827 tab->SetLabel(tab->GetLabel() + "_maxV_" + MakeString(maxV));
00828 tab->DumpSummary();
00829 tab->DumpSummaryObject();
00830 }
00831 if (maxP != -1)
00832 {
00833 tab->SelectQuidObjectMaxPositive(maxP);
00834 tab->SetLabel(tab->GetLabel() + "_maxP_" + MakeString(maxP));
00835 tab->DumpSummary();
00836 tab->DumpSummaryObject();
00837 }
00838 if (maxN != -1)
00839 {
00840 tab->SelectQuidObjectMaxNegative(maxN);
00841 tab->SetLabel(tab->GetLabel() + "_maxN_" + MakeString(maxN));
00842 tab->DumpSummary();
00843 tab->DumpSummaryObject();
00844 }
00845 }
00846 delete tSet;
00847 }
00848
00849 void
00850 DoDiffAnnotationTable()
00851 {
00852 typedef Core::Table::AnnotationTable AnnotationTable;
00853
00854 ILOG_VAR(Impala.Application.Table.DoDiffAnnotationTable);
00855 CmdOptions& options = CmdOptions::GetInstance();
00856 Util::Database* db = &Util::Database::GetInstance();
00857 String fName1 = options.GetArg(1);
00858 AnnotationTable table1;
00859 Core::Table::Read(&table1, fName1, db);
00860 String fName2 = options.GetArg(2);
00861 AnnotationTable table2;
00862 Core::Table::Read(&table2, fName2, db);
00863 if (table1.Size() != table2.Size())
00864 {
00865 ILOG_INFO("Different table sizes: " << table1.Size() << " vs "
00866 << table2.Size());
00867 return;
00868 }
00869 int verb = options.GetInt("verb");
00870 int bOrder = options.GetBool("order", false);
00871 if (bOrder)
00872 {
00873 table1.UpdateQuidMap();
00874 table2.UpdateQuidMap();
00875 ILOG_INFO("Resorting annotation tables before comparsion");
00876 }
00877 int nDiff = 0;
00878 for (int i=0 ; i<table1.Size() ; i++)
00879 {
00880 if (table1.Get1(i) != table2.Get1(i))
00881 {
00882 nDiff++;
00883 if (verb)
00884 ILOG_INFO("diff elem " << i << ": " << table1.Get1(i)
00885 << " vs " << table2.Get1(i));
00886 }
00887 if (table1.Get2(i) != table2.Get2(i))
00888 {
00889 nDiff++;
00890 if (verb)
00891 ILOG_INFO("diff elem " << i << ": " << table1.Get2(i)
00892 << " vs " << table2.Get2(i));
00893 }
00894 }
00895 if (nDiff > 0)
00896 ILOG_INFO("Found " << nDiff << " differences");
00897 }
00898
00899 void
00900 DoDumpSimilarityTableSet()
00901 {
00902 typedef Core::Table::SimilarityTableSet SimilarityTableSet;
00903
00904 CmdOptions& options = CmdOptions::GetInstance();
00905 Core::Database::RawDataSet* dataSet = 0;
00906 String setName = options.GetString("videoSet");
00907 if (! setName.empty())
00908 dataSet = Core::VideoSet::MakeVideoSet(setName);
00909 setName = options.GetString("imageSet");
00910 if (! setName.empty())
00911 dataSet = Core::ImageSet::MakeImageSet(setName);
00912 Util::Database* db = &Util::Database::GetInstance();
00913 if (dataSet)
00914 db = dataSet->GetDatabase();
00915 String path = options.GetArg(1);
00916 SimilarityTableSet* simSet =
00917 Core::Table::SimilarityTableSet::MakeFromFile(path, db);
00918
00919 simSet->DumpRanking(dataSet, options.GetInt("start"), options.GetInt("end"));
00920 delete simSet;
00921 }
00922
00923 void
00924 DoDumpSimilarityTableSetTrec()
00925 {
00926 typedef Core::Table::SimilarityTableSet SimilarityTableSet;
00927
00928 ILOG_VAR(Impala.Application.Table.DoDumpSimilarityTableSetTrec);
00929 CmdOptions& options = CmdOptions::GetInstance();
00930 if (options.GetNrArg() < 3)
00931 {
00932 ILOG_ERROR("Need more parameters");
00933 return;
00934 }
00935
00936 String setName = options.GetArg(1);
00937 Core::VideoSet::VideoSet* vidSet = Core::VideoSet::MakeVideoSet(setName);
00938 Core::VideoSet::Keyframes keyframes(vidSet, "keyframes");
00939 String path = options.GetArg(2);
00940 SimilarityTableSet* simSet =
00941 Core::Table::SimilarityTableSet::MakeFromFile(path,
00942 vidSet->GetDatabase());
00943
00944 Core::Table::QuidTable* qTable = simSet->GetQuidTable();
00945 int start = options.GetInt("start");
00946 int end = options.GetInt("end");
00947 if ((end == -1) || (end > qTable->Size()))
00948 end = qTable->Size();
00949
00950 std::cout << "SimilarityTableSet " << simSet->GetDescription() << std::endl;
00951 for (int t=0 ; t<simSet->NrTables() ; t++)
00952 {
00953 SimilarityTableSet::SimTableType* simTable = simSet->GetSimTable(t);
00954 std::cout << "table " << t << ", name = " << simSet->GetName(t)
00955 << std::endl;
00956 if (simTable->Size() != qTable->Size())
00957 {
00958 ILOG_ERROR("DumpRanking: simtable size doesn't match");
00959 continue;
00960 }
00961 String concept = simSet->GetName(t);
00962 for (int i=start ; i<end ; i++)
00963 {
00964 Quid quid = qTable->Get1(i);
00965
00966 std::cout << concept << ", ";
00967 int keyId = keyframes.GetFrameId(quid);
00968 if (keyId != -1)
00969 std::cout << FileNameBase(keyframes.GetName(keyId)) << ", ";
00970 else
00971 std::cout << vidSet->QuidToString(quid, true) << ", ";
00972 std::cout << simTable->Get1(i) << std::endl;
00973 }
00974 std::cout << std::endl;
00975 }
00976 delete simSet;
00977 }
00978
00979 void
00980 DoImportSimilarityTableSet()
00981 {
00982 typedef Core::Table::SimilarityTableSet SimilarityTableSet;
00983 typedef Core::Table::SimilarityTableSet::SimTableType SimTableType;
00984
00985 ILOG_VAR(Impala.Application.Table.DoImportSimilarityTableSet);
00986 ILOG_ERROR("Will fail because doesn't have Quids (yet)");
00987 CmdOptions& options = CmdOptions::GetInstance();
00988 if (options.GetNrArg() < 5)
00989 {
00990 ILOG_ERROR("Need more arguments");
00991 return;
00992 }
00993 String outDir = options.GetArg(1);
00994 String conceptFile = options.GetArg(2);
00995 String inDir = options.GetArg(3);
00996 int nrIds = atol(options.GetArg(4));
00997 String fileExt("");
00998 if (options.GetNrArg() > 5)
00999 fileExt = options.GetArg(5);
01000 Util::Database* db = &Util::Database::GetInstance();
01001
01002 std::vector<String> concepts;
01003 Util::DatabaseReadString(std::back_inserter(concepts), conceptFile, db, true);
01004 ILOG_INFO("nrConcepts = " << concepts.size());
01005 SimilarityTableSet simSet(concepts, nrIds);
01006 String outPath = outDir + "/" + FileNameTail(conceptFile) + "/";
01007 simSet.SaveNames(outPath, db);
01008 for (int c=0 ; c<concepts.size() ; c++)
01009 {
01010 String fName = inDir + "/" + concepts[c] + fileExt;
01011 ILOG_INFO("importing " << concepts[c] << " from " << fName);
01012 std::vector<String> lines;
01013 Util::DatabaseReadString(std::back_inserter(lines), fName, db, true);
01014 if (lines.size() != nrIds)
01015 {
01016 ILOG_ERROR("wrong number of lines : " << lines.size() <<
01017 " instead of " << nrIds);
01018 continue;
01019 }
01020 SimTableType* simTable = simSet.GetSimTable(c);
01021 simTable->SetSize(0);
01022 for (int i=0 ; i<lines.size() ; i++)
01023 simTable->Add(atof(lines[i]));
01024 simSet.ComputeRank(c, true);
01025 simSet.Save(c, outPath, db, true);
01026 }
01027 }
01028
01029 void
01030 DoDiffSimilarityTableSet()
01031 {
01032 typedef Core::Table::SimilarityTableSet SimilarityTableSet;
01033 typedef Core::Table::SimilarityTableSet::SimTableType SimTableType;
01034 typedef Core::Table::SimilarityTableSet::RankTableType RankTableType;
01035
01036 ILOG_VAR(Impala.Application.Table.DoDiffSimilarityTableSet);
01037 CmdOptions& options = CmdOptions::GetInstance();
01038 Util::Database* db = &Util::Database::GetInstance();
01039 String fName1 = options.GetArg(1);
01040 SimilarityTableSet* simSet1 =
01041 Core::Table::SimilarityTableSet::MakeFromFile(fName1, db);
01042 String fName2 = options.GetArg(2);
01043 SimilarityTableSet* simSet2 =
01044 Core::Table::SimilarityTableSet::MakeFromFile(fName2, db);
01045 if (simSet1->NrTables() != simSet2->NrTables())
01046 {
01047 ILOG_INFO("Different nr tables: " << simSet1->NrTables() << " vs "
01048 << simSet2->NrTables());
01049 return;
01050 }
01051 if (simSet1->TableSize() != simSet2->TableSize())
01052 {
01053 ILOG_INFO("Different table size: " << simSet1->TableSize()
01054 << " vs " << simSet2->TableSize());
01055 return;
01056 }
01057 int verb = options.GetInt("verb");
01058 int nTableDiff = 0;
01059 Core::Table::QuidTable* qTable1 = simSet1->GetQuidTable();
01060 Core::Table::QuidTable* qTable2 = simSet2->GetQuidTable();
01061 int qDiff = 0;
01062 for (int i=0 ; i<qTable1->Size() ; i++)
01063 {
01064 if (qTable1->Get1(i) != qTable2->Get1(i))
01065 {
01066 qDiff++;
01067 if (verb)
01068 ILOG_INFO("quid table diff elem " << i << ": "
01069 << qTable1->Get1(i) << " vs " << qTable2->Get1(i));
01070 }
01071 }
01072 if (qDiff > 0)
01073 ILOG_INFO("Found " << qDiff << " differences in quid table");
01074 for (int t=0 ; t<simSet1->NrTables() ; t++)
01075 {
01076 int nDiff = 0;
01077 SimTableType* sTable1 = simSet1->GetSimTable(t);
01078 SimTableType* sTable2 = simSet2->GetSimTable(t);
01079 for (int i=0 ; i<sTable1->Size() ; i++)
01080 {
01081 if (::fabs(sTable1->Get1(i) - sTable2->Get1(i)) > 0.00001)
01082 {
01083 nDiff++;
01084 if (verb)
01085 ILOG_INFO("sim table " << t << ", diff elem " << i << ": "
01086 << sTable1->Get1(i) << " vs " << sTable2->Get1(i));
01087 }
01088 }
01089 if (nDiff > 0)
01090 ILOG_INFO("Found " << nDiff << " differences in sim table " <<
01091 simSet1->GetName(t));
01092
01093 nDiff = 0;
01094 RankTableType* rTable1 = simSet1->GetRankTable(t);
01095 RankTableType* rTable2 = simSet2->GetRankTable(t);
01096 for (int i=0 ; i<rTable1->Size() ; i++)
01097 {
01098 if (rTable1->Get1(i) != rTable2->Get1(i))
01099 {
01100 nDiff++;
01101 if (verb)
01102 ILOG_INFO("rank table " << t << ", diff elem " << i << ": "
01103 << rTable1->Get1(i) << " vs " << rTable2->Get1(i));
01104 }
01105 }
01106 if (nDiff > 0)
01107 ILOG_INFO("Found " << nDiff << " differences in rank table " <<
01108 simSet1->GetName(t));
01109 }
01110 }
01111
01112 void
01113 DoProcSimilarityTableSet()
01114 {
01115 typedef Core::Table::SimilarityTableSet SimilarityTableSet;
01116 typedef Core::Table::SimilarityTableSet::SimTableType SimTableType;
01117 typedef Core::Table::SimilarityTableSet::RankTableType RankTableType;
01118 typedef Core::Array::Array2dScalarReal64 ArrayType;
01119
01120 ILOG_VAR(Impala.Application.Table.DoProcSimilarityTableSet);
01121 CmdOptions& options = CmdOptions::GetInstance();
01122 if (options.GetNrArg() < 7)
01123 {
01124 ILOG_ERROR("Need more parameters");
01125 return;
01126 }
01127
01128 String setName = options.GetArg(1);
01129 Core::VideoSet::VideoSet* vidSet = Core::VideoSet::MakeVideoSet(setName);
01130 String walkType = options.GetArg(2);
01131 String conceptSet = options.GetArg(3);
01132 String model = options.GetArg(4);
01133 String feature = options.GetArg(5);
01134 int fileId = Impala::atol(options.GetArg(6));
01135
01136 SimilarityTableSet* srcSet = Core::Table::SimilarityTableSet::MakeFromFile
01137 (vidSet, walkType, conceptSet, model, feature, fileId);
01138
01139
01140 std::vector<String> srcNames = srcSet->GetNames();
01141 std::vector<String> dstNames;
01142 for (int i=0 ; i<srcNames.size() ; i++)
01143 {
01144 dstNames.push_back(srcNames[i]);
01145 dstNames.push_back(srcNames[i] + "_proc");
01146 }
01147 SimilarityTableSet* dstSet =
01148 new SimilarityTableSet(dstNames, srcSet->TableSize());
01149
01150
01151 Core::Table::Copy(dstSet->GetQuidTable(), srcSet->GetQuidTable());
01152 for (int t=0 ; t<srcSet->NrTables() ; t++)
01153 {
01154 SimTableType* srcTable = srcSet->GetSimTable(t);
01155 Core::Table::Copy(dstSet->GetSimTable(2*t), srcTable);
01156
01157 SimTableType* dstTable = dstSet->GetSimTable(2*t+1);
01158 Core::Table::Copy(dstTable, srcTable);
01159 ArrayType srcWrap(srcTable->Size(), 1, 0, 0,
01160 srcTable->GetColumn1()->GetData(), true);
01161 ArrayType* tmp = 0;
01162
01163
01164
01165 Core::Array::Percentile(tmp, &srcWrap, 5, 0.5);
01166 ArrayType* ker = Core::Array::ArrayCreate<ArrayType>(101, 1);
01167 Core::Matrix::MatSet(ker, 0);
01168 Core::Array::Erosion(tmp, tmp, ker);
01169 Core::Array::Dilation(tmp, tmp, ker);
01170 delete ker;
01171
01172 Real64* tmpPtr = tmp->CPB(0, 0);
01173 for (int i=tmp->CW()-1 ; i>=1 ; i--)
01174 {
01175 if (tmpPtr[i] == tmpPtr[i-1])
01176 tmpPtr[i] = 0;
01177 }
01178
01179 ker = Core::Array::ArrayCreate<ArrayType>(501, 1);
01180 Core::Matrix::MatSet(ker, 0);
01181 ArrayType* localMax = 0;
01182 Core::Array::Dilation(localMax, tmp, ker);
01183 Core::Array::Equals(localMax, localMax, tmp);
01184 Core::Array::Mul(tmp, localMax, tmp);
01185 delete ker;
01186 delete localMax;
01187
01188 ArrayType* dstWrap = new ArrayType(dstTable->Size(), 1, 0, 0,
01189 dstTable->GetColumn1()->GetData(), true);
01190 Core::Array::Set(dstWrap, tmp);
01191 delete dstWrap;
01192 delete tmp;
01193
01194 }
01195 dstSet->ComputeRanks(true);
01196 String con = FileNameBase(conceptSet) + "_proc." + FileNameExt(conceptSet);
01197 dstSet->Save(vidSet, walkType, con, model, feature, fileId, true);
01198 }
01199
01200 void
01201 DoMakeRandomSimilarityTableSet()
01202 {
01203 typedef Core::Table::SimilarityTableSet SimilarityTableSet;
01204 typedef Core::Table::SimilarityTableSet::SimTableType SimTableType;
01205
01206 ILOG_VAR(Impala.Application.Table.DoSimFeatureTable);
01207
01208
01209
01210 CmdOptions& options = CmdOptions::GetInstance();
01211 if (options.GetNrArg() < 2)
01212 {
01213 ILOG_ERROR("Need more arguments");
01214 return;
01215 }
01216 String setName = options.GetArg(1);
01217 Core::VideoSet::VideoSet* vidSet = Core::VideoSet::MakeVideoSet(setName);
01218 Core::VideoSet::Keyframes keyframes(vidSet, "keyframes");
01219
01220 std::vector<String> names;
01221 names.push_back("RandomKeyframes");
01222
01223
01224 for (int v=0 ; v<vidSet->NrFiles() ; v++)
01225 {
01226 int nrKeys = keyframes.GetNrKeyframesVideo(v);
01227 SimilarityTableSet simSet(names, nrKeys);
01228 int idx = 0;
01229 SimTableType* simTable = simSet.GetSimTable(idx);
01230 Core::Table::QuidTable* qTable = simSet.GetQuidTable();
01231 int firstKey = keyframes.GetFirstKeyframeVideo(v);
01232 for (int k=0 ; k<nrKeys ; k++)
01233 {
01234 Quid q = keyframes.GetQuidFrame(firstKey + k);
01235 qTable->Add(q);
01236 Real64 sim = (Real64) rand() / RAND_MAX;
01237 simTable->Add(sim);
01238 }
01239 simSet.ComputeRank(0, true);
01240 simSet.Save(vidSet, "Keyframes", "artificialConcepts.txt", "no_model",
01241 "Random", v, true);
01242 }
01243
01244 }
01245
01246 void
01247 DoDumpTaskTable()
01248 {
01249 typedef Core::VideoSet::TaskTable TaskTable;
01250
01251 CmdOptions& options = CmdOptions::GetInstance();
01252 Util::Database* db = &Util::Database::GetInstance();
01253 String fName = options.GetArg(1);
01254 TaskTable table(fName, db);
01255
01256 table.Dump(options.GetInt("start"), options.GetInt("end"));
01257 }
01258
01259 void
01260 DoDumpTableReal()
01261 {
01262 CmdOptions& options = CmdOptions::GetInstance();
01263 DoDump<Real64>(options.GetArg(1));
01264 }
01265
01266 void
01267 DoDumpTableInt()
01268 {
01269 CmdOptions& options = CmdOptions::GetInstance();
01270 DoDump<Int32>(options.GetArg(1));
01271 }
01272
01273 void
01274 DoDiffTableReal()
01275 {
01276 CmdOptions& options = CmdOptions::GetInstance();
01277 DoDiff<Real64>(options.GetArg(1), options.GetArg(2));
01278 }
01279
01280 void
01281 DoDiffTableInt()
01282 {
01283 CmdOptions& options = CmdOptions::GetInstance();
01284 DoDiff<Int32>(options.GetArg(1), options.GetArg(2));
01285 }
01286
01287 void
01288 DoDiffTableUInt64()
01289 {
01290 CmdOptions& options = CmdOptions::GetInstance();
01291 DoDiff<UInt64>(options.GetArg(1), options.GetArg(2));
01292 }
01293
01294 int
01295 mainTable(int argc, char* argv[])
01296 {
01297 CmdOptions& options = CmdOptions::GetInstance();
01298 options.Initialise(false, false, true);
01299 options.AddOption(0, "start", "nr", "0");
01300 options.AddOption(0, "end", "nr", "-1");
01301 options.AddOption(0, "order", "", "false");
01302 String usageStr = "cmd = \n\n";
01303 usageStr += " vxstable file.vxs\n";
01304 usageStr += " diffsegmentation tablename1 tablename2\n";
01305 usageStr += " diffkeyframes tablename1 tablename2\n";
01306 usageStr += " diffstills tablename1 tablename2\n";
01307 usageStr += " dumpquidtable tablename [doGroup]\n";
01308 usageStr += " dumpfeaturetable tablename [doRewrite]\n";
01309 usageStr += " convertfeaturetableold tablename\n";
01310 usageStr += " scalefeaturetable tablename scaledtablename minmaxtablename\n";
01311 usageStr += " concatfeaturetable dir useName resultDef tableDefs\n";
01312 usageStr += " featuretable2svm tablename svmname [concept.truth]\n";
01313 usageStr += " featuretablereadascii tablename asciiname\n";
01314 usageStr += " featuretablewriteascii tablename asciiname\n";
01315 usageStr += " difffeaturetable tablename1 tablename2\n";
01316 usageStr += " simfeaturetable outDir tablename1 tablename2\n";
01317 usageStr += " selectfeaturetableset dataset.txt feature output.txt\n";
01318 usageStr += " dumpannotationtable tablename\n";
01319 usageStr += " dumpannotationtableset videoset.txt conceptSet.txt quidClass doTable [maxVidId maxPos maxNeg]\n";
01320 usageStr += " diffannotationtable tablename1 tablename2\n";
01321 usageStr += " dumpsimilaritytableset names.txt\n";
01322 usageStr += " dumpsimilaritytablesettrec videoset.txt names.txt\n";
01323 usageStr += " importsimilaritytableset outdir concepts indir nrIds [fileext]\n";
01324 usageStr += " diffsimilaritytableset names1.txt names2.txt\n";
01325 usageStr += " procsimilaritytableset videoset.txt walkType concepts.txt model feature fileId\n";
01326 usageStr += " makerandomsimilaritytableset videoset.txt\n";
01327 usageStr += " dumptasktable tablename\n";
01328 usageStr += " dumptablereal tablename\n";
01329 usageStr += " dumptableint tablename\n";
01330 usageStr += " difftablereal tablename1 tablename2\n";
01331 usageStr += " difftableint tablename1 tablename2\n";
01332 usageStr += " difftableuint64 tablename1 tablename2\n";
01333 if (! options.ParseArgs(argc, argv, usageStr, 1))
01334 return 1;
01335
01336 ILOG_VAR(Impala.Application.mainTable);
01337
01338 String cmd = options.GetArg(0);
01339 ILOG_DEBUG("table command : " << cmd);
01340
01341 if (cmd == "vxstable")
01342 DoVxsTable();
01343 else if (cmd == "diffsegmentation")
01344 DoDiffSegmentation();
01345 else if (cmd == "diffkeyframes")
01346 DoDiffKeyframes();
01347 else if (cmd == "diffstills")
01348 DoDiffStills();
01349 else if (cmd == "dumpquidtable")
01350 DoDumpQuidTable();
01351 else if (cmd == "dumpfeaturetable")
01352 DoDumpFeatureTable();
01353 else if (cmd == "scalefeaturetable")
01354 DoScaleFeatureTable();
01355 else if (cmd == "append")
01356 DoAppendFeatureTable();
01357 else if (cmd == "concatfeaturetable")
01358 DoConcatFeatureTable();
01359 else if (cmd == "featuretable2svm")
01360 DoFeatureTable2Svm();
01361 else if (cmd == "featuretablereadascii")
01362 DoFeatureTableReadAscii();
01363 else if (cmd == "featuretablewriteascii")
01364 DoFeatureTableWriteAscii();
01365 else if (cmd == "difffeaturetable")
01366 DoDiffFeatureTable();
01367 else if (cmd == "simfeaturetable")
01368 DoSimFeatureTable();
01369 else if (cmd == "selectfeaturetableset")
01370 DoSelectFeatureTableSet();
01371 else if (cmd == "dumpannotationtable")
01372 DoDumpAnnotationTable();
01373 else if (cmd == "dumpannotationtableset")
01374 DoDumpAnnotationTableSet();
01375 else if (cmd == "diffannotationtable")
01376 DoDiffAnnotationTable();
01377 else if (cmd == "dumpsimilaritytableset")
01378 DoDumpSimilarityTableSet();
01379 else if (cmd == "dumpsimilaritytablesettrec")
01380 DoDumpSimilarityTableSetTrec();
01381 else if (cmd == "importsimilaritytableset")
01382 DoImportSimilarityTableSet();
01383 else if (cmd == "diffsimilaritytableset")
01384 DoDiffSimilarityTableSet();
01385 else if (cmd == "procsimilaritytableset")
01386 DoProcSimilarityTableSet();
01387 else if (cmd == "makerandomsimilaritytableset")
01388 DoMakeRandomSimilarityTableSet();
01389 else if (cmd == "dumptasktable")
01390 DoDumpTaskTable();
01391 else if (cmd == "dumptablereal")
01392 DoDumpTableReal();
01393 else if (cmd == "dumptableint")
01394 DoDumpTableInt();
01395 else if (cmd == "difftablereal")
01396 DoDiffTableReal();
01397 else if (cmd == "difftableint")
01398 DoDiffTableInt();
01399 else if (cmd == "difftableuint64")
01400 DoDiffTableUInt64();
01401 else ILOG_ERROR("Unknown cmd : " << cmd);
01402
01403 return 0;
01404 }
01405
01406 }
01407 }
01408 }
01409
01410 int
01411 main(int argc, char* argv[])
01412 {
01413 return Impala::Application::Table::mainTable(argc, argv);
01414 }