在410c上做一个拍照号码识别遇上问题,opencv 派生类LogisticRegressionImpl 没有完全实现基类LogisticRe

liangeng4271 2016-10-13 10:07:25
派生类中没有完全实现基类中的纯虚函数,为什么能够使用基类的纯虚函数?下面是opencv的一个使用例子和部分源代码。不知道opencv是如何处理的,各位帮忙指点一下吧。

opencv 机器学习头文件ml.hpp 定义LogisticRegression类代码
class CV_EXPORTS_W LogisticRegression : public StatModel
{
public:

/** Learning rate. */
/** @see setLearningRate */
CV_WRAP virtual double getLearningRate() const = 0;
/** @copybrief getLearningRate @see getLearningRate */
CV_WRAP virtual void setLearningRate(double val) = 0;

/** Number of iterations. */
/** @see setIterations */
CV_WRAP virtual int getIterations() const = 0;
/** @copybrief getIterations @see getIterations */
CV_WRAP virtual void setIterations(int val) = 0;

/** Kind of regularization to be applied. See LogisticRegression::RegKinds. */
/** @see setRegularization */
CV_WRAP virtual int getRegularization() const = 0;
/** @copybrief getRegularization @see getRegularization */
CV_WRAP virtual void setRegularization(int val) = 0;

/** Kind of training method used. See LogisticRegression::Methods. */
/** @see setTrainMethod */
CV_WRAP virtual int getTrainMethod() const = 0;
/** @copybrief getTrainMethod @see getTrainMethod */
CV_WRAP virtual void setTrainMethod(int val) = 0;

/** Specifies the number of training samples taken in each step of Mini-Batch Gradient
Descent. Will only be used if using LogisticRegression::MINI_BATCH training algorithm. It
has to take values less than the total number of training samples. */
/** @see setMiniBatchSize */
CV_WRAP virtual int getMiniBatchSize() const = 0;
/** @copybrief getMiniBatchSize @see getMiniBatchSize */
CV_WRAP virtual void setMiniBatchSize(int val) = 0;

/** Termination criteria of the algorithm. */
/** @see setTermCriteria */
CV_WRAP virtual TermCriteria getTermCriteria() const = 0;
/** @copybrief getTermCriteria @see getTermCriteria */
CV_WRAP virtual void setTermCriteria(TermCriteria val) = 0;

//! Regularization kinds
enum RegKinds {
REG_DISABLE = -1, //!< Regularization disabled
REG_L1 = 0, //!< %L1 norm
REG_L2 = 1 //!< %L2 norm
};

//! Training methods
enum Methods {
BATCH = 0,
MINI_BATCH = 1 //!< Set MiniBatchSize to a positive integer when using this method.
};

/** @brief Predicts responses for input samples and returns a float type.

@param samples The input data for the prediction algorithm. Matrix [m x n], where each row
contains variables (features) of one object being classified. Should have data type CV_32F.
@param results Predicted labels as a column matrix of type CV_32S.
@param flags Not used.
*/
CV_WRAP virtual float predict( InputArray samples, OutputArray results=noArray(), int flags=0 ) const = 0;

/** @brief This function returns the trained paramters arranged across rows.

For a two class classifcation problem, it returns a row matrix. It returns learnt paramters of
the Logistic Regression as a matrix of type CV_32F.
*/
CV_WRAP virtual Mat get_learnt_thetas() const = 0;

/** @brief Creates empty model.

Creates Logistic Regression model with parameters given.
*/
CV_WRAP static Ptr<LogisticRegression> create();

opencv LogisticRegression的派生类LogisticRegressionImpl定义代码

本人怀疑和LogisticRegressionImpl定义中下面的代码有关, 因为下面6个代码分别和没有实现的纯虚函数有关,不知道CV_IMPL_PROPERTY宏是如何实现定义纯虚函数的。

CV_IMPL_PROPERTY(double, LearningRate, params.alpha)
CV_IMPL_PROPERTY(int, Iterations, params.num_iters)
CV_IMPL_PROPERTY(int, Regularization, params.norm)
CV_IMPL_PROPERTY(int, TrainMethod, params.train_method)
CV_IMPL_PROPERTY(int, MiniBatchSize, params.mini_batch_size)
CV_IMPL_PROPERTY(TermCriteria, TermCriteria, params.term_crit)
...全文
1949 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Winston_Jory 2016-10-13
  • 打赏
  • 举报
回复
可能是opencv就是利用了CV_IMPL_PROPERTY宏定义进行get和set开头的内联函数的定义。所以在派生类中还是有积累纯虚函数的定义的。

5,359

社区成员

发帖
与我相关
我的任务
社区描述
本论坛以AI、WoS 、XR、IoT、Auto、生成式AI等核心板块组成,为开发者提供便捷及高效的学习和交流平台。 高通开发者专区主页:https://qualcomm.csdn.net/
人工智能物联网机器学习 技术论坛(原bbs) 北京·东城区
社区管理员
  • csdnsqst0050
  • chipseeker
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