Fix missing format when writing Algorithm-based objects

Added a writeFormat() method to Algorithm which must be called by the
write() method of derived classes.
This commit is contained in:
mvukad 2016-03-22 15:19:42 -07:00
parent fd1b66b37d
commit 695e33b25b
33 changed files with 47 additions and 1 deletions

View File

@ -1225,6 +1225,7 @@ public:
void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << name_
<< "minDisparity" << params.minDisparity
<< "numDisparities" << params.numDisparities

View File

@ -1512,6 +1512,7 @@ public:
void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << name_
<< "minDisparity" << params.minDisparity
<< "numDisparities" << params.numDisparities

View File

@ -3059,6 +3059,9 @@ public:
/** Returns the algorithm string identifier.
This string is used as top level xml/yml node tag when the object is saved to a file or string. */
CV_WRAP virtual String getDefaultName() const;
protected:
void writeFormat(FileStorage& fs) const;
};
struct Param {

View File

@ -57,7 +57,6 @@ void Algorithm::save(const String& filename) const
{
FileStorage fs(filename, FileStorage::WRITE);
fs << getDefaultName() << "{";
fs << "format" << (int)3;
write(fs);
fs << "}";
}
@ -67,6 +66,11 @@ String Algorithm::getDefaultName() const
return String("my_object");
}
void Algorithm::writeFormat(FileStorage& fs) const
{
fs << "format" << (int)3;
}
}
/* End of file. */

View File

@ -93,6 +93,7 @@ namespace
void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << "Canny_CUDA"
<< "low_thresh" << low_thresh_
<< "high_thresh" << high_thresh_

View File

@ -99,6 +99,7 @@ namespace
void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << "HoughCirclesDetector_CUDA"
<< "dp" << dp_
<< "minDist" << minDist_

View File

@ -95,6 +95,7 @@ namespace
void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << "HoughLinesDetector_CUDA"
<< "rho" << rho_
<< "theta" << theta_

View File

@ -98,6 +98,7 @@ namespace
void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << "PHoughLinesDetector_CUDA"
<< "rho" << rho_
<< "theta" << theta_

View File

@ -217,6 +217,7 @@ namespace cv
void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "descriptor" << descriptor;
fs << "descriptor_channels" << descriptor_channels;
fs << "descriptor_size" << descriptor_size;

View File

@ -184,6 +184,7 @@ void SimpleBlobDetectorImpl::read( const cv::FileNode& fn )
void SimpleBlobDetectorImpl::write( cv::FileStorage& fs ) const
{
writeFormat(fs);
params.write(fs);
}

View File

@ -159,6 +159,7 @@ namespace cv
void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "extended" << (int)extended;
fs << "upright" << (int)upright;
fs << "threshold" << threshold;

View File

