如何在 Eigen 中声明一个带有 Matrix 类型参数的函数?

how to declare a function with Matrix type argument in Eigen?

我写了下面的代码。在这段代码中,我在 foo.h:

中声明了 func
#pragma once
#include "stdafx.h"
#include <vector>
#include <opencv2\opencv.hpp>
#include <Eigen>

void func(std::vector<int>, cv::Mat_<float>, Eigen::Matrix<float, Dynamic, Dynamic, RowMajor>&, Eigen::VectorXf&);

所以,在 foo.cpp:

#include "stdafx.h"
#include "foo.h"
#include <vector>
#include <opencv2\opencv.hpp>
#include <Eigen>

using namespace std;
using namespace cv;
using namespace Eigen;

void func(std::vector<int> gnd, cv::Mat_<float> _data, Eigen::Matrix<float, Dynamic, Dynamic, RowMajor> &A, Eigen::VectorXf &B)
{
//some code
}

但我有以下错误:

'Dynamic': undeclared identifier

'RowMajor': undeclared identifier

'_Rows': invalid template argument for 'Eigen::Matrix', expected compile-time constant expression

'_Cols': invalid template argument for 'Eigen::Matrix', expected compile-time constant expression

'_Options': invalid template argument for 'Eigen::Matrix', expected compile-time constant expression

如何修复此代码?

我自己搞定了!我必须在 Dynamic 之前添加命名空间 Eigen,在 foo.h:

中添加 RowMajor
void func(std::vector<int>, cv::Mat_<float>, Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>&, Eigen::VectorXf&);