我正在使用ceres-solver和AutoDiffCostFunction。我的成本函数作为参数1x3向量并输出1x1残差。 如何创建我的T *参数向量中的opencv Mat?它可能是Jet或浮动。 我尝试下面的代码,但得到错误“无法从喷气CONVER浮动”将T * array(Jet *或float *)转换为cv :: Mat <CV_32f>
struct ErrorFunc
{
template <typename T>
bool operator()(const T * const Kparams, T * residual) const // Kparams - [f, u, v]
{
cv::Mat K = cv::Mat::eye(3, 3, CV_32F);
K.at<float>(0, 0) = float(Kparams[0]); // error
K.at<float>(0, 2) = float(Kparams[1]); // error
K.at<float>(1, 1) = float(Kparams[0]); // error
K.at<float>(1, 2) = float(Kparams[2]); // error
Mat Hdot = K.inv() * H * K;
cv::decomposeHomographyMat(Hdot, K, rot, tr, norm); //want to call this opencv function
residual[0] = calcResidual(norm);
return true;
}
Mat H;
}
有一种方式来获得特征矩阵进行T *矩阵:
const Eigen::Matrix< T, 3, 3, Eigen::RowMajor> hom = Eigen::Map< const Eigen::Matrix< T, 3, 3, Eigen::RowMajor> >(Matrix)
,但我想打电话给cv::decomposeHomographyMat
。我怎样才能做到这一点?
顺便说一句,CV :: Mat没有[]运算符 – berak
您是否可以使用此原型创建函数? float getFromJetAt(Jet * Kparams,int pos)。该函数应该从Jet中获得位置pos的值。而且你不必担心它在该函数中浮动的可能性。 –