Commit 7da3c639 authored by Guillaume Pasero's avatar Guillaume Pasero

ENH: complete wrapping of CvRTreeWrapper

parent 381d42f8
......@@ -30,7 +30,9 @@ namespace otb
* \ingroup OTBSupervised
*/
class OTBSupervised_EXPORT CvRTreesWrapper
#ifndef OTB_OPENCV_3
#ifdef OTB_OPENCV_3
: public cv::ml::RTrees
#else
: public CvRTrees
#endif
{
......@@ -61,10 +63,67 @@ public:
const cv::Mat& missing =
cv::Mat()) const;
private:
#ifdef OTB_OPENCV_3
cv::Ptr<cv::ml::RTrees> m_RTrees;
#define OTB_CV_WRAP_PROPERTY(type,name) \
virtual type get##name() const; \
virtual void set##name(type val);
#define OTB_CV_WRAP_PROPERTY_REF(type,name) \
virtual type get##name() const; \
virtual void set##name(const type &val);
#define OTB_CV_WRAP_CSTREF_GET(type, name) \
virtual const type& get##name() const;
// TODO : wrap all method used
virtual int getVarCount() const;
virtual bool isTrained() const;
virtual bool isClassifier() const;
OTB_CV_WRAP_PROPERTY(int, MaxCategories)
OTB_CV_WRAP_PROPERTY(int, MaxDepth)
OTB_CV_WRAP_PROPERTY(int, MinSampleCount)
OTB_CV_WRAP_PROPERTY(bool, UseSurrogates)
OTB_CV_WRAP_PROPERTY(int, CVFolds)
OTB_CV_WRAP_PROPERTY(bool, Use1SERule)
OTB_CV_WRAP_PROPERTY(bool,TruncatePrunedTree)
OTB_CV_WRAP_PROPERTY(float, RegressionAccuracy)
OTB_CV_WRAP_PROPERTY(bool, CalculateVarImportance)
OTB_CV_WRAP_PROPERTY(int, ActiveVarCount)
OTB_CV_WRAP_PROPERTY_REF(cv::Mat, Priors)
OTB_CV_WRAP_PROPERTY_REF(cv::TermCriteria, TermCriteria)
OTB_CV_WRAP_CSTREF_GET(std::vector<int>, Roots)
OTB_CV_WRAP_CSTREF_GET(std::vector<cv::ml::DTrees::Node>, Nodes)
OTB_CV_WRAP_CSTREF_GET(std::vector<cv::ml::DTrees::Split>, Splits)
OTB_CV_WRAP_CSTREF_GET(std::vector<int>, Subsets)
virtual cv::Mat getVarImportance() const;
virtual cv::String getDefaultName () const;
virtual void read (const cv::FileNode &fn);
virtual void save (const cv::String &filename) const;
virtual bool train(cv::InputArray samples, int layout, cv::InputArray responses);
virtual bool train( const cv::Ptr<cv::ml::TrainData>& trainData, int flags=0 );
virtual float predict (cv::InputArray samples, cv::OutputArray results=cv::noArray(), int flags=0) const;
static cv::Ptr<CvRTreesWrapper> create();
#undef OTB_CV_WRAP_PROPERTY
#undef OTB_CV_WRAP_PROPERTY_REF
#undef OTB_CV_WRAP_CSTREF_GET
#endif
private:
cv::Ptr<cv::ml::RTrees> m_Impl;
};
}
......
......@@ -27,15 +27,12 @@ void dont_delete_me(void *){}
CvRTreesWrapper::CvRTreesWrapper()
{
#ifdef OTB_OPENCV_3
m_RTrees = cv::Ptr<cv::ml::RTrees>((cv::ml::RTrees::create()).get(), dont_delete_me).get();
m_Impl = cv::ml::RTrees::create();
#endif
}
CvRTreesWrapper::~CvRTreesWrapper()
{
#ifdef OTB_OPENCV_3
delete m_RTrees;
#endif
}
void CvRTreesWrapper::get_votes(const cv::Mat& sample,
......@@ -99,4 +96,101 @@ float CvRTreesWrapper::predict_confidence(const cv::Mat& sample,
#endif
}
#ifdef OTB_OPENCV_3
#define OTB_CV_WRAP_IMPL(type,name) \
type CvRTreesWrapper::get##name() const \
{ return m_Impl->get##name(); } \
void CvRTreesWrapper::set##name(type val) \
{ m_Impl->set##name(val); }
#define OTB_CV_WRAP_IMPL_REF(type,name) \
type CvRTreesWrapper::get##name() const \
{ return m_Impl->get##name(); } \
void CvRTreesWrapper::set##name(const type &val) \
{ m_Impl->set##name(val); }
#define OTB_CV_WRAP_IMPL_CSTREF_GET(type, name) \
const type& CvRTreesWrapper::get##name() const \
{ return m_Impl->get##name(); }
// TODO : wrap all method used
OTB_CV_WRAP_IMPL(int, MaxCategories)
OTB_CV_WRAP_IMPL(int, MaxDepth)
OTB_CV_WRAP_IMPL(int, MinSampleCount)
OTB_CV_WRAP_IMPL(bool, UseSurrogates)
OTB_CV_WRAP_IMPL(int, CVFolds)
OTB_CV_WRAP_IMPL(bool, Use1SERule)
OTB_CV_WRAP_IMPL(bool,TruncatePrunedTree)
OTB_CV_WRAP_IMPL(float, RegressionAccuracy)
OTB_CV_WRAP_IMPL(bool, CalculateVarImportance)
OTB_CV_WRAP_IMPL(int, ActiveVarCount)
OTB_CV_WRAP_IMPL_REF(cv::Mat, Priors)
OTB_CV_WRAP_IMPL_REF(cv::TermCriteria, TermCriteria)
OTB_CV_WRAP_IMPL_CSTREF_GET(std::vector<int>, Roots)
OTB_CV_WRAP_IMPL_CSTREF_GET(std::vector<cv::ml::DTrees::Node>, Nodes)
OTB_CV_WRAP_IMPL_CSTREF_GET(std::vector<cv::ml::DTrees::Split>, Splits)
OTB_CV_WRAP_IMPL_CSTREF_GET(std::vector<int>, Subsets)
int CvRTreesWrapper::getVarCount() const
{
return m_Impl->getVarCount();
}
bool CvRTreesWrapper::isTrained() const
{
return m_Impl->isTrained();
}
bool CvRTreesWrapper::isClassifier() const
{
return m_Impl->isClassifier();
}
cv::Mat CvRTreesWrapper::getVarImportance() const
{
return m_Impl->getVarImportance();
}
cv::String CvRTreesWrapper::getDefaultName () const
{
return m_Impl->getDefaultName();
}
void CvRTreesWrapper::read (const cv::FileNode &fn)
{
m_Impl->read(fn);
}
void CvRTreesWrapper::save (const cv::String &filename) const
{
m_Impl->save(filename);
}
bool CvRTreesWrapper::train(cv::InputArray samples, int layout, cv::InputArray responses)
{
return m_Impl->train(samples,layout, responses);
}
bool CvRTreesWrapper::train( const cv::Ptr<cv::ml::TrainData>& trainData, int flags )
{
return m_Impl->train(trainData, flags);
}
float CvRTreesWrapper::predict (cv::InputArray samples, cv::OutputArray results, int flags) const
{
return m_Impl->predict(samples, results, flags);
}
cv::Ptr<CvRTreesWrapper> CvRTreesWrapper::create()
{
return cv::makePtr<CvRTreesWrapper>();
}
#undef OTB_CV_WRAP_IMPL
#undef OTB_CV_WRAP_IMPL_REF
#undef OTB_CV_WRAP_IMPL_CSTREF_GET
#endif
}
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