@ -1179,6 +1179,7 @@ void FlannBasedMatcher::read( const FileNode& fn)
void FlannBasedMatcher::write( FileStorage& fs) const
{
writeFormat(fs);
fs << "indexParams" << "[";
if (indexParams)

View File

@ -1151,6 +1151,7 @@ public:
return;
int i, l_count = layer_count();
writeFormat(fs);
fs << "layer_sizes" << layer_sizes;
write_params( fs );

View File

@ -387,6 +387,7 @@ public:
if( roots.empty() )
CV_Error( CV_StsBadArg, "RTrees have not been trained" );
writeFormat(fs);
writeParams(fs);
int k, ntrees = (int)roots.size();

View File

@ -770,6 +770,7 @@ public:
void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "training_params" << "{";
write_params(fs);
fs << "}";

View File

@ -466,6 +466,7 @@ public:
void write( FileStorage& fs ) const
{
writeFormat(fs);
impl->write(fs);
}

View File

@ -547,6 +547,7 @@ void LogisticRegressionImpl::write(FileStorage& fs) const
{
CV_Error(CV_StsBadArg,"file can't open. Check file path");
}
writeFormat(fs);
string desc = "Logisitic Regression Classifier";
fs<<"classifier"<<desc.c_str();
fs<<"alpha"<<this->params.alpha;

View File

@ -342,6 +342,7 @@ public:
{
int nclasses = (int)cls_labels.total(), i;
writeFormat(fs);
fs << "var_count" << (var_idx.empty() ? nallvars : (int)var_idx.total());
fs << "var_all" << nallvars;

View File

@ -296,6 +296,7 @@ public:
if( roots.empty() )
CV_Error( CV_StsBadArg, "RTrees have not been trained" );
writeFormat(fs);
writeParams(fs);
fs << "oob_error" << oobError;

View File

@ -2037,6 +2037,7 @@ public:
if( !isTrained() )
CV_Error( CV_StsParseError, "SVM model data is invalid, check sv_count, var_* and class_count tags" );
writeFormat(fs);
write_params( fs );
fs << "var_count" << var_count;

View File

@ -364,6 +364,7 @@ void SVMSGDImpl::write(FileStorage& fs) const
if( !isTrained() )
CV_Error( CV_StsParseError, "SVMSGD model data is invalid, it hasn't been trained" );
writeFormat(fs);
writeParams( fs );
fs << "weights" << weights_;

View File

@ -1681,6 +1681,7 @@ void DTreesImpl::writeTree( FileStorage& fs, int root ) const
void DTreesImpl::write( FileStorage& fs ) const
{
writeFormat(fs);
writeParams(fs);
writeTree(fs, roots[0]);
}

View File

@ -184,6 +184,7 @@ public:
void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << name
<< "max_bits" << max_bits
<< "exclude_range" << exclude_range

View File

@ -141,6 +141,7 @@ public:
void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << name
<< "samples" << samples
<< "lambda" << lambda
@ -250,6 +251,7 @@ public:
void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << name
<< "max_iter" << max_iter
<< "threshold" << threshold;

View File

@ -265,6 +265,7 @@ public:
void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << name
<< "contrast_weight" << wcon
<< "saturation_weight" << wsat

View File

@ -83,6 +83,7 @@ public:
void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << name
<< "gamma" << gamma;
}
@ -161,6 +162,7 @@ public:
void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << name
<< "gamma" << gamma
<< "bias" << bias
@ -242,6 +244,7 @@ public:
void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << name
<< "gamma" << gamma
<< "contrast" << contrast
@ -339,6 +342,7 @@ public:
void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << name
<< "gamma" << gamma
<< "intensity" << intensity
@ -446,6 +450,7 @@ public:
void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << name
<< "gamma" << gamma
<< "scale" << scale

View File

@ -79,6 +79,7 @@ public:
//! write/read
virtual void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << name_
<< "affine_type" << int(fullAffine);
}

View File

@ -77,6 +77,7 @@ public:
//! write/read
virtual void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << name_
<< "distance" << distanceFlag
<< "rank" << rankProportion;

View File

@ -99,6 +99,7 @@ public:
//! write/read
virtual void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << name_
<< "flag" << flag
<< "dummies" << nDummies
@ -224,6 +225,7 @@ public:
//! write/read
virtual void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << name_
<< "flag" << flag
<< "dummies" << nDummies
@ -350,6 +352,7 @@ public:
//! write/read
virtual void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << name_
<< "dummies" << nDummies
<< "default" << defaultCost;
@ -466,6 +469,7 @@ public:
//! write/read
virtual void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << name_
<< "dummies" << nDummies
<< "default" << defaultCost;

View File

@ -137,6 +137,7 @@ public:
//! write/read
virtual void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << name_
<< "nRads" << nRadialBins
<< "nAngs" << nAngularBins

View File

@ -81,6 +81,7 @@ public:
//! write/read
virtual void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << name_
<< "regularization" << regularizationParameter;
}

View File

@ -183,6 +183,7 @@ public:
virtual void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << name_
<< "history" << history
<< "nsamples" << nN

View File

@ -286,6 +286,7 @@ public:
virtual void write(FileStorage& fs) const
{
writeFormat(fs);
fs << "name" << name_
<< "history" << history
<< "nmixtures" << nmixtures