2013-09-30 08:27:43 +08:00
|
|
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
|
|
|
//
|
|
|
|
// By downloading, copying, installing or using the software you agree to this license.
|
|
|
|
// If you do not agree to this license, do not download, install,
|
|
|
|
// copy or use the software.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// License Agreement
|
|
|
|
// For Open Source Computer Vision Library
|
|
|
|
//
|
|
|
|
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
|
|
|
// Third party copyrights are property of their respective owners.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
// are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistribution's of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// * The name of the copyright holders may not be used to endorse or promote products
|
|
|
|
// derived from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// This software is provided by the copyright holders and contributors "as is" and
|
|
|
|
// any express or implied warranties, including, but not limited to, the implied
|
|
|
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
|
|
|
// In no event shall the OpenCV Foundation or contributors be liable for any direct,
|
|
|
|
// indirect, incidental, special, exemplary, or consequential damages
|
|
|
|
// (including, but not limited to, procurement of substitute goods or services;
|
|
|
|
// loss of use, data, or profits; or business interruption) however caused
|
|
|
|
// and on any theory of liability, whether in contract, strict liability,
|
|
|
|
// or tort (including negligence or otherwise) arising in any way out of
|
|
|
|
// the use of this software, even if advised of the possibility of such damage.
|
|
|
|
//
|
|
|
|
//M*/
|
2013-08-01 20:42:59 +08:00
|
|
|
#include "precomp.hpp"
|
2014-08-14 16:50:07 +08:00
|
|
|
|
|
|
|
#define dprintf(x)
|
|
|
|
#define print_matrix(x)
|
2013-08-01 20:42:59 +08:00
|
|
|
|
2014-05-22 20:52:37 +08:00
|
|
|
/*
|
|
|
|
|
|
|
|
****Error Message********************************************************************************************************************
|
|
|
|
|
|
|
|
Downhill Simplex method in OpenCV dev 3.0.0 getting this error:
|
|
|
|
|
|
|
|
OpenCV Error: Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)(s ize.p[0] * size.p[1])
|
|
|
|
&& elemSize() == (((((DataType<_Tp>::type) & ((512 - 1) << 3)) >> 3) + 1) << ((((sizeof(size_t)/4+1)16384|0x3a50)
|
|
|
|
>> ((DataType<_Tp>::typ e) & ((1 << 3) - 1))2) & 3))) in cv::Mat::at,
|
|
|
|
file C:\builds\master_PackSlave-w in32-vc12-shared\opencv\modules\core\include\opencv2/core/mat.inl.hpp, line 893
|
|
|
|
|
|
|
|
****Problem and Possible Fix*********************************************************************************************************
|
|
|
|
|
|
|
|
DownhillSolverImpl::innerDownhillSimplex something looks broken here:
|
|
|
|
Mat_<double> coord_sum(1,ndim,0.0),buf(1,ndim,0.0),y(1,ndim,0.0);
|
|
|
|
nfunk = 0;
|
|
|
|
for(i=0;i<ndim+1;++i)
|
|
|
|
{
|
|
|
|
y(i) = f->calc(p[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
y has only ndim elements, while the loop goes over ndim+1
|
|
|
|
|
|
|
|
Edited the following for possible fix:
|
|
|
|
|
|
|
|
Replaced y(1,ndim,0.0) ------> y(1,ndim+1,0.0)
|
|
|
|
|
|
|
|
***********************************************************************************************************************************
|
|
|
|
|
|
|
|
The code below was used in tesing the source code.
|
|
|
|
Created by @SareeAlnaghy
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cmath>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <opencv2\optim\optim.hpp>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace cv;
|
|
|
|
|
2014-08-14 16:50:07 +08:00
|
|
|
void test(Ptr<optim::DownhillSolver> MinProblemSolver, Ptr<optim::MinProblemSolver::Function> ptr_F, Mat &P, Mat &step)
|
2014-05-22 20:52:37 +08:00
|
|
|
{
|
|
|
|
try{
|
|
|
|
|
2014-08-14 16:50:07 +08:00
|
|
|
MinProblemSolver->setFunction(ptr_F);
|
|
|
|
MinProblemSolver->setInitStep(step);
|
|
|
|
double res = MinProblemSolver->minimize(P);
|
2014-05-22 20:52:37 +08:00
|
|
|
|
|
|
|
cout << "res " << res << endl;
|
|
|
|
}
|
|
|
|
catch (exception e)
|
|
|
|
{
|
|
|
|
cerr << "Error:: " << e.what() << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
|
2014-08-14 16:50:07 +08:00
|
|
|
class DistanceToLines :public optim::MinProblemSolver::Function {
|
2014-05-22 20:52:37 +08:00
|
|
|
public:
|
|
|
|
double calc(const double* x)const{
|
|
|
|
|
|
|
|
return x[0] * x[0] + x[1] * x[1];
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Mat P = (Mat_<double>(1, 2) << 1.0, 1.0);
|
|
|
|
Mat step = (Mat_<double>(2, 1) << -0.5, 0.5);
|
|
|
|
|
2014-08-14 16:50:07 +08:00
|
|
|
Ptr<optim::MinProblemSolver::Function> ptr_F(new DistanceToLines());
|
|
|
|
Ptr<optim::DownhillSolver> MinProblemSolver = optim::createDownhillSolver();
|
2014-05-22 20:52:37 +08:00
|
|
|
|
2014-08-14 16:50:07 +08:00
|
|
|
test(MinProblemSolver, ptr_F, P, step);
|
2014-05-22 20:52:37 +08:00
|
|
|
|
|
|
|
system("pause");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
****Suggesttion for imporving Simplex implentation***************************************************************************************
|
|
|
|
|
|
|
|
Currently the downhilll simplex method outputs the function value that is minimized. It should also return the coordinate points where the
|
|
|
|
function is minimized. This is very useful in many applications such as using back projection methods to find a point of intersection of
|
|
|
|
multiple lines in three dimensions as not all lines intersect in three dimensions.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2014-08-14 16:50:07 +08:00
|
|
|
namespace cv
|
|
|
|
{
|
2013-08-01 20:42:59 +08:00
|
|
|
|
|
|
|
class DownhillSolverImpl : public DownhillSolver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void getInitStep(OutputArray step) const;
|
|
|
|
void setInitStep(InputArray step);
|
|
|
|
Ptr<Function> getFunction() const;
|
|
|
|
void setFunction(const Ptr<Function>& f);
|
|
|
|
TermCriteria getTermCriteria() const;
|
|
|
|
DownhillSolverImpl();
|
|
|
|
void setTermCriteria(const TermCriteria& termcrit);
|
|
|
|
double minimize(InputOutputArray x);
|
|
|
|
protected:
|
2014-08-14 16:50:07 +08:00
|
|
|
Ptr<MinProblemSolver::Function> _Function;
|
2013-08-01 20:42:59 +08:00
|
|
|
TermCriteria _termcrit;
|
|
|
|
Mat _step;
|
2013-09-22 00:14:49 +08:00
|
|
|
Mat_<double> buf_x;
|
|
|
|
|
2013-08-01 20:42:59 +08:00
|
|
|
private:
|
2013-08-28 00:27:59 +08:00
|
|
|
inline void createInitialSimplex(Mat_<double>& simplex,Mat& step);
|
|
|
|
inline double innerDownhillSimplex(cv::Mat_<double>& p,double MinRange,double MinError,int& nfunk,
|
2014-08-14 16:50:07 +08:00
|
|
|
const Ptr<MinProblemSolver::Function>& f,int nmax);
|
|
|
|
inline double tryNewPoint(Mat_<double>& p,Mat_<double>& y,Mat_<double>& coord_sum,const Ptr<MinProblemSolver::Function>& f,int ihi,
|
2013-08-01 20:42:59 +08:00
|
|
|
double fac,Mat_<double>& ptry);
|
|
|
|
};
|
|
|
|
|
2013-08-28 00:27:59 +08:00
|
|
|
double DownhillSolverImpl::tryNewPoint(
|
2013-08-20 17:54:14 +08:00
|
|
|
Mat_<double>& p,
|
2013-08-01 20:42:59 +08:00
|
|
|
Mat_<double>& y,
|
2013-08-20 17:54:14 +08:00
|
|
|
Mat_<double>& coord_sum,
|
2014-08-14 16:50:07 +08:00
|
|
|
const Ptr<MinProblemSolver::Function>& f,
|
2013-08-20 17:54:14 +08:00
|
|
|
int ihi,
|
2013-08-01 20:42:59 +08:00
|
|
|
double fac,
|
|
|
|
Mat_<double>& ptry
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int ndim=p.cols;
|
|
|
|
int j;
|
|
|
|
double fac1,fac2,ytry;
|
2013-08-20 17:54:14 +08:00
|
|
|
|
2013-08-01 20:42:59 +08:00
|
|
|
fac1=(1.0-fac)/ndim;
|
|
|
|
fac2=fac1-fac;
|
2013-08-20 17:54:14 +08:00
|
|
|
for (j=0;j<ndim;j++)
|
2013-08-01 20:42:59 +08:00
|
|
|
{
|
|
|
|
ptry(j)=coord_sum(j)*fac1-p(ihi,j)*fac2;
|
|
|
|
}
|
2014-08-13 19:08:27 +08:00
|
|
|
ytry=f->calc(ptry.ptr<double>());
|
2013-08-20 17:54:14 +08:00
|
|
|
if (ytry < y(ihi))
|
2013-08-01 20:42:59 +08:00
|
|
|
{
|
|
|
|
y(ihi)=ytry;
|
2013-08-20 17:54:14 +08:00
|
|
|
for (j=0;j<ndim;j++)
|
2013-08-01 20:42:59 +08:00
|
|
|
{
|
|
|
|
coord_sum(j) += ptry(j)-p(ihi,j);
|
|
|
|
p(ihi,j)=ptry(j);
|
|
|
|
}
|
|
|
|
}
|
2013-08-20 17:54:14 +08:00
|
|
|
|
2013-08-01 20:42:59 +08:00
|
|
|
return ytry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-08-14 16:50:07 +08:00
|
|
|
Performs the actual minimization of MinProblemSolver::Function f (after the initialization was done)
|
2013-08-01 20:42:59 +08:00
|
|
|
|
|
|
|
The matrix p[ndim+1][1..ndim] represents ndim+1 vertices that
|
|
|
|
form a simplex - each row is an ndim vector.
|
|
|
|
On output, nfunk gives the number of function evaluations taken.
|
|
|
|
*/
|
2013-08-28 00:27:59 +08:00
|
|
|
double DownhillSolverImpl::innerDownhillSimplex(
|
2013-08-20 17:54:14 +08:00
|
|
|
cv::Mat_<double>& p,
|
2013-08-01 20:42:59 +08:00
|
|
|
double MinRange,
|
|
|
|
double MinError,
|
|
|
|
int& nfunk,
|
2014-08-14 16:50:07 +08:00
|
|
|
const Ptr<MinProblemSolver::Function>& f,
|
2013-08-01 20:42:59 +08:00
|
|
|
int nmax
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int ndim=p.cols;
|
|
|
|
double res;
|
|
|
|
int i,ihi,ilo,inhi,j,mpts=ndim+1;
|
|
|
|
double error, range,ysave,ytry;
|
2014-05-22 20:52:37 +08:00
|
|
|
Mat_<double> coord_sum(1,ndim,0.0),buf(1,ndim,0.0),y(1,ndim+1,0.0);
|
2013-08-01 20:42:59 +08:00
|
|
|
|
|
|
|
nfunk = 0;
|
2013-08-20 17:54:14 +08:00
|
|
|
|
2013-08-01 20:42:59 +08:00
|
|
|
for(i=0;i<ndim+1;++i)
|
|
|
|
{
|
|
|
|
y(i) = f->calc(p[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
nfunk = ndim+1;
|
2013-08-20 17:54:14 +08:00
|
|
|
|
2013-08-28 00:27:59 +08:00
|
|
|
reduce(p,coord_sum,0,CV_REDUCE_SUM);
|
2013-08-20 17:54:14 +08:00
|
|
|
|
|
|
|
for (;;)
|
2013-08-01 20:42:59 +08:00
|
|
|
{
|
|
|
|
ilo=0;
|
|
|
|
/* find highest (worst), next-to-worst, and lowest
|
|
|
|
(best) points by going through all of them. */
|
|
|
|
ihi = y(0)>y(1) ? (inhi=1,0) : (inhi=0,1);
|
2013-08-20 17:54:14 +08:00
|
|
|
for (i=0;i<mpts;i++)
|
2013-08-01 20:42:59 +08:00
|
|
|
{
|
2013-08-20 17:54:14 +08:00
|
|
|
if (y(i) <= y(ilo))
|
2013-08-01 20:42:59 +08:00
|
|
|
ilo=i;
|
2013-08-20 17:54:14 +08:00
|
|
|
if (y(i) > y(ihi))
|
2013-08-01 20:42:59 +08:00
|
|
|
{
|
|
|
|
inhi=ihi;
|
|
|
|
ihi=i;
|
2013-08-20 17:54:14 +08:00
|
|
|
}
|
|
|
|
else if (y(i) > y(inhi) && i != ihi)
|
2013-08-01 20:42:59 +08:00
|
|
|
inhi=i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check stop criterion */
|
|
|
|
error=fabs(y(ihi)-y(ilo));
|
|
|
|
range=0;
|
|
|
|
for(i=0;i<ndim;++i)
|
|
|
|
{
|
|
|
|
double min = p(0,i);
|
|
|
|
double max = p(0,i);
|
|
|
|
double d;
|
|
|
|
for(j=1;j<=ndim;++j)
|
|
|
|
{
|
|
|
|
if( min > p(j,i) ) min = p(j,i);
|
|
|
|
if( max < p(j,i) ) max = p(j,i);
|
|
|
|
}
|
|
|
|
d = fabs(max-min);
|
|
|
|
if(range < d) range = d;
|
|
|
|
}
|
|
|
|
|
2013-08-20 17:54:14 +08:00
|
|
|
if(range <= MinRange || error <= MinError)
|
2013-08-01 20:42:59 +08:00
|
|
|
{ /* Put best point and value in first slot. */
|
|
|
|
std::swap(y(0),y(ilo));
|
2013-08-20 17:54:14 +08:00
|
|
|
for (i=0;i<ndim;i++)
|
2013-08-01 20:42:59 +08:00
|
|
|
{
|
|
|
|
std::swap(p(0,i),p(ilo,i));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nfunk >= nmax){
|
|
|
|
dprintf(("nmax exceeded\n"));
|
|
|
|
return y(ilo);
|
|
|
|
}
|
|
|
|
nfunk += 2;
|
|
|
|
/*Begin a new iteration. First, reflect the worst point about the centroid of others */
|
2013-08-28 00:27:59 +08:00
|
|
|
ytry = tryNewPoint(p,y,coord_sum,f,ihi,-1.0,buf);
|
2013-08-01 20:42:59 +08:00
|
|
|
if (ytry <= y(ilo))
|
|
|
|
{ /*If that's better than the best point, go twice as far in that direction*/
|
2013-08-28 00:27:59 +08:00
|
|
|
ytry = tryNewPoint(p,y,coord_sum,f,ihi,2.0,buf);
|
2013-08-01 20:42:59 +08:00
|
|
|
}
|
2013-08-20 17:54:14 +08:00
|
|
|
else if (ytry >= y(inhi))
|
2013-08-01 20:42:59 +08:00
|
|
|
{ /* The new point is worse than the second-highest, but better
|
|
|
|
than the worst so do not go so far in that direction */
|
|
|
|
ysave = y(ihi);
|
2013-08-28 00:27:59 +08:00
|
|
|
ytry = tryNewPoint(p,y,coord_sum,f,ihi,0.5,buf);
|
2013-08-20 17:54:14 +08:00
|
|
|
if (ytry >= ysave)
|
2013-08-01 20:42:59 +08:00
|
|
|
{ /* Can't seem to improve things. Contract the simplex to good point
|
|
|
|
in hope to find a simplex landscape. */
|
2013-08-20 17:54:14 +08:00
|
|
|
for (i=0;i<mpts;i++)
|
2013-08-01 20:42:59 +08:00
|
|
|
{
|
2013-08-20 17:54:14 +08:00
|
|
|
if (i != ilo)
|
2013-08-01 20:42:59 +08:00
|
|
|
{
|
|
|
|
for (j=0;j<ndim;j++)
|
|
|
|
{
|
|
|
|
p(i,j) = coord_sum(j) = 0.5*(p(i,j)+p(ilo,j));
|
|
|
|
}
|
2014-08-13 19:08:27 +08:00
|
|
|
y(i)=f->calc(coord_sum.ptr<double>());
|
2013-08-01 20:42:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
nfunk += ndim;
|
2013-08-28 00:27:59 +08:00
|
|
|
reduce(p,coord_sum,0,CV_REDUCE_SUM);
|
2013-08-01 20:42:59 +08:00
|
|
|
}
|
|
|
|
} else --(nfunk); /* correct nfunk */
|
|
|
|
dprintf(("this is simplex on iteration %d\n",nfunk));
|
|
|
|
print_matrix(p);
|
|
|
|
} /* go to next iteration. */
|
|
|
|
res = y(0);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-08-28 00:27:59 +08:00
|
|
|
void DownhillSolverImpl::createInitialSimplex(Mat_<double>& simplex,Mat& step){
|
2013-08-01 20:42:59 +08:00
|
|
|
for(int i=1;i<=step.cols;++i)
|
|
|
|
{
|
|
|
|
simplex.row(0).copyTo(simplex.row(i));
|
|
|
|
simplex(i,i-1)+= 0.5*step.at<double>(0,i-1);
|
|
|
|
}
|
|
|
|
simplex.row(0) -= 0.5*step;
|
|
|
|
|
|
|
|
dprintf(("this is simplex\n"));
|
|
|
|
print_matrix(simplex);
|
|
|
|
}
|
|
|
|
|
|
|
|
double DownhillSolverImpl::minimize(InputOutputArray x){
|
|
|
|
dprintf(("hi from minimize\n"));
|
|
|
|
CV_Assert(_Function.empty()==false);
|
|
|
|
dprintf(("termcrit:\n\ttype: %d\n\tmaxCount: %d\n\tEPS: %g\n",_termcrit.type,_termcrit.maxCount,_termcrit.epsilon));
|
|
|
|
dprintf(("step\n"));
|
|
|
|
print_matrix(_step);
|
|
|
|
|
|
|
|
Mat x_mat=x.getMat();
|
|
|
|
CV_Assert(MIN(x_mat.rows,x_mat.cols)==1);
|
|
|
|
CV_Assert(MAX(x_mat.rows,x_mat.cols)==_step.cols);
|
|
|
|
CV_Assert(x_mat.type()==CV_64FC1);
|
|
|
|
|
|
|
|
Mat_<double> proxy_x;
|
|
|
|
|
|
|
|
if(x_mat.rows>1){
|
2013-09-22 00:14:49 +08:00
|
|
|
buf_x.create(1,_step.cols);
|
2014-08-13 19:08:27 +08:00
|
|
|
Mat_<double> proxy(_step.cols,1,buf_x.ptr<double>());
|
2013-09-22 00:14:49 +08:00
|
|
|
x_mat.copyTo(proxy);
|
|
|
|
proxy_x=buf_x;
|
2013-08-01 20:42:59 +08:00
|
|
|
}else{
|
|
|
|
proxy_x=x_mat;
|
|
|
|
}
|
|
|
|
|
|
|
|
int count=0;
|
|
|
|
int ndim=_step.cols;
|
|
|
|
Mat_<double> simplex=Mat_<double>(ndim+1,ndim,0.0);
|
|
|
|
|
2015-05-03 01:59:57 +08:00
|
|
|
proxy_x.copyTo(simplex.row(0));
|
2013-08-28 00:27:59 +08:00
|
|
|
createInitialSimplex(simplex,_step);
|
|
|
|
double res = innerDownhillSimplex(
|
2013-08-01 20:42:59 +08:00
|
|
|
simplex,_termcrit.epsilon, _termcrit.epsilon, count,_Function,_termcrit.maxCount);
|
|
|
|
simplex.row(0).copyTo(proxy_x);
|
|
|
|
|
|
|
|
dprintf(("%d iterations done\n",count));
|
|
|
|
|
|
|
|
if(x_mat.rows>1){
|
2014-08-13 19:08:27 +08:00
|
|
|
Mat(x_mat.rows, 1, CV_64F, proxy_x.ptr<double>()).copyTo(x);
|
2013-08-01 20:42:59 +08:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
DownhillSolverImpl::DownhillSolverImpl(){
|
|
|
|
_Function=Ptr<Function>();
|
|
|
|
_step=Mat_<double>();
|
|
|
|
}
|
2014-08-14 16:50:07 +08:00
|
|
|
Ptr<MinProblemSolver::Function> DownhillSolverImpl::getFunction()const{
|
2013-08-01 20:42:59 +08:00
|
|
|
return _Function;
|
|
|
|
}
|
|
|
|
void DownhillSolverImpl::setFunction(const Ptr<Function>& f){
|
|
|
|
_Function=f;
|
|
|
|
}
|
|
|
|
TermCriteria DownhillSolverImpl::getTermCriteria()const{
|
|
|
|
return _termcrit;
|
|
|
|
}
|
|
|
|
void DownhillSolverImpl::setTermCriteria(const TermCriteria& termcrit){
|
|
|
|
CV_Assert(termcrit.type==(TermCriteria::MAX_ITER+TermCriteria::EPS) && termcrit.epsilon>0 && termcrit.maxCount>0);
|
|
|
|
_termcrit=termcrit;
|
|
|
|
}
|
|
|
|
// both minRange & minError are specified by termcrit.epsilon; In addition, user may specify the number of iterations that the algorithm does.
|
2014-08-14 16:50:07 +08:00
|
|
|
Ptr<DownhillSolver> DownhillSolver::create(const Ptr<MinProblemSolver::Function>& f, InputArray initStep, TermCriteria termcrit){
|
|
|
|
Ptr<DownhillSolver> DS = makePtr<DownhillSolverImpl>();
|
2013-08-01 20:42:59 +08:00
|
|
|
DS->setFunction(f);
|
|
|
|
DS->setInitStep(initStep);
|
|
|
|
DS->setTermCriteria(termcrit);
|
2014-08-14 16:50:07 +08:00
|
|
|
return DS;
|
2013-08-01 20:42:59 +08:00
|
|
|
}
|
|
|
|
void DownhillSolverImpl::getInitStep(OutputArray step)const{
|
|
|
|
_step.copyTo(step);
|
|
|
|
}
|
|
|
|
void DownhillSolverImpl::setInitStep(InputArray step){
|
|
|
|
//set dimensionality and make a deep copy of step
|
|
|
|
Mat m=step.getMat();
|
|
|
|
dprintf(("m.cols=%d\nm.rows=%d\n",m.cols,m.rows));
|
|
|
|
CV_Assert(MIN(m.cols,m.rows)==1 && m.type()==CV_64FC1);
|
|
|
|
if(m.rows==1){
|
|
|
|
m.copyTo(_step);
|
|
|
|
}else{
|
2013-08-28 00:27:59 +08:00
|
|
|
transpose(m,_step);
|
2013-08-01 20:42:59 +08:00
|
|
|
}
|
|
|
|
}
|
2014-08-14 16:50:07 +08:00
|
|
|
}
|