|
43 | 43 | #ifndef __OPENCV_OPTIM_HPP__
|
44 | 44 | #define __OPENCV_OPTIM_HPP__
|
45 | 45 |
|
| 46 | +#include <iostream> |
46 | 47 | #include "opencv2/core.hpp"
|
47 | 48 | #include "opencv2/core/mat.hpp"
|
48 | 49 |
|
49 | 50 | /*! \namespace cv
|
50 | 51 | Namespace where all the C++ OpenCV functionality resides
|
51 | 52 | */
|
52 |
| -namespace cv |
| 53 | +namespace cv{namespace optim |
53 | 54 | {
|
54 |
| - |
55 |
| -/* //! restores the damaged image areas using one of the available intpainting algorithms */ |
56 |
| -class Solver : public Algorithm /* Algorithm is the base OpenCV class */ |
| 55 | +//! generic class for optimization algorithms */ |
| 56 | +class CV_EXPORTS Solver : public Algorithm /* Algorithm is the base OpenCV class */ |
57 | 57 | {
|
58 |
| - class Function |
| 58 | + public: |
| 59 | + class CV_EXPORTS Function |
59 | 60 | {
|
60 | 61 | public:
|
61 |
| - virtual ~Function(); |
| 62 | + virtual ~Function(){} |
62 | 63 | virtual double calc(InputArray args) const = 0;
|
63 |
| - //virtual double calc(InputArray args, OutputArray grad) const = 0; |
| 64 | + }; |
| 65 | + class CV_EXPORTS Constraints |
| 66 | + { |
| 67 | + public: |
| 68 | + virtual ~Constraints(){} |
64 | 69 | };
|
65 | 70 |
|
66 |
| - // could be reused for all the generic algorithms like downhill simplex. |
67 |
| - virtual void solve(InputArray x0, OutputArray result) const = 0; |
| 71 | + //! could be reused for all the generic algorithms like downhill simplex. Return value is the maximum value of a function*/ |
| 72 | + virtual double solve(const Function& F,const Constraints& C, OutputArray result) const = 0; |
68 | 73 |
|
69 |
| - virtual void setTermCriteria(const TermCriteria& criteria) = 0; |
70 |
| - virtual TermCriteria getTermCriteria() = 0; |
| 74 | + /*virtual void setTermCriteria(const TermCriteria& criteria) = 0; |
| 75 | + virtual TermCriteria getTermCriteria() = 0;*/ |
71 | 76 |
|
72 | 77 | // more detailed API to be defined later ...
|
73 |
| - |
74 | 78 | };
|
75 | 79 |
|
76 |
| -class LPSolver : public Solver |
| 80 | +class CV_EXPORTS LPSolver : public Solver |
77 | 81 | {
|
78 | 82 | public:
|
79 |
| - virtual void solve(InputArray coeffs, InputArray constraints, OutputArray result) const = 0; |
80 |
| - // ... |
81 |
| -}; |
| 83 | + class CV_EXPORTS LPFunction:public Solver::Function |
| 84 | + { |
| 85 | + cv::Mat z; |
| 86 | + public: |
| 87 | + //! Note, that this class is supposed to be immutable, so it's ok to make only a shallow copy of z_in.*/ |
| 88 | + LPFunction(cv::Mat z_in):z(z_in){} |
| 89 | + ~LPFunction(){}; |
| 90 | + const cv::Mat& getz()const{return z;} |
| 91 | + double calc(InputArray args)const; |
| 92 | + }; |
82 | 93 |
|
83 |
| -Ptr<LPSolver> createLPSimplexSolver(); |
84 |
| -}// cv |
| 94 | + //!This class represents constraints for linear problem. There are two matrix stored: m-by-n matrix A and n-by-1 column-vector b. |
| 95 | + //!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 |
| 96 | + //!this form and **we shall create various constructors for this class that will perform these conversions**. |
| 97 | + class CV_EXPORTS LPConstraints:public Solver::Constraints |
| 98 | + { |
| 99 | + cv::Mat A,b; |
| 100 | + public: |
| 101 | + ~LPConstraints(){}; |
| 102 | + //! 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.*/ |
| 103 | + LPConstraints(cv::Mat A_in, cv::Mat b_in):A(A_in),b(b_in){} |
| 104 | + const cv::Mat& getA()const{return A;} |
| 105 | + const cv::Mat& getb()const{return b;} |
| 106 | + }; |
| 107 | + |
| 108 | + LPSolver(){} |
| 109 | + double solve(const Function& F,const Constraints& C, OutputArray result)const; |
| 110 | +}; |
| 111 | +}}// cv |
85 | 112 |
|
86 | 113 | #endif
|
0 commit comments