EdgeProjectXYZ2UV类
class G2O_TYPES_SBA_API EdgeProjectXYZ2UV : public BaseBinaryEdge<2, Vector2, VertexSBAPointXYZ, VertexSE3Expmap>{
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
EdgeProjectXYZ2UV();
bool read(std::istream& is);
bool write(std::ostream& os) const;
void computeError() {
const VertexSE3Expmap* v1 = static_cast<const VertexSE3Expmap*>(_vertices[1]);
const VertexSBAPointXYZ* v2 = static_cast<const VertexSBAPointXYZ*>(_vertices[0]);
const CameraParameters * cam
= static_cast<const CameraParameters *>(parameter(0));
Vector2 obs(_measurement);
_error = obs-cam->cam_map(v1->estimate().map(v2->estimate()));
}
virtual void linearizeOplus();
CameraParameters * _cam;
};
EdgeSE3ProjectXYZ类
// Projection using focal_length in x and y directions
class G2O_TYPES_SBA_API EdgeSE3ProjectXYZ : public BaseBinaryEdge<2, Vector2, VertexSBAPointXYZ, VertexSE3Expmap> {
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
EdgeSE3ProjectXYZ();
bool read(std::istream &is);
bool write(std::ostream &os) const;
void computeError() {
const VertexSE3Expmap *v1 = static_cast<const VertexSE3Expmap *>(_vertices[1]);
const VertexSBAPointXYZ *v2 = static_cast<const VertexSBAPointXYZ *>(_vertices[0]);
Vector2 obs(_measurement);
_error = obs - cam_project(v1->estimate().map(v2->estimate()));
}
bool isDepthPositive() {
const VertexSE3Expmap *v1 = static_cast<const VertexSE3Expmap *>(_vertices[1]);
const VertexSBAPointXYZ *v2 = static_cast<const VertexSBAPointXYZ *>(_vertices[0]);
return (v1->estimate().map(v2->estimate()))(2) > 0.0;
}
virtual void linearizeOplus();
Vector2 cam_project(const Vector3 &trans_xyz) const;
number_t fx, fy, cx, cy;
};
在computeError函数中,计算error分别与cam_map和cam_project有关,其中参数为v1->estimate().map(v2->estimate()),表示将地图点从世界坐标系转换到相机坐标系中,以便于重投影。
cam_map函数
Vector2 CameraParameters::cam_map(const Vector3 & trans_xyz) const {
Vector2 proj = project2d(trans_xyz);
Vector2 res;
res[0] = proj[0]*focal_length + principle_point[0];
res[1] = proj[1]*focal_length + principle_point[1];
return res;
}
cam_project函数
Vector2 EdgeSE3ProjectXYZ::cam_project(const Vector3 &trans_xyz) const {
Vector2 proj = project2d(trans_xyz);
Vector2 res;
res[0] = proj[0] * fx + cx;
res[1] = proj[1] * fy + cy;
return res;
}
focal_length和fx、fy一样,principle_point和cx、cy一样,因此在作用可以认为两个函数没有区别,都是计算地图点重投影到相机平面的位置。
而EdgeSE3ProjectXYZ中多了一个函数isDepthPositive,用于判断地图点是否在相机的前面;而且两者在使用时,参数的输入方式也不尽相同。
版权声明:本文为leaveforwaiting原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。