Commit 1307bb1d authored by Maksim Shabunin's avatar Maksim Shabunin

Merge pull request #6314 from mvukad:bugfix_dtreeswrite

parents 2b29db86 695e33b2
...@@ -1225,6 +1225,7 @@ public: ...@@ -1225,6 +1225,7 @@ public:
void write(FileStorage& fs) const void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << name_ fs << "name" << name_
<< "minDisparity" << params.minDisparity << "minDisparity" << params.minDisparity
<< "numDisparities" << params.numDisparities << "numDisparities" << params.numDisparities
......
...@@ -1512,6 +1512,7 @@ public: ...@@ -1512,6 +1512,7 @@ public:
void write(FileStorage& fs) const void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << name_ fs << "name" << name_
<< "minDisparity" << params.minDisparity << "minDisparity" << params.minDisparity
<< "numDisparities" << params.numDisparities << "numDisparities" << params.numDisparities
......
...@@ -3067,6 +3067,9 @@ public: ...@@ -3067,6 +3067,9 @@ public:
/** Returns the algorithm string identifier. /** 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. */ 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; CV_WRAP virtual String getDefaultName() const;
protected:
void writeFormat(FileStorage& fs) const;
}; };
struct Param { struct Param {
......
...@@ -57,7 +57,6 @@ void Algorithm::save(const String& filename) const ...@@ -57,7 +57,6 @@ void Algorithm::save(const String& filename) const
{ {
FileStorage fs(filename, FileStorage::WRITE); FileStorage fs(filename, FileStorage::WRITE);
fs << getDefaultName() << "{"; fs << getDefaultName() << "{";
fs << "format" << (int)3;
write(fs); write(fs);
fs << "}"; fs << "}";
} }
...@@ -67,6 +66,11 @@ String Algorithm::getDefaultName() const ...@@ -67,6 +66,11 @@ String Algorithm::getDefaultName() const
return String("my_object"); return String("my_object");
} }
void Algorithm::writeFormat(FileStorage& fs) const
{
fs << "format" << (int)3;
}
} }
/* End of file. */ /* End of file. */
...@@ -93,6 +93,7 @@ namespace ...@@ -93,6 +93,7 @@ namespace
void write(FileStorage& fs) const void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << "Canny_CUDA" fs << "name" << "Canny_CUDA"
<< "low_thresh" << low_thresh_ << "low_thresh" << low_thresh_
<< "high_thresh" << high_thresh_ << "high_thresh" << high_thresh_
......
...@@ -99,6 +99,7 @@ namespace ...@@ -99,6 +99,7 @@ namespace
void write(FileStorage& fs) const void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << "HoughCirclesDetector_CUDA" fs << "name" << "HoughCirclesDetector_CUDA"
<< "dp" << dp_ << "dp" << dp_
<< "minDist" << minDist_ << "minDist" << minDist_
......
...@@ -95,6 +95,7 @@ namespace ...@@ -95,6 +95,7 @@ namespace
void write(FileStorage& fs) const void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << "HoughLinesDetector_CUDA" fs << "name" << "HoughLinesDetector_CUDA"
<< "rho" << rho_ << "rho" << rho_
<< "theta" << theta_ << "theta" << theta_
......
...@@ -98,6 +98,7 @@ namespace ...@@ -98,6 +98,7 @@ namespace
void write(FileStorage& fs) const void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << "PHoughLinesDetector_CUDA" fs << "name" << "PHoughLinesDetector_CUDA"
<< "rho" << rho_ << "rho" << rho_
<< "theta" << theta_ << "theta" << theta_
......
...@@ -217,6 +217,7 @@ namespace cv ...@@ -217,6 +217,7 @@ namespace cv
void write(FileStorage& fs) const void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "descriptor" << descriptor; fs << "descriptor" << descriptor;
fs << "descriptor_channels" << descriptor_channels; fs << "descriptor_channels" << descriptor_channels;
fs << "descriptor_size" << descriptor_size; fs << "descriptor_size" << descriptor_size;
......
...@@ -184,6 +184,7 @@ void SimpleBlobDetectorImpl::read( const cv::FileNode& fn ) ...@@ -184,6 +184,7 @@ void SimpleBlobDetectorImpl::read( const cv::FileNode& fn )
void SimpleBlobDetectorImpl::write( cv::FileStorage& fs ) const void SimpleBlobDetectorImpl::write( cv::FileStorage& fs ) const
{ {
writeFormat(fs);
params.write(fs); params.write(fs);
} }
......
...@@ -159,6 +159,7 @@ namespace cv ...@@ -159,6 +159,7 @@ namespace cv
void write(FileStorage& fs) const void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "extended" << (int)extended; fs << "extended" << (int)extended;
fs << "upright" << (int)upright; fs << "upright" << (int)upright;
fs << "threshold" << threshold; fs << "threshold" << threshold;
......
...@@ -1179,6 +1179,7 @@ void FlannBasedMatcher::read( const FileNode& fn) ...@@ -1179,6 +1179,7 @@ void FlannBasedMatcher::read( const FileNode& fn)
void FlannBasedMatcher::write( FileStorage& fs) const void FlannBasedMatcher::write( FileStorage& fs) const
{ {
writeFormat(fs);
fs << "indexParams" << "["; fs << "indexParams" << "[";
if (indexParams) if (indexParams)
......
...@@ -1151,6 +1151,7 @@ public: ...@@ -1151,6 +1151,7 @@ public:
return; return;
int i, l_count = layer_count(); int i, l_count = layer_count();
writeFormat(fs);
fs << "layer_sizes" << layer_sizes; fs << "layer_sizes" << layer_sizes;
write_params( fs ); write_params( fs );
......
...@@ -387,6 +387,7 @@ public: ...@@ -387,6 +387,7 @@ public:
if( roots.empty() ) if( roots.empty() )
CV_Error( CV_StsBadArg, "RTrees have not been trained" ); CV_Error( CV_StsBadArg, "RTrees have not been trained" );
writeFormat(fs);
writeParams(fs); writeParams(fs);
int k, ntrees = (int)roots.size(); int k, ntrees = (int)roots.size();
......
...@@ -770,6 +770,7 @@ public: ...@@ -770,6 +770,7 @@ public:
void write(FileStorage& fs) const void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "training_params" << "{"; fs << "training_params" << "{";
write_params(fs); write_params(fs);
fs << "}"; fs << "}";
......
...@@ -466,6 +466,7 @@ public: ...@@ -466,6 +466,7 @@ public:
void write( FileStorage& fs ) const void write( FileStorage& fs ) const
{ {
writeFormat(fs);
impl->write(fs); impl->write(fs);
} }
......
...@@ -578,6 +578,7 @@ void LogisticRegressionImpl::write(FileStorage& fs) const ...@@ -578,6 +578,7 @@ void LogisticRegressionImpl::write(FileStorage& fs) const
{ {
CV_Error(CV_StsBadArg,"file can't open. Check file path"); CV_Error(CV_StsBadArg,"file can't open. Check file path");
} }
writeFormat(fs);
string desc = "Logisitic Regression Classifier"; string desc = "Logisitic Regression Classifier";
fs<<"classifier"<<desc.c_str(); fs<<"classifier"<<desc.c_str();
fs<<"alpha"<<this->params.alpha; fs<<"alpha"<<this->params.alpha;
......
...@@ -342,6 +342,7 @@ public: ...@@ -342,6 +342,7 @@ public:
{ {
int nclasses = (int)cls_labels.total(), i; int nclasses = (int)cls_labels.total(), i;
writeFormat(fs);
fs << "var_count" << (var_idx.empty() ? nallvars : (int)var_idx.total()); fs << "var_count" << (var_idx.empty() ? nallvars : (int)var_idx.total());
fs << "var_all" << nallvars; fs << "var_all" << nallvars;
......
...@@ -296,6 +296,7 @@ public: ...@@ -296,6 +296,7 @@ public:
if( roots.empty() ) if( roots.empty() )
CV_Error( CV_StsBadArg, "RTrees have not been trained" ); CV_Error( CV_StsBadArg, "RTrees have not been trained" );
writeFormat(fs);
writeParams(fs); writeParams(fs);
fs << "oob_error" << oobError; fs << "oob_error" << oobError;
......
...@@ -2037,6 +2037,7 @@ public: ...@@ -2037,6 +2037,7 @@ public:
if( !isTrained() ) if( !isTrained() )
CV_Error( CV_StsParseError, "SVM model data is invalid, check sv_count, var_* and class_count tags" ); CV_Error( CV_StsParseError, "SVM model data is invalid, check sv_count, var_* and class_count tags" );
writeFormat(fs);
write_params( fs ); write_params( fs );
fs << "var_count" << var_count; fs << "var_count" << var_count;
......
...@@ -364,6 +364,7 @@ void SVMSGDImpl::write(FileStorage& fs) const ...@@ -364,6 +364,7 @@ void SVMSGDImpl::write(FileStorage& fs) const
if( !isTrained() ) if( !isTrained() )
CV_Error( CV_StsParseError, "SVMSGD model data is invalid, it hasn't been trained" ); CV_Error( CV_StsParseError, "SVMSGD model data is invalid, it hasn't been trained" );
writeFormat(fs);
writeParams( fs ); writeParams( fs );
fs << "weights" << weights_; fs << "weights" << weights_;
......
...@@ -1681,6 +1681,7 @@ void DTreesImpl::writeTree( FileStorage& fs, int root ) const ...@@ -1681,6 +1681,7 @@ void DTreesImpl::writeTree( FileStorage& fs, int root ) const
void DTreesImpl::write( FileStorage& fs ) const void DTreesImpl::write( FileStorage& fs ) const
{ {
writeFormat(fs);
writeParams(fs); writeParams(fs);
writeTree(fs, roots[0]); writeTree(fs, roots[0]);
} }
......
...@@ -184,6 +184,7 @@ public: ...@@ -184,6 +184,7 @@ public:
void write(FileStorage& fs) const void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << name fs << "name" << name
<< "max_bits" << max_bits << "max_bits" << max_bits
<< "exclude_range" << exclude_range << "exclude_range" << exclude_range
......
...@@ -141,6 +141,7 @@ public: ...@@ -141,6 +141,7 @@ public:
void write(FileStorage& fs) const void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << name fs << "name" << name
<< "samples" << samples << "samples" << samples
<< "lambda" << lambda << "lambda" << lambda
...@@ -250,6 +251,7 @@ public: ...@@ -250,6 +251,7 @@ public:
void write(FileStorage& fs) const void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << name fs << "name" << name
<< "max_iter" << max_iter << "max_iter" << max_iter
<< "threshold" << threshold; << "threshold" << threshold;
......
...@@ -265,6 +265,7 @@ public: ...@@ -265,6 +265,7 @@ public:
void write(FileStorage& fs) const void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << name fs << "name" << name
<< "contrast_weight" << wcon << "contrast_weight" << wcon
<< "saturation_weight" << wsat << "saturation_weight" << wsat
......
...@@ -83,6 +83,7 @@ public: ...@@ -83,6 +83,7 @@ public:
void write(FileStorage& fs) const void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << name fs << "name" << name
<< "gamma" << gamma; << "gamma" << gamma;
} }
...@@ -161,6 +162,7 @@ public: ...@@ -161,6 +162,7 @@ public:
void write(FileStorage& fs) const void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << name fs << "name" << name
<< "gamma" << gamma << "gamma" << gamma
<< "bias" << bias << "bias" << bias
...@@ -242,6 +244,7 @@ public: ...@@ -242,6 +244,7 @@ public:
void write(FileStorage& fs) const void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << name fs << "name" << name
<< "gamma" << gamma << "gamma" << gamma
<< "contrast" << contrast << "contrast" << contrast
...@@ -339,6 +342,7 @@ public: ...@@ -339,6 +342,7 @@ public:
void write(FileStorage& fs) const void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << name fs << "name" << name
<< "gamma" << gamma << "gamma" << gamma
<< "intensity" << intensity << "intensity" << intensity
...@@ -446,6 +450,7 @@ public: ...@@ -446,6 +450,7 @@ public:
void write(FileStorage& fs) const void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << name fs << "name" << name
<< "gamma" << gamma << "gamma" << gamma
<< "scale" << scale << "scale" << scale
......
...@@ -79,6 +79,7 @@ public: ...@@ -79,6 +79,7 @@ public:
//! write/read //! write/read
virtual void write(FileStorage& fs) const virtual void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << name_ fs << "name" << name_
<< "affine_type" << int(fullAffine); << "affine_type" << int(fullAffine);
} }
......
...@@ -77,6 +77,7 @@ public: ...@@ -77,6 +77,7 @@ public:
//! write/read //! write/read
virtual void write(FileStorage& fs) const virtual void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << name_ fs << "name" << name_
<< "distance" << distanceFlag << "distance" << distanceFlag
<< "rank" << rankProportion; << "rank" << rankProportion;
......
...@@ -99,6 +99,7 @@ public: ...@@ -99,6 +99,7 @@ public:
//! write/read //! write/read
virtual void write(FileStorage& fs) const virtual void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << name_ fs << "name" << name_
<< "flag" << flag << "flag" << flag
<< "dummies" << nDummies << "dummies" << nDummies
...@@ -224,6 +225,7 @@ public: ...@@ -224,6 +225,7 @@ public:
//! write/read //! write/read
virtual void write(FileStorage& fs) const virtual void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << name_ fs << "name" << name_
<< "flag" << flag << "flag" << flag
<< "dummies" << nDummies << "dummies" << nDummies
...@@ -350,6 +352,7 @@ public: ...@@ -350,6 +352,7 @@ public:
//! write/read //! write/read
virtual void write(FileStorage& fs) const virtual void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << name_ fs << "name" << name_
<< "dummies" << nDummies << "dummies" << nDummies
<< "default" << defaultCost; << "default" << defaultCost;
...@@ -466,6 +469,7 @@ public: ...@@ -466,6 +469,7 @@ public:
//! write/read //! write/read
virtual void write(FileStorage& fs) const virtual void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << name_ fs << "name" << name_
<< "dummies" << nDummies << "dummies" << nDummies
<< "default" << defaultCost; << "default" << defaultCost;
......
...@@ -137,6 +137,7 @@ public: ...@@ -137,6 +137,7 @@ public:
//! write/read //! write/read
virtual void write(FileStorage& fs) const virtual void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << name_ fs << "name" << name_
<< "nRads" << nRadialBins << "nRads" << nRadialBins
<< "nAngs" << nAngularBins << "nAngs" << nAngularBins
......
...@@ -81,6 +81,7 @@ public: ...@@ -81,6 +81,7 @@ public:
//! write/read //! write/read
virtual void write(FileStorage& fs) const virtual void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << name_ fs << "name" << name_
<< "regularization" << regularizationParameter; << "regularization" << regularizationParameter;
} }
......
...@@ -183,6 +183,7 @@ public: ...@@ -183,6 +183,7 @@ public:
virtual void write(FileStorage& fs) const virtual void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << name_ fs << "name" << name_
<< "history" << history << "history" << history
<< "nsamples" << nN << "nsamples" << nN
......
...@@ -286,6 +286,7 @@ public: ...@@ -286,6 +286,7 @@ public:
virtual void write(FileStorage& fs) const virtual void write(FileStorage& fs) const
{ {
writeFormat(fs);
fs << "name" << name_ fs << "name" << name_
<< "history" << history << "history" << history
<< "nmixtures" << nmixtures << "nmixtures" << nmixtures
......
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