Skip to content

Commit 1a6e86e

Browse files
author
swayfreeda
committed
new task4 for class4 incremental structure from motion
1 parent fbb1de7 commit 1a6e86e

File tree

8 files changed

+37
-14
lines changed

8 files changed

+37
-14
lines changed

core/scene.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Scene
4040
public:
4141
/** Constructs and loads a scene from the given directory. */
4242
static Scene::Ptr create (std::string const& path);
43+
//static Scene::Ptr New();
4344

4445
Scene(const Scene&) = delete;
4546
Scene& operator=(const Scene&) = delete;
@@ -111,10 +112,17 @@ inline Scene::Ptr
111112
Scene::create (std::string const& path)
112113
{
113114
Scene::Ptr scene(new Scene);
115+
if(path.empty()) return scene;
114116
scene->load_scene(path);
115117
return scene;
116118
}
117119

120+
//Scene::Ptr Scene::New(){
121+
// Scene::Ptr scene(new Scene);
122+
// return scene;
123+
//}
124+
125+
118126
inline Scene::ViewList const&
119127
Scene::get_views (void) const
120128
{

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_subdirectory(task1)
22
add_subdirectory(task2)
33
add_subdirectory(task3)
4+
add_subdirectory(task4)
45

examples/task2/class2_test_camera.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
//// Created by caoqi on 2018/9/5.//#include <iostream>#include "math/vector.h"class Camera{public: // constructor Camera(){ // 采用归一化坐标,不考虑图像尺寸 c_[0]=c_[1] = 0.0; } // 相机投影过程 math::Vec2d projection(math::Vec3d const & p3d){ // 世界坐标系到相机坐标系 double xc = R_[0] * p3d[0] + R_[1] * p3d[1] + R_[2]* p3d[2] + t_[0]; double yc = R_[3] * p3d[0] + R_[4] * p3d[1] + R_[5]* p3d[2] + t_[1]; double zc = R_[6] * p3d[0] + R_[7] * p3d[1] + R_[8]* p3d[2] + t_[2]; // 相机坐标系到像平面 double x = xc/zc; double y = yc/zc; // 径向畸变过程 double r2 = x*x + y*y; double distort_ratio = 1+ dist_[0]* r2+ dist_[1]*r2*r2; // 图像坐标系到屏幕坐标系 math::Vec2d p; p[0] = f_* distort_ratio*x + c_[0]; p[1] = f_* distort_ratio*y + c_[1]; return p; } // 相机在世界坐标中的位置 -R^T*t math::Vec3d pos_in_world(){ math::Vec3d pos; pos[0] = R_[0]* t_[0] + R_[3]* t_[1] + R_[6]* t_[2]; pos[1] = R_[1]* t_[0] + R_[4]* t_[1] + R_[7]* t_[2]; pos[2] = R_[2]* t_[0] + R_[5]* t_[1] + R_[8]* t_[2]; return -pos; } // 相机在世界坐标中的方向 math::Vec3d dir_in_world(){ math::Vec3d dir (R_[6], R_[7],R_[8]); return dir; }public: // 焦距f double f_; // 径向畸变系数k1, k2 double dist_[2]; // 中心点坐标u0, v0 double c_[2]; // 旋转矩阵 /* * [ R_[0], R_[1], R_[2] ] * [ R_[3], R_[4], R_[5] ] * [ R_[6], R_[7], R_[8] ] */ double R_[9]; // 平移向量 double t_[3];};int main(int argc, char* argv[]){ Camera cam; //焦距 cam.f_ = 0.920227; // 径向畸变系数 cam.dist_[0] = -0.106599; cam.dist_[1] = 0.104385; // 平移向量 cam.t_[0] = 0.0814358; cam.t_[1] = 0.937498; cam.t_[2] = -0.0887441; // 旋转矩阵 cam.R_[0] = 0.999796 ; cam.R_[1] = -0.0127375; cam.R_[2] = 0.0156807; cam.R_[3] = 0.0128557; cam.R_[4] = 0.999894 ; cam.R_[5] = -0.0073718; cam.R_[6] = -0.0155846; cam.R_[7] = 0.00757181; cam.R_[8] = 0.999854; // 三维点坐标 math::Vec3d p3d ={1.36939, -1.17123, 7.04869}; /*计算相机的投影点*/ math::Vec2d p2d = cam.projection(p3d); std::cout<<"projection coord:\n "<<p2d<<std::endl; std::cout<<"result should be:\n 0.208188 -0.035398\n\n"; /*计算相机在世界坐标系中的位置*/ math::Vec3d pos = cam.pos_in_world(); std::cout<<"cam position in world is:\n "<< pos<<std::endl; std::cout<<"result should be: \n -0.0948544 -0.935689 0.0943652\n\n"; /*计算相机在世界坐标系中的方向*/ math::Vec3d dir = cam.dir_in_world(); std::cout<<"cam direction in world is:\n "<<dir<<std::endl; std::cout<<"result should be: \n -0.0155846 0.00757181 0.999854\n";}
1+
//// Created by caoqi on 2018/9/5.//#include <iostream>#include "math/vector.h"class Camera{public: // constructor Camera(){ // 采用归一化坐标,不考虑图像尺寸 c_[0]=c_[1] = 0.0; } // 相机投影过程 math::Vec2d projection(math::Vec3d const & p3d){ // 世界坐标系到相机坐标系 double xc = R_[0] * p3d[0] + R_[1] * p3d[1] + R_[2]* p3d[2] + t_[0]; double yc = R_[3] * p3d[0] + R_[4] * p3d[1] + R_[5]* p3d[2] + t_[1]; double zc = R_[6] * p3d[0] + R_[7] * p3d[1] + R_[8]* p3d[2] + t_[2]; // 相机坐标系到像平面 double x = xc/zc; double y = yc/zc; // 径向畸变过程 double r2 = x*x + y*y; double distort_ratio = 1+ dist_[0]* r2+ dist_[1]*r2*r2; // 图像坐标系到屏幕坐标系 math::Vec2d p; p[0] = f_* distort_ratio*x + c_[0]; p[1] = f_* distort_ratio*y + c_[1]; return p; } // 相机在世界坐标中的位置 -R^T*t math::Vec3d pos_in_world(){ math::Vec3d pos; pos[0] = R_[0]* t_[0] + R_[3]* t_[1] + R_[6]* t_[2]; pos[1] = R_[1]* t_[0] + R_[4]* t_[1] + R_[7]* t_[2]; pos[2] = R_[2]* t_[0] + R_[5]* t_[1] + R_[8]* t_[2]; return -pos; } // 相机在世界坐标中的方向 math::Vec3d dir_in_world(){ math::Vec3d dir (R_[6], R_[7],R_[8]); return dir; }public: // 焦距f double f_; // 径向畸变系数k1, k2 double dist_[2]; // 中心点坐标u0, v0 double c_[2]; // 旋转矩阵 /* * [ R_[0], R_[1], R_[2] ] * [ R_[3], R_[4], R_[5] ] * [ R_[6], R_[7], R_[8] ] */ double R_[9]; // 平移向量 double t_[3];};int main(int argc, char* argv[]){ Camera cam; //焦距 cam.f_ = 0.920227; // 径向畸变系数 cam.dist_[0] = -0.106599; cam.dist_[1] = 0.104385; // 平移向量 cam.t_[0] = 0.0814358; cam.t_[1] = 0.937498; cam.t_[2] = -0.0887441; // 旋转矩阵 cam.R_[0] = 0.999796 ; cam.R_[1] = -0.0127375; cam.R_[2] = 0.0156807; cam.R_[3] = 0.0128557; cam.R_[4] = 0.999894 ; cam.R_[5] = -0.0073718; cam.R_[6] = -0.0155846; cam.R_[7] = 0.00757181; cam.R_[8] = 0.999854; // 三维点坐标 math::Vec3d p3d ={1.36939, -1.17123, 7.04869}; /*计算相机的投影点*/ math::Vec2d p2d = cam.projection(p3d); std::cout<<"projection coord:\n "<<p2d<<std::endl; std::cout<<"result should be:\n 0.208188 -0.035398\n\n"; /*计算相机在世界坐标系中的位置*/ math::Vec3d pos = cam.pos_in_world(); std::cout<<"cam position in world is:\n "<< pos<<std::endl; std::cout<<"result should be: \n -0.0948544 -0.935689 0.0943652\n\n"; /*计算相机在世界坐标系中的方向*/ math::Vec3d dir = cam.dir_in_world(); std::cout<<"cam direction in world is:\n "<<dir<<std::endl; std::cout<<"result should be: \n -0.0155846 0.00757181 0.999854\n";}

examples/task3/class3_test_lm_optimize.cc

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

features/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ set(HEADERS
1212
matching_base.h
1313
matching.h
1414
exhaustive_matching.h
15+
cascade_hashing.h
1516
)
1617

1718
set(SOURCE_FILES
@@ -20,6 +21,7 @@ set(SOURCE_FILES
2021
nearest_neighbor.cc
2122
matching.cc
2223
exhaustive_matching.cc
24+
cascade_hashing.cc
2325

2426
)
2527
add_library(${PROJECT_NAME} ${HEADERS} ${SOURCE_FILES})

features/cascade_hashing.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#include <cstdint>
1212
#include <vector>
1313

14-
#include "sfm/cascade_hashing.h"
14+
#include "features/cascade_hashing.h"
1515

16-
SFM_NAMESPACE_BEGIN
16+
FEATURES_NAMESPACE_BEGIN
1717

1818
void
1919
CascadeHashing::GlobalData::generate_proj_matrices (Options const& opts)
@@ -31,7 +31,7 @@ CascadeHashing::GlobalData::generate_proj_matrices (Options const& opts)
3131
/* ---------------------------------------------------------------- */
3232

3333
void
34-
CascadeHashing::init (bundler::ViewportList* viewports)
34+
CascadeHashing::init (sfm::bundler::ViewportList* viewports)
3535
{
3636
ExhaustiveMatching::init(viewports);
3737

@@ -222,4 +222,4 @@ CascadeHashing::build_buckets(
222222
}
223223
}
224224

225-
SFM_NAMESPACE_END
225+
FEATURES_NAMESPACE_END

features/cascade_hashing.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
#include "math/functions.h"
1818
#include "math/vector.h"
1919
#include "sfm/defines.h"
20-
#include "sfm/exhaustive_matching.h"
21-
#include "sfm/matching.h"
22-
#include "sfm/sift.h"
23-
#include "sfm/surf.h"
20+
#include "features/exhaustive_matching.h"
21+
#include "features/matching.h"
22+
#include "features/sift.h"
23+
#include "features/surf.h"
2424
#include "util/system.h"
2525
#include "util/timer.h"
2626

27-
SFM_NAMESPACE_BEGIN
27+
FEATURES_NAMESPACE_BEGIN
2828

2929
class CascadeHashing : public ExhaustiveMatching
3030
{
@@ -48,7 +48,7 @@ class CascadeHashing : public ExhaustiveMatching
4848
* Initialize matcher by computing cascade hashes of the SIFT/SURF
4949
* descriptors.
5050
*/
51-
void init (bundler::ViewportList* viewports) override;
51+
void init (sfm::bundler::ViewportList* viewports) override;
5252

5353
/** Matches all feature types yielding a single matching result. */
5454
void pairwise_match (int view_1_id, int view_2_id,
@@ -470,6 +470,6 @@ CascadeHashing::collect_top_ranked_candidates (
470470
}
471471
}
472472

473-
SFM_NAMESPACE_END
473+
FEATURES_NAMESPACE_END
474474

475475
#endif /* SFM_CASCADE_HASHING_HEADER */

sfm/CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ set(HEADERS
2626
ba_cholesky.h
2727
extract_focal_length.h
2828
triangulate.h
29+
bundler_features.h
30+
bundler_matching.h
31+
bundler_intrinsics.h
32+
bundler_tracks.h
33+
bundler_incremental.h
34+
bundler_init_pair.h
2935
)
3036

3137
set(SOURCE_FILES
@@ -43,7 +49,13 @@ set(SOURCE_FILES
4349
ba_linear_solver.cc
4450
extract_focal_length.cc
4551
triangulate.cc
52+
bundler_features.cc
53+
bundler_matching.cc
54+
bundler_intrinsics.cc
55+
bundler_tracks.cc
56+
bundler_incremental.cc
57+
bundler_init_pair.cc
4658
)
4759
add_library(sfm ${HEADERS} ${SOURCE_FILES})
48-
target_link_libraries(sfm core util features)
60+
#target_link_libraries(sfm core util features)
4961

0 commit comments

Comments
 (0)