Home || Visual Search || Applications || Architecture || Important Messages || OGL || Src

ReadCodebook.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Feature_ReadCodebook_h
00002 #define Impala_Core_Feature_ReadCodebook_h
00003 
00004 #include "Core/Feature/FeatureTable.h"
00005 #include "Core/Feature/PointDescriptorIO.h"
00006 #include "Core/Matrix/Mat.h"
00007 
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace Feature
00013 {
00014 
00015 
00016 FeatureTable*
00017 ReadCodebookFromBuffer(Util::IOBuffer* buf)
00018 {
00019     ILOG_VAR(Impala.Core.Feature.ReadCodebookFromBuffer);
00020 
00021     using namespace Matrix;
00022 
00023     FeatureTable* result = 0;
00024     buf->Seek(0, SEEK_SET);
00025     char buf2[2049];
00026     buf2[2048] = '\0';
00027     buf->Read(buf2, 2048);
00028     buf->Seek(0, SEEK_SET);
00029     String recognizer(buf2);
00030     if(recognizer.find("nr strings") != String::npos)
00031     {   // nr strings : then FeatureTableOld
00032         typedef Table::TableTem<Column::ColumnTem<String>,
00033                         Vector::VectorSet<Array::Array2dScalarReal64> >
00034                         FeatureTableOldType;
00035         FeatureTableOldType* oldCodebook = new FeatureTableOldType(
00036                  Column::ColumnTem<String>(0),
00037                  Vector::VectorSet<Array::Array2dScalarReal64>(true, 1, 0));
00038         Read(oldCodebook, buf);
00039         
00040         int d = oldCodebook->GetColumn2()->GetVectorLength(0);
00041         // need to copy oldCodebook into result
00042         result = new FeatureTable(FeatureDefinition(""), 
00043                                oldCodebook->Size(), 
00044                                d);
00045         Mat* matrixCodebook = oldCodebook->GetColumn2()->GetStorage();
00046         for(int i = 0; i < oldCodebook->Size(); i++)
00047         {
00048             Quid q = MakeQuidCodebook(0, 0, i);
00049             Core::Vector::VectorTem<Real64>
00050                 v(d);
00051             for(int j = 0; j < d; j++)
00052             {
00053                 v[j] = *MatE(matrixCodebook, i, j);
00054             }
00055             result->Add(q, v);
00056         }
00057         ILOG_WARN("Codebook is in an old format. Future versions might not work.");
00058     }
00059     else if(recognizer.substr(0,5) == String("KOEN1") || 
00060             recognizer.substr(0,8) == String("BINDESC1"))
00061     {
00062         // other format
00063         buf->Seek(0, SEEK_SET);
00064         Mat* ignored = 0;
00065         Mat* descriptors = 0;
00066         ReadBINDESC1FromBuffer(ignored, descriptors, buf, false, true);
00067         result = new FeatureTable(FeatureDefinition(""),
00068                                   MatNrRow(descriptors), 
00069                                   MatNrCol(descriptors));
00070         for(int i = 0; i < MatNrRow(descriptors); i++)
00071         {
00072             Vector::VectorTem<Real64> v(MatNrCol(descriptors), 
00073                                         MatE(descriptors, i, 0),
00074                                         true);
00075             result->Add(i, v);
00076         }
00077         delete descriptors;
00078     }
00079     else
00080     {
00081         result = new FeatureTable(FeatureDefinition(""));
00082         Read(result, buf);
00083     }
00084     return result;
00085 }
00086 
00087 
00088 } // namespace Feature
00089 } // namespace Core
00090 } // namespace Impala
00091 
00092 #endif

Generated on Thu Jan 13 09:04:26 2011 for ImpalaSrc by  doxygen 1.5.1