#include "test_precomp.hpp" #include #include #include static void mytest(cv::Ptr solver,cv::Ptr ptr_F,cv::Mat& x,cv::Mat& step, cv::Mat& etalon_x,double etalon_res){ solver->setFunction(ptr_F); int ndim=MAX(step.cols,step.rows); solver->setInitStep(step); cv::Mat settedStep; solver->getInitStep(settedStep); ASSERT_TRUE(settedStep.rows==1 && settedStep.cols==ndim); ASSERT_TRUE(std::equal(step.begin(),step.end(),settedStep.begin())); std::cout<<"step setted:\n\t"<minimize(x); std::cout<<"res:\n\t"<getTermCriteria().epsilon; ASSERT_TRUE(std::abs(res-etalon_res)::iterator it1=x.begin(),it2=etalon_x.begin();it1!=x.end();it1++,it2++){ ASSERT_TRUE(std::abs((*it1)-(*it2)) solver=cv::optim::createDownhillSolver(); #if 1 { cv::Ptr ptr_F(new SphereF()); cv::Mat x=(cv::Mat_(1,2)<<1.0,1.0), step=(cv::Mat_(2,1)<<-0.5,-0.5), etalon_x=(cv::Mat_(1,2)<<-0.0,0.0); double etalon_res=0.0; mytest(solver,ptr_F,x,step,etalon_x,etalon_res); } #endif #if 1 { cv::Ptr ptr_F(new RosenbrockF()); cv::Mat x=(cv::Mat_(2,1)<<0.0,0.0), step=(cv::Mat_(2,1)<<0.5,+0.5), etalon_x=(cv::Mat_(2,1)<<1.0,1.0); double etalon_res=0.0; mytest(solver,ptr_F,x,step,etalon_x,etalon_res); } #endif }