![](/img/trans.png)
[英]pass parameters of double but get Jet<double,6>when using ceres solver
[英]Ceres solver number of parameters question
我寫了一個像這樣的函子:
class Functor
{
...
static CostFunction* create()
{
return new AutoDiffCostFunction<Functor, N_RES, N_PARAMS>(new Functor());
}
...
}
我稱之為:
std::vector<double> params(N_PARAMS, 0);
CostFunction* costFunc = Functor::create();
problem.AddResidualBlock(costFunc, nullptr, params.data());
奇怪的是,這在N_PARAMS=236
時N_PARAMS=236
,但適用於6
、 237
(我試過)。 錯誤消息是段錯誤。 而且我之前用過Ceres Solver,從來沒有遇到過這樣的問題。
Ceres Solver 中的參數數量有限制嗎?
==========================================更新======== ============ 我是這樣寫的:
class ReprojError {
public:
ReprojError(
const std::vector<std::vector<Eigen::Vector3d>>& pt2d,
const std::vector<Eigen::Matrix<double, 3, 4>>& vmProjs) :
m_pt2d(pt2d), m_vmProjs(vmProjs) { }
template<typename _Tp>
bool operator () (const _Tp* const pts, _Tp* aResiduals) const
{
for(int i = 0; i < 24; ++i)
{
std::cout << "?" << std::endl;
if(m_pt2d[i].empty())
{
for(int j = 0; j < 276; ++j)
{
aResiduals[i * 276 * 2 + j * 2] = _Tp(0);
aResiduals[i * 276 * 2 + j * 2 + 1] = _Tp(0);
}
}
else
{
auto proj = m_vmProjs[i];
for(int j = 0; j < 276; ++j)
{
auto X = pts[j * 3];
auto Y = pts[j * 3 + 1];
auto Z = pts[j * 3 + 2];
auto newX = (_Tp)proj(0, 0) * X + (_Tp)proj(0, 1) * Y + (_Tp)proj(0, 2) * Z + (_Tp)proj(0, 3);
auto newY = (_Tp)proj(1, 0) * X + (_Tp)proj(1, 1) * Y + (_Tp)proj(1, 2) * Z + (_Tp)proj(1, 3);
auto newZ = (_Tp)proj(2, 0) * X + (_Tp)proj(2, 1) * Y + (_Tp)proj(2, 2) * Z + (_Tp)proj(2, 3);
aResiduals[i * 276 * 2 + j * 2] = newX / newZ - m_pt2d[i][j](0);
aResiduals[i * 276 * 2 + j * 2 + 1] = newY / newZ - m_pt2d[i][j](1);
}
}
}
return true;
}
static ceres::CostFunction* create(
const std::vector<std::vector<Eigen::Vector3d>>& pt2d,
const std::vector<Eigen::Matrix<double, 3, 4>>& vmProjs)
{
return (new ceres::AutoDiffCostFunction<ReprojError, 24 * 2 * 276, 276 * 3>(
new ReprojError(pt2d, vmProjs)));
}
private:
const std::vector<std::vector<Eigen::Vector3d>>& m_pt2d;
const std::vector<Eigen::Matrix<double, 3, 4>>& m_vmProjs;
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
並定義了:
EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(Eigen::Vector3d)
EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(Eigen::Matrix<double, 3, 4>)
和 '?' 沒有輸出,這意味着 operator() 沒有被執行。
沒有這樣的參數限制。 在調試模式下編譯代碼以查看發生了什么會很有幫助。
也就是說,你為什么要把所有這些都放在一個單一的成本函數中,為什么不為每個觀察都有一個成本函數?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.