特征C断言失败

我有一个名为v的Eigen MatrixXd对象,我在尝试访问此矩阵内容时遇到了一些问题 . 当我只在控制台上打印内容时(如代码中所示),效果一样好 . 当我尝试使用内容时,错误显示:

断言失败:(row> = 0 && row <rows()&& col> = 0 && col <cols()),function operator(),file /usr/local/Cellar/eigen/3.2.4/include/eigen3 /Eigen/src/Core/DenseCoeffsBase.h,第337行 .

ChosenPoint ** points = new ChosenPoint*[width];
    for (int i = 0; i < width; i++)
    {
        points[i] = new ChosenPoint[height];
        for (int j = 0; j < height; j++)
        {
            points[i][j].setPoint(i, j, false);
            points[i][j].setNumberOfFrames(numberOfFrames);
        }
    }

Matrix<double, 2, 1> v = (aT * a).inverse() * aT * b;
if (v.rows() == 2 && v.cols() == 1)
{
     points[x][y].setFlow(v(0,0), v(1,0), frame);
}

我的ChosenPoint课程:

typedef struct point
{
    double x;
    double y;
    bool isValid;
 } point;

 class ChosenPoint 
{
public: 
ChosenPoint()
{

}

~ChosenPoint()
{
}

void setNumberOfFrames(int numberOfFrames)
{
    this->flow = new point[numberOfFrames];

    for (int i = 0; i < numberOfFrames; i++)
    {
        point f;
        f.x = 0.0;
        f.y = 0.0;
        this->flow[i] = f;
    }
}

void setPoint(int x, int y, bool isValid)
{
    this->pt.x = (double) x;
    this->pt.y = (double) y;
    this->pt.isValid = isValid;
}

point getPoint()
{
    return this->pt;
}

point* getFlow()
{
    return this->flow;
}

void setFlow(double &xFlow, double &yFlow, int &position)
{
    this->flow[position].x = xFlow;
    this->flow[position].y = yFlow;
}

void updateFlow(int position)
{
    this->flow[position].x = 2*this->flow[position].x;
    this->flow[position].y = 2*this->flow[position].y;
}

void updateFlow(double xFlow, double yFlow, int position)
{
    this->flow[position].x = xFlow;
    this->flow[position].y = yFlow;
}

point pt;
point *flow;

};

回答(1)

2 years ago

我的错 . 问题在于我在项目中使用的其他矩阵之一,并花了一些时间才弄明白 . 不幸的是,当发生这种情况时,Eigen似乎并没有真正的帮助:

我有2个矩阵(A和B) . 有问题的矩阵是A(不知何故,一些数据没有加载到矩阵中) . 但是当我乘以A和B时,它生成了一个带有一些有效结果的新矩阵C(我所有的理智检查都是无用的) . 我承认我不知道很多Eigen .

无论如何,希望这对像我这样的更多人有帮助 .