KSquare Utilities
FeatureVectorProducer.cpp
Go to the documentation of this file.
1 #include "FirstIncludes.h"
2 #include <ctype.h>
3 #include <math.h>
4 #include <time.h>
5 #include <string>
6 #include <iostream>
7 #include <fstream>
8 #include <map>
9 #include <vector>
10 #include <string.h>
11 #include <typeinfo>
12 #include "MemoryDebug.h"
13 using namespace std;
14 
15 #include "GlobalGoalKeeper.h"
16 #include "ImageIO.h"
17 #include "KKBaseTypes.h"
18 using namespace KKB;
19 
20 
21 
23 #include "FeatureVector.h"
24 using namespace KKMLL;
25 
26 
27 
29  FactoryFVProducerPtr _factory /**< Pointer to factory that instantiated this instance. */
30  ):
31  factory (_factory),
32  fileDesc (NULL),
33  name (_name)
34 {
35 }
36 
37 
38 
39 
41 {
42 }
43 
44 
45 
46 
47 FeatureVectorPtr FeatureVectorProducer::ComputeFeatureVectorFromImage (const KKStr& fileName,
48  const MLClassPtr knownClass,
49  RasterListPtr intermediateImages,
50  RunLog& runLog
51  )
52 {
53  FeatureVectorPtr fv = NULL;
54 
55  RasterPtr i = KKB::ReadImage (fileName);
56  if (i == NULL)
57  {
58  runLog.Level (-1) << "FeatureVectorProducer::ComputeFeatureVectorFromImage ***ERROR*** Error loading ImageFile: " << fileName << endl << endl;
59  }
60  else
61  {
62  fv = ComputeFeatureVector (*i, knownClass, intermediateImages, 1.0f, runLog);
63  delete i;
64  i = NULL;
65  }
66 
67  return fv;
68 } /* ComputeFeatureVectorFromImage */
69 
70 
71 
72 
73 
74 FileDescConstPtr FeatureVectorProducer::FileDesc () const
75 {
76  if (!fileDesc)
77  {
79  if (!fileDesc)
80  {
81  fileDesc = DefineFileDesc ();
82  fileDesc = FileDesc::GetExistingFileDesc (fileDesc);
83  }
85  }
86  return fileDesc;
87 }
88 
89 
90 
91 
92 
94 {
95  if (!fileDesc)
96  return 0;
97  else
98  return fileDesc->NumOfFields ();
99 }
100 
101 
102 
104 {
105  if (fileDesc == NULL)
106  return KKStr::EmptyStr ();
107 
108  if (fieldNum >= fileDesc->NumOfFields ())
109  return KKStr::EmptyStr ();
110  else
111  return fileDesc->FieldName (fieldNum);
112 }
113 
114 
115 
116 
117 bool FeatureVectorProducer::atExitDefined = false;
Provides a detailed description of the attributes of a dataset.
Definition: FileDesc.h:72
static FileDescPtr GetExistingFileDesc(FileDescPtr fileDesc)
Returns a pointer to an existing instance of &#39;fileDesc&#39; if it exists, otherwise will use one being pa...
Definition: FileDesc.cpp:555
kkuint32 NumOfFields() const
Definition: FileDesc.h:197
FileDescConstPtr FileDesc() const
Returns back a "FileDesc" instance that describes the features that this instance of &#39;FeatureVectorPr...
virtual FileDescPtr DefineFileDesc() const =0
const KKStr & FieldName(kkint32 fieldNum) const
Definition: FileDesc.cpp:387
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
RasterPtr ReadImage(const KKStr &imageFileName)
Definition: ImageIO.cpp:188
const KKStr & FeatureName(kkuint32 fieldNum) const
KKTHread * KKTHreadPtr
RasterList * RasterListPtr
Definition: Raster.h:75
KKStr(const KKStr &str)
Copy Constructor.
Definition: KKStr.cpp:561
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
virtual FeatureVectorPtr ComputeFeatureVector(const Raster &image, const MLClassPtr knownClass, RasterListPtr intermediateImages, float priorReductionFactor, RunLog &runLog)=0
Compute a FeatureVector for the supplied &#39;image&#39;.
virtual FeatureVectorPtr ComputeFeatureVectorFromImage(const KKStr &fileName, const MLClassPtr knownClass, RasterListPtr intermediateImages, RunLog &runLog)
Compute a FeatureVector from the image file specified by &#39;fileName&#39;.
static const KKStr & EmptyStr()
Static method that returns an Empty String.
Definition: KKStr.cpp:3453
FeatureVectorProducer(const KKStr &_name, FactoryFVProducerPtr _factory)
Used for logging messages.
Definition: RunLog.h:49
void EncodeProblem(const struct svm_paramater &param, struct svm_problem &prob_in, struct svm_problem &prob_out)
Maintains one instance of a GoalKeeper object that can be used anywhere in the application.
A abstract class that is meant to compute a FeatureVector from a source image.