diff --git a/.gitignore b/.gitignore index 0a19f3cee..caaebed0e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ OpenCV4Tegra/ .sw[a-z] .*.swp tags +build/ diff --git a/modules/optim/CMakeLists.txt b/modules/optim/CMakeLists.txt index a73df3230..c36c24d9d 100644 --- a/modules/optim/CMakeLists.txt +++ b/modules/optim/CMakeLists.txt @@ -1,3 +1,2 @@ set(the_description "Generic optimization") -ocv_define_module(optim opencv_imgproc) -#ocv_define_module(optim core) +ocv_define_module(optim opencv_core) diff --git a/modules/optim/include/opencv2/optim.hpp b/modules/optim/include/opencv2/optim.hpp index 44b01efc5..8464cf872 100644 --- a/modules/optim/include/opencv2/optim.hpp +++ b/modules/optim/include/opencv2/optim.hpp @@ -43,44 +43,71 @@ #ifndef __OPENCV_OPTIM_HPP__ #define __OPENCV_OPTIM_HPP__ +#include #include "opencv2/core.hpp" #include "opencv2/core/mat.hpp" /*! \namespace cv Namespace where all the C++ OpenCV functionality resides */ -namespace cv +namespace cv{namespace optim { - -/* //! restores the damaged image areas using one of the available intpainting algorithms */ -class Solver : public Algorithm /* Algorithm is the base OpenCV class */ +//! generic class for optimization algorithms */ +class CV_EXPORTS Solver : public Algorithm /* Algorithm is the base OpenCV class */ { - class Function + public: + class CV_EXPORTS Function { public: - virtual ~Function(); + virtual ~Function(){} virtual double calc(InputArray args) const = 0; - //virtual double calc(InputArray args, OutputArray grad) const = 0; + }; + class CV_EXPORTS Constraints + { + public: + virtual ~Constraints(){} }; - // could be reused for all the generic algorithms like downhill simplex. - virtual void solve(InputArray x0, OutputArray result) const = 0; + //! could be reused for all the generic algorithms like downhill simplex. Return value is the maximum value of a function*/ + virtual double solve(const Function& F,const Constraints& C, OutputArray result) const = 0; - virtual void setTermCriteria(const TermCriteria& criteria) = 0; - virtual TermCriteria getTermCriteria() = 0; + /*virtual void setTermCriteria(const TermCriteria& criteria) = 0; + virtual TermCriteria getTermCriteria() = 0;*/ // more detailed API to be defined later ... - }; -class LPSolver : public Solver +class CV_EXPORTS LPSolver : public Solver { public: - virtual void solve(InputArray coeffs, InputArray constraints, OutputArray result) const = 0; - // ... -}; + class CV_EXPORTS LPFunction:public Solver::Function + { + cv::Mat z; + public: + //! Note, that this class is supposed to be immutable, so it's ok to make only a shallow copy of z_in.*/ + LPFunction(cv::Mat z_in):z(z_in){} + ~LPFunction(){}; + const cv::Mat& getz()const{return z;} + double calc(InputArray args)const; + }; -Ptr createLPSimplexSolver(); -}// cv + //!This class represents constraints for linear problem. There are two matrix stored: m-by-n matrix A and n-by-1 column-vector b. + //!What this represents is the set of constraints Ax\leq b and x\geq 0. It can be shown that any set of linear constraints can be converted + //!this form and **we shall create various constructors for this class that will perform these conversions**. + class CV_EXPORTS LPConstraints:public Solver::Constraints + { + cv::Mat A,b; + public: + ~LPConstraints(){}; + //! Note, that this class is supposed to be immutable, so it's ok to make only a shallow copy of A_in and b_in.*/ + LPConstraints(cv::Mat A_in, cv::Mat b_in):A(A_in),b(b_in){} + const cv::Mat& getA()const{return A;} + const cv::Mat& getb()const{return b;} + }; + + LPSolver(){} + double solve(const Function& F,const Constraints& C, OutputArray result)const; +}; +}}// cv #endif diff --git a/modules/optim/src/lpsolver.cpp b/modules/optim/src/lpsolver.cpp index 5559a0660..56dec1235 100644 --- a/modules/optim/src/lpsolver.cpp +++ b/modules/optim/src/lpsolver.cpp @@ -1,2 +1,22 @@ #include "precomp.hpp" -#include "opencv2/optim.hpp" + +namespace cv{namespace optim{ + +double LPSolver::solve(const Function& F,const Constraints& C, OutputArray result)const{ + printf("call to solve\n"); + + //TODO: sanity check and throw exception, if appropriate + + //TODO: copy A,b,z + + //TODO: run simplex algo + + return 0.0; +} + +double LPSolver::LPFunction::calc(InputArray args)const{ + printf("call to LPFunction::calc()\n"); + return 0.0; +} + +}}