* @param[in] residual An array of the resulting residuals.
* @return Returns true. The ceres documentation is not clear about that I think.
*/
template<typenameT>
booloperator()(constT*constx,T*residual)const{
for(inti=0;i<num_variables;++i)
{
residual[i]=weight*x[i];
}
returntrue;
};
private:
intnum_variables;
doubleweight;
};
/**
* 2D landmark error cost function.
*
* Computes the landmark reprojection error in 2D.
* Models the cost for one landmark. The residual is 2-dim, [x, y].
* Its input params are camera parameters, shape coefficients and
* blendshape coefficients.
*/
structLandmarkCost{
/**
* Constructs a new landmark cost function object with for a particular landmark/vertex id.
*
* Warning: Don't put in temporaries for \c shape_model and \c blendshapes! We don't make a copy, we store a reference to what is given to the function!
*
* @param[in] shape_model A PCA 3D shape model. Do not use a temporary.
* @param[in] blendshapes A set of 3D blendshapes. Do not use a temporary.
* @param[in] observed_landmark An observed 2D landmark in an image.
* @param[in] vertex_id The vertex id that the given observed landmark corresponds to.
* @param[in] image_width Width of the image that the 2D landmark is from (needed for the model projection).
* @param[in] image_height Height of the image.
* @param[in] use_perspective Whether a perspective or an orthographic projection should be used.
// We rotate ZXY*p, which is RPY*p. I'm not sure this matrix still corresponds to RPY - probably if we use glm::eulerAngles(), these are not RPY anymore and we'd have to adjust if we were to use rotation matrices.
consttmat4x4<T>rot_mtx=glm::mat4_cast(rot_quat);
// Todo: use get_opencv_viewport() from nonlin_cam_esti.hpp.
constautot_mtx=glm::translate(tvec3<T>(camera_translation_and_intrinsics[0],camera_translation_and_intrinsics[1],0.0));// we don't have t_z in ortho camera, it doesn't matter where it is
* Image error cost function (at vertex locations).
*
* Measures the RGB image error between a particular vertex point of the 3D
* model at its projected location and the observed input image.
* Models the cost for 1 vertex. The residual is 3-dim, [r, g, b].
* Its input params are cam, shape-coeffs, BS-coeffs and colour coeffs.
* This projects the vertex locations - so not a full rendering pass.
*/
structImageCost{
/**
* Constructs a new cost function object for a particular vertex id that measures the RGB image error between the estimated model point and the observed input image.
*
* Warning: Don't put in temporaries for \c morphable_model and \c blendshapes! We don't make a copy, we store a reference to what is given to the function!
*
* @param[in] morphable_model A 3D Morphable Model. Do not use a temporary.
* @param[in] blendshapes A set of 3D blendshapes. Do not use a temporary.
* @param[in] image The observed image. TODO: We should assert that the image we get is 8UC3!
* @param[in] vertex_id Vertex id of the 3D model that should be projected and measured.
* @param[in] use_perspective Whether a perspective or an orthographic projection should be used.
* @throws std::runtime_error if the given \c image is not of type CV_8UC3.
// We rotate ZXY*p, which is RPY*p. I'm not sure this matrix still corresponds to RPY - probably if we use glm::eulerAngles(), these are not RPY anymore and we'd have to adjust if we were to use rotation matrices.
consttmat4x4<T>rot_mtx=glm::mat4_cast(rot_quat);
// Todo: use get_opencv_viewport() from nonlin_cam_esti.hpp.
constautot_mtx=glm::translate(tvec3<T>(camera_translation_and_intrinsics[0],camera_translation_and_intrinsics[1],0.0));// we don't have t_z in ortho camera, it doesn't matter where it is
// It kind of looks like as if when it's out of bounds, there will be a vector out of bound access and an assert/crash?
// No, in debugging, it looks like it just interpolates or something. Not clear currently.
}
else{
// Note: We could store the BiCubicInterpolator as member variable.
// The default template arguments for Grid2D are <T, kDataDim=1, kRowMajor=true, kInterleaved=true> and (except for the dimension), they're the right ones for us.