Ask Your Question

Revision history [back]

OPENCV dev 3.0.0 "DownhillSimplex Method" OpenCV Error: Assertion failed

I am trying to implement a very simple example using the Downhill Simplex method in OpenCV dev 3.0.0 However I keep 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

My code is:

#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include "test_precomp.h"

using namespace std;
using namespace cv;

void test(Ptr<optim::DownhillSolver> solver, Ptr<optim::Solver::Function> ptr_F, Mat &P, Mat &step)
{
    try{

        solver->setFunction(ptr_F);
        solver->setInitStep(step);
        double res = solver->minimize(P);

        cout << "res " << res << endl;
    }
    catch (exception e)
    {
        cerr << "Error:: " << e.what() << endl;
    }
}

int main()
{

    class DistanceToLines :public optim::Solver::Function {
    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);

    Ptr<optim::Solver::Function> ptr_F(new DistanceToLines());
    Ptr<optim::DownhillSolver> solver = optim::createDownhillSolver();

    test(solver, ptr_F, P, step);


    system("pause");
    return 0;
}
click to hide/show revision 2
retagged

updated 2014-05-20 02:33:16 -0600

berak gravatar image

OPENCV dev 3.0.0 "DownhillSimplex Method" OpenCV Error: Assertion failed

I am trying to implement a very simple example using the Downhill Simplex method in OpenCV dev 3.0.0 However I keep 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

My code is:

#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include "test_precomp.h"

using namespace std;
using namespace cv;

void test(Ptr<optim::DownhillSolver> solver, Ptr<optim::Solver::Function> ptr_F, Mat &P, Mat &step)
{
    try{

        solver->setFunction(ptr_F);
        solver->setInitStep(step);
        double res = solver->minimize(P);

        cout << "res " << res << endl;
    }
    catch (exception e)
    {
        cerr << "Error:: " << e.what() << endl;
    }
}

int main()
{

    class DistanceToLines :public optim::Solver::Function {
    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);

    Ptr<optim::Solver::Function> ptr_F(new DistanceToLines());
    Ptr<optim::DownhillSolver> solver = optim::createDownhillSolver();

    test(solver, ptr_F, P, step);


    system("pause");
    return 0;
}