大家好! camera.h:
#ifndef CAMERA_H #define CAMERA_H #include "myslam/common_include.h" #include <myslam/config.h> /** *小孔成像相机模型 */ namespace myslam { class Camera { public: typedef std::shared_ptr<Camera> Ptr; //定义相机参数及尺度 float fx, fy, cx, cy, depth_scale; Camera(); Camera(float fx_, float fy_, float cx_, float cy_, float depth_scale_ = 0); Vector3d world2camera(const Vector3d &p_w, const SE3 &Tcw); Vector3d camera2world(const Vector3d &p_c, const SE3 &Tcw); Vector2d camera2pixel(const Vector3d &p_c); Vector3d pixel2camera(const Vector2d &p_p, double depth = 1); Vector3d pixel2world(const Vector2d &p_p, const SE3 &Tcw, double depth = 1); Vector2d world2pixel(const Vector3d &p_w, const SE3 &Tcw); }; Camera::Camera(float fx_, float fy_, float cx_, float cy_, float depth_scale_) : fx(fx_), fy(fy_), cx(cx_), cy(cy_), depth_scale(depth_scale_) {} Camera::Camera() { fx = Config::get<float>("camera.fx"); fy = Config::get<float>("camera.fy"); cx = Config::get<float>("camera.cx"); cy = Config::get<float>("camera.cy"); depth_scale = Config::get<float>("camera.depth_scale"); } } // namespace myslam #endif // !CAMERA_H camera.cpp:
#include <myslam/camera.h> namespace myslam { Vector3d Camera::world2camera(const Vector3d &p_w, const SE3 &Tcw) { //Tcw 是李群 return Tcw * p_w; } Vector3d Camera::camera2world(const Vector3d &p_c, const SE3 &Tcw) { return Tcw.inverse() * p_c; } Vector2d Camera::camera2pixel(const Vector3d &p_c) { return Vector2d(fx * p_c(0) / p_c(2) + cx, fy * p_c(1) / p_c(2) + cy); } Vector3d Camera::pixel2camera(const Vector2d &p_p, double depth) { reurn Vector3d((p_p(0) - cx) * depth / fx, (p_p(1) - cy) * depth / fy, depth); } Vector3d Camera::pixel2world(const Vector2d &p_p, const SE3 &Tcw, double depth) { return camera2world(pixel2camera(p_p, depth), Tcw); } Vector2d Camera::world2pixel(const Vector3d &p_w, const SE3 &Tcw) { return camera2pixel(world2camera(p_w, Tcw)); } } // namespace myslam [build] CMakeFiles/myslam.dir/map.cpp.o: In function `myslam::Camera::Camera(float, float, float, float, float)': [build] /home/bob/CLionProjects/slam14/project/0.1/include/myslam/camera.h:29: multiple definition of `myslam::Camera::Camera(float, float, float, float, float)' [build] CMakeFiles/myslam.dir/frame.cpp.o:/home/bob/CLionProjects/slam14/project/0.1/include/myslam/camera.h:29: first defined here [build] CMakeFiles/myslam.dir/map.cpp.o: In function `myslam::Camera::Camera(float, float, float, float, float)': 只要我把这两个 Camera 的构造函数放到 camera.cpp 里定义就不会报错. 现在百思不得其解,求教.
