Commit a702e5b2 authored by Ilya Lysenkov's avatar Ilya Lysenkov

Storing PCA components and One Way descriptors in one yml file.

parent 08c377cb
...@@ -1024,6 +1024,12 @@ public: ...@@ -1024,6 +1024,12 @@ public:
const char* pca_hr_config = 0, const char* pca_desc_config = 0, int pyr_levels = 1, const char* pca_hr_config = 0, const char* pca_desc_config = 0, int pyr_levels = 1,
int pca_dim_high = 100, int pca_dim_low = 100); int pca_dim_high = 100, int pca_dim_low = 100);
OneWayDescriptorBase(CvSize patch_size, int pose_count, const string &pca_filename, const string &train_path = string(), const string &images_list = string(),
int pyr_levels = 1,
int pca_dim_high = 100, int pca_dim_low = 100);
~OneWayDescriptorBase(); ~OneWayDescriptorBase();
// Allocate: allocates memory for a given number of descriptors // Allocate: allocates memory for a given number of descriptors
...@@ -1111,6 +1117,15 @@ public: ...@@ -1111,6 +1117,15 @@ public:
// - filename: output filename // - filename: output filename
void SavePCADescriptors(const char* filename); void SavePCADescriptors(const char* filename);
// SavePCADescriptors: saves PCA descriptors to a file storage
// - fs: output file storage
void SavePCADescriptors(CvFileStorage* fs);
// GeneratePCA: calculate and save PCA components and descriptors
// - img_path: path to training PCA images directory
// - images_list: filename with filenames of training PCA images
void GeneratePCA(const char* img_path, const char* images_list);
// SetPCAHigh: sets the high resolution pca matrices (copied to internal structures) // SetPCAHigh: sets the high resolution pca matrices (copied to internal structures)
void SetPCAHigh(CvMat* avg, CvMat* eigenvectors); void SetPCAHigh(CvMat* avg, CvMat* eigenvectors);
...@@ -1129,6 +1144,8 @@ public: ...@@ -1129,6 +1144,8 @@ public:
void ConvertDescriptorsArrayToTree(); // Converting pca_descriptors array to KD tree void ConvertDescriptorsArrayToTree(); // Converting pca_descriptors array to KD tree
// GetPCAFilename: get default PCA filename
static string GetPCAFilename () { return "pca.yml"; }
protected: protected:
CvSize m_patch_size; // patch size CvSize m_patch_size; // patch size
...@@ -1151,7 +1168,6 @@ protected: ...@@ -1151,7 +1168,6 @@ protected:
int m_pca_dim_low; int m_pca_dim_low;
int m_pyr_levels; int m_pyr_levels;
}; };
class CV_EXPORTS OneWayDescriptorObject : public OneWayDescriptorBase class CV_EXPORTS OneWayDescriptorObject : public OneWayDescriptorBase
...@@ -1168,6 +1184,11 @@ public: ...@@ -1168,6 +1184,11 @@ public:
OneWayDescriptorObject(CvSize patch_size, int pose_count, const char* train_path, const char* pca_config, OneWayDescriptorObject(CvSize patch_size, int pose_count, const char* train_path, const char* pca_config,
const char* pca_hr_config = 0, const char* pca_desc_config = 0, int pyr_levels = 1); const char* pca_hr_config = 0, const char* pca_desc_config = 0, int pyr_levels = 1);
OneWayDescriptorObject(CvSize patch_size, int pose_count, const string &pca_filename,
const string &train_path = string (), const string &images_list = string (), int pyr_levels = 1);
~OneWayDescriptorObject(); ~OneWayDescriptorObject();
// Allocate: allocates memory for a given number of features // Allocate: allocates memory for a given number of features
...@@ -1690,19 +1711,20 @@ public: ...@@ -1690,19 +1711,20 @@ public:
Params( int _poseCount = POSE_COUNT, Params( int _poseCount = POSE_COUNT,
Size _patchSize = Size(PATCH_WIDTH, PATCH_HEIGHT), Size _patchSize = Size(PATCH_WIDTH, PATCH_HEIGHT),
string _pcaFilename = string (),
string _trainPath = string(), string _trainPath = string(),
string _pcaConfig = string(), string _pcaHrConfig = string(), string _trainImagesList = string(),
string _pcaDescConfig = string(),
float _minScale = GET_MIN_SCALE(), float _maxScale = GET_MAX_SCALE(), float _minScale = GET_MIN_SCALE(), float _maxScale = GET_MAX_SCALE(),
float _stepScale = GET_STEP_SCALE() ) : float _stepScale = GET_STEP_SCALE() ) :
poseCount(_poseCount), patchSize(_patchSize), trainPath(_trainPath), poseCount(_poseCount), patchSize(_patchSize), pcaFilename(_pcaFilename),
pcaConfig(_pcaConfig), pcaHrConfig(_pcaHrConfig), pcaDescConfig(_pcaDescConfig), trainPath(_trainPath), trainImagesList(_trainImagesList),
minScale(_minScale), maxScale(_maxScale), stepScale(_stepScale) {} minScale(_minScale), maxScale(_maxScale), stepScale(_stepScale) {}
int poseCount; int poseCount;
Size patchSize; Size patchSize;
string pcaFilename;
string trainPath; string trainPath;
string pcaConfig, pcaHrConfig, pcaDescConfig; string trainImagesList;
float minScale, maxScale, stepScale; float minScale, maxScale, stepScale;
}; };
......
...@@ -203,9 +203,8 @@ void OneWayDescriptorMatch::initialize( const Params& _params) ...@@ -203,9 +203,8 @@ void OneWayDescriptorMatch::initialize( const Params& _params)
void OneWayDescriptorMatch::add( const Mat& image, vector<KeyPoint>& keypoints ) void OneWayDescriptorMatch::add( const Mat& image, vector<KeyPoint>& keypoints )
{ {
if( base.empty() ) if( base.empty() )
base = new OneWayDescriptorObject( params.patchSize, params.poseCount, params.trainPath.c_str(), base = new OneWayDescriptorObject( params.patchSize, params.poseCount, params.pcaFilename,
params.pcaConfig.c_str(), params.pcaHrConfig.c_str(), params.trainPath, params.trainImagesList);
params.pcaDescConfig.c_str());
size_t trainFeatureCount = keypoints.size(); size_t trainFeatureCount = keypoints.size();
...@@ -225,9 +224,8 @@ void OneWayDescriptorMatch::add( const Mat& image, vector<KeyPoint>& keypoints ) ...@@ -225,9 +224,8 @@ void OneWayDescriptorMatch::add( const Mat& image, vector<KeyPoint>& keypoints )
void OneWayDescriptorMatch::add( KeyPointCollection& keypoints ) void OneWayDescriptorMatch::add( KeyPointCollection& keypoints )
{ {
if( base.empty() ) if( base.empty() )
base = new OneWayDescriptorObject( params.patchSize, params.poseCount, params.trainPath.c_str(), base = new OneWayDescriptorObject( params.patchSize, params.poseCount, params.pcaFilename,
params.pcaConfig.c_str(), params.pcaHrConfig.c_str(), params.trainPath, params.trainImagesList);
params.pcaDescConfig.c_str());
size_t trainFeatureCount = keypoints.calcKeypointCount(); size_t trainFeatureCount = keypoints.calcKeypointCount();
......
This diff is collapsed.
This diff is collapsed.
one_way_train_0000.jpg
one_way_train_0001.jpg
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment