Skip to content

Commit 84f6fe9

Browse files
committed
major refactor; data loading seems working
1 parent e7c34e7 commit 84f6fe9

13 files changed

Lines changed: 151 additions & 254 deletions

‎CMakeLists.txt‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.5)
22
project(VISMA)
33

44
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMakeModules)
5-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -O3 -Wall -g -fopenmp")
5+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -O3 -Wall -g -fopenmp -fPIC")
66
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-compare -Wno-unused-function -Wno-unused-variable -Wno-narrowing")
77
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin )
88
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib )
@@ -21,6 +21,7 @@ find_package(Protobuf REQUIRED)
2121
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${PROJECT_SOURCE_DIR}/protocols/vlslam.proto)
2222

2323
add_subdirectory(thirdparty/abseil-cpp)
24+
add_subdirectory(thirdparty/jsoncpp)
2425

2526
include_directories(
2627
${CMAKE_CURRENT_BINARY_DIR}
@@ -30,7 +31,6 @@ include_directories(
3031
${PROJECT_SOURCE_DIR}/thirdparty/jsoncpp/include
3132
${PROJECT_SOURCE_DIR}/thirdparty/abseil-cpp
3233

33-
${OpenCV_INCLUDE_DIRS}
3434
${EIGEN3_INCLUDE_DIR}
3535
${PROTOBUF_INCLUDE_DIRS}
3636
${GLOG_INCLUDE_DIRS}
@@ -39,32 +39,30 @@ message(STATUS "Found Eigen at ${EIGEN3_INCLUDE_DIR}")
3939

4040
link_directories(
4141
${PROJECT_SOURCE_DIR}/lib
42+
${PROJECT_SOURCE_DIR}/jsoncpp/lib
4243
/usr/local/lib
4344
/usr/lib
4445
)
4546

4647

47-
set(OpenCV_MINIMAL
48+
link_libraries(
49+
protobuf
50+
glog
51+
jsoncpp
52+
absl::str_format
53+
4854
opencv_highgui
4955
opencv_core
50-
opencv_imgcodecs
5156
opencv_imgproc
5257
opencv_video
53-
opencv_calib3d)
54-
55-
56-
link_libraries(
57-
protobuf
58-
${OpenCV_MINIMAL}
59-
glog
58+
opencv_calib3d
6059
)
6160

6261
add_library(visma SHARED
6362
src/dataloader.cpp
6463
src/utils.cpp
6564
src/undistorter.cpp
6665
${PROTO_SRCS})
67-
target_link_libraries(visma absl::strings)
6866

6967

7068
add_executable(example_load example/example_load.cpp)

‎example/example_dump.cpp‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
#include "sys/stat.h"
66

77
// 3rdparty
8-
#include "folly/Format.h"
9-
#include "opencv2/imgproc.hpp"
8+
#include "opencv2/imgproc/imgproc.hpp"
109

1110
// feh
1211
#include "dataloader.h"
@@ -39,19 +38,19 @@ int main(int argc, char *argv[]) {
3938
exit(-1);
4039
}
4140

42-
auto ss = folly::sformat("{}/image", argv[2]);
41+
auto ss = absl::StrFormat("%s/image", argv[2]);
4342
if (mkdir(ss.c_str(), DIR_MODE) < 0) {
4443
std::cout << feh::TermColor::red
4544
<< "Failed to create output/image directory" << feh::TermColor::endl;
4645
exit(-1);
4746
}
48-
ss = folly::sformat("{}/pose", argv[2]);
47+
ss = absl::StrFormat("%s/pose", argv[2]);
4948
if (mkdir(ss.c_str(), DIR_MODE) < 0) {
5049
std::cout << feh::TermColor::red
5150
<< "Failed to create output/pose directory" << feh::TermColor::endl;
5251
exit(-1);
5352
}
54-
ss = folly::sformat("{}/depth", argv[2]);
53+
ss = absl::StrFormat("%s/depth", argv[2]);
5554
if (mkdir(ss.c_str(), DIR_MODE) < 0) {
5655
std::cout << feh::TermColor::red
5756
<< "Failed to create output/depth directory" << feh::TermColor::endl;
@@ -70,7 +69,7 @@ int main(int argc, char *argv[]) {
7069
K << params[0], 0, params[2],
7170
0, params[1], params[3],
7271
0, 0, 1;
73-
std::ofstream Kout(folly::sformat("{}/K.txt", argv[2]), std::ios::out);
72+
std::ofstream Kout(absl::StrFormat("%s/K.txt", argv[2]), std::ios::out);
7473
Kout << K;
7574
Kout.close();
7675

@@ -88,14 +87,14 @@ int main(int argc, char *argv[]) {
8887

8988
// write out pose
9089
std::ofstream fid_pose;
91-
fid_pose.open(folly::sformat("{}/pose/{:06d}.txt", argv[2], i));
90+
fid_pose.open(absl::StrFormat("%s/pose/%06d.txt", argv[2], i));
9291
fid_pose << gwc.matrix();
9392
fid_pose.close();
9493

9594
// write out sparse depth
9695
std::ofstream fid_depth;
9796
try {
98-
fid_depth.open(folly::sformat("{}/depth/{:06d}.txt", argv[2], i));
97+
fid_depth.open(absl::StrFormat("%s/depth/%06d.txt", argv[2], i));
9998
for (const auto &s : depth_samples) {
10099
if (s.second[1] > 0) {
101100
fid_depth << s.second[0] << " "
@@ -109,7 +108,7 @@ int main(int argc, char *argv[]) {
109108
}
110109

111110
// write out image
112-
cv::imwrite(folly::sformat("{}/image/{:06d}.jpg", argv[2], i), img);
111+
cv::imwrite(absl::StrFormat("%s/image/%06d.jpg", argv[2], i), img);
113112

114113
cv::imshow("image", img);
115114
// cv::imshow("edge map", edgemap);

‎example/example_evaluate.cpp‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
// folly
2-
#include "folly/dynamic.h"
3-
#include "folly/json.h"
4-
#include "folly/FileUtil.h"
5-
// igl
1+
#include "utils.h"
62
#include "tool.h"
73

84
using namespace feh;
95

106
int main(int argc, char **argv) {
117
// READ IN CONFIGURATION
12-
folly::fbstring contents;
13-
folly::readFile("../cfg/tool.json", contents);
14-
folly::dynamic config = folly::parseJson(folly::json::stripComments(contents));
8+
auto config = LoadJson("../cfg/tool.json");
159
// TURN OFF ORIGINAL SCENE MESH IN QUANTITATIVE EVALUATION
1610
// AND ONLY COMPARE MESHES CONSIST OF OBJECTS-OF-INTEREST
1711
// config["result_visualization"]["show_original_scene"] = false;

‎include/dataloader.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
// own
1414
#include "vlslam.pb.h"
15-
#include "eigen_alias.h"
15+
#include "alias.h"
1616

1717
namespace feh {
1818

‎include/eigen_alias.h‎

Lines changed: 0 additions & 54 deletions
This file was deleted.

‎include/geometry.h‎

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// Created by visionlab on 2/19/18.
33
//
44
#pragma once
5-
6-
#include "eigen_alias.h"
75
#include <vector>
86
#include <random>
97
#include <chrono>
108

119
// 3rd party
1210
#include "igl/AABB.h"
13-
#include "folly/dynamic.h"
11+
12+
#include "alias.h"
13+
#include "utils.h"
1414

1515
namespace feh {
1616

@@ -25,40 +25,6 @@ Eigen::Matrix<T, DIM, 1> FindPlaneNormal(const Eigen::Matrix<T, Eigen::Dynamic,
2525
return n;
2626
}
2727

28-
/// \brief: Convert from std vector of Eigen vectors to Eigen matrix.
29-
template <typename T, int DIM=3>
30-
Eigen::Matrix<T, Eigen::Dynamic, DIM>
31-
StdVectorOfEigenVectorToEigenMatrix(const std::vector<Eigen::Matrix<T, DIM, 1> > &v) {
32-
Eigen::Matrix<T, Eigen::Dynamic, DIM> out;
33-
out.resize(v.size(), DIM);
34-
for (int i = 0; i < v.size(); ++i) {
35-
out.row(i) = v[i];
36-
}
37-
return out;
38-
}
39-
40-
41-
/// \brief: Convert from an Eigen matrix type to a std vector of Eigen vectors.
42-
template <typename T, int DIM=3>
43-
std::vector<Eigen::Matrix<T, DIM, 1>>
44-
EigenMatrixToStdVectorOfEigenVector(const Eigen::Matrix<T, Eigen::Dynamic, DIM> &m) {
45-
std::vector<Eigen::Matrix<T, DIM, 1>> out(m.rows());
46-
for (int i = 0; i < m.rows(); ++i) out[i] = m.row(i);
47-
return out;
48-
};
49-
50-
/// \brief: Convert from a std vector of Eigen vectors to an Eigen matrix.
51-
template <typename T, int DIM=3>
52-
Eigen::Matrix<T, DIM, 1> StdVectorOfEigenVectorMean(const std::vector<Eigen::Matrix<T, DIM, 1>> &v) {
53-
return StdVectorOfEigenVectorToEigenMatrix(v).colwise().mean();
54-
};
55-
56-
/// \brief: Compute the rotation matrix to align two vectors.
57-
template <typename T>
58-
Eigen::Matrix<T, 3, 3> RotationBetweenVectors(Eigen::Matrix<T, 3, 1> u, Eigen::Matrix<T, 3, 1> v) {
59-
return Eigen::Quaternion<T>::FromTwoVectors(u, v).toRotationMatrix();
60-
};
61-
6228
/// \brief: Sample point cloud from surface uniformly.
6329
template <typename T>
6430
std::vector<Eigen::Matrix<T, 3, 1>>
@@ -154,13 +120,13 @@ GenericErrorMetric<T> MeasureSurfaceError(
154120
const Eigen::Matrix<int, Eigen::Dynamic, 3> &Fs,
155121
const Eigen::Matrix<T, Eigen::Dynamic, 3> &Vt,
156122
const Eigen::Matrix<int, Eigen::Dynamic, 3> &Ft,
157-
const folly::dynamic &options) {
123+
const Json::Value &options) {
158124
// DENSELY SAMPLE FROM THE INPUT MESH
159-
auto pts_s = SamplePointCloudFromMesh(Vs, Fs, options["num_samples"].getInt());
125+
auto pts_s = SamplePointCloudFromMesh(Vs, Fs, options["num_samples"].asInt());
160126
// CONSTRUCT AABB TREE FROM TARGET MESH
161127
igl::AABB<Eigen::Matrix<T, Eigen::Dynamic, 3>, 3> tree;
162128
tree.init(Vt, Ft);
163-
Eigen::Matrix<T, Eigen::Dynamic, 3> P = feh::StdVectorOfEigenVectorToEigenMatrix(pts_s); // query point list
129+
Eigen::Matrix<T, Eigen::Dynamic, 3> P = StdVectorOfEigenVectorToEigenMatrix(pts_s); // query point list
164130
Eigen::VectorXd D2; // squared distance
165131
Eigen::VectorXi I; // index into face list Ft
166132
Eigen::Matrix<T, Eigen::Dynamic, 3> C; // closest point in mesh, NOT necessarily a vertex
@@ -182,8 +148,8 @@ template <typename T>
182148
std::array<GenericErrorMetric<T>, 2> MeasurePoseError(
183149
const std::vector<Eigen::Matrix<T, 3, 4>> &Gs,
184150
const std::vector<Eigen::Matrix<T, 3, 4>> &Gt,
185-
const folly::dynamic &options) {
186-
T thresh = (T) options["dist_thresh"].getDouble();
151+
const Json::Value &options) {
152+
T thresh = (T) options["dist_thresh"].asDouble();
187153
int match_counter(0);
188154
std::vector<T> t_err, r_err;
189155
for (int i = 0; i < Gs.size(); ++i) {

‎include/tool.h‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#pragma once
2-
#include "eigen_alias.h"
2+
#include "alias.h"
33

44
// stl
55
#include <unordered_map>
66
#include <memory>
77
#include <list>
88

99
// 3rd party
10-
#include "folly/dynamic.h"
1110
#include "Core/Core.h"
1211

1312
namespace feh {
@@ -34,13 +33,13 @@ struct Model {
3433
////////////////////////////////////////////////////////////
3534

3635
/// \brief: Annotation procedure. Automated tool to align models to scene.
37-
void AnnotationTool(const folly::dynamic &config);
36+
void AnnotationTool(const Json::Value &config);
3837

3938
/// \brief: Enumerate possible azimuth rotation and perform ICP to find the best transformation to align the
4039
/// model to the scene. Both model and scene are represented as a point cloud.
4140
Eigen::Matrix4d RegisterModelToScene(std::shared_ptr <open3d::PointCloud> model,
4241
std::shared_ptr <open3d::PointCloud> scene,
43-
const folly::dynamic options);
42+
const Json::Value options);
4443
/// \brief: Helper.
4544
double MinY(const std::vector<Eigen::Vector3d> &v);
4645

@@ -49,7 +48,7 @@ double MinY(const std::vector<Eigen::Vector3d> &v);
4948
////////////////////////////////////////////////////////////
5049

5150
/// \brief: Align semantic mapping and RGB-D reconstruction for quantitative evaluation.
52-
void MeshAlignment(const folly::dynamic &config);
51+
void MeshAlignment(const Json::Value &config);
5352

5453
/// \Brief: Find the rigid body transformation to align the two lists of objects.
5554
/// Method: find two objects with same shape name in the tgt and src. Compute the relative
@@ -85,7 +84,7 @@ Eigen::Matrix4d OptimizeAlignment(
8584
open3d::RegistrationResult ICPRefinement(std::shared_ptr<open3d::PointCloud> scene,
8685
const std::unordered_map<int, Model> &src,
8786
const Eigen::Matrix4d &T_scene_src,
88-
const folly::dynamic &options);
87+
const Json::Value &options);
8988

9089

9190
/// \brief: Assemble the scene mesh by:
@@ -95,28 +94,28 @@ open3d::RegistrationResult ICPRefinement(std::shared_ptr<open3d::PointCloud> sce
9594
/// \param objects: List of shape name, pose pairs.
9695
/// \param alignment: Corvis to EF alignment.
9796
/// \param vertices, faces: Assembled mesh.
98-
void AssembleScene(const folly::dynamic &config,
97+
void AssembleScene(const Json::Value &config,
9998
const std::list<std::pair<std::string, Eigen::Matrix<double, 3, 4> > > &objects,
10099
const Eigen::Matrix<double, 3, 4> &alignment,
101100
std::vector<Eigen::Matrix<double, 3, 1>> &vertices,
102101
std::vector<Eigen::Matrix<int, 3, 1>> &faces);
103102
/// \brief: Visualize semantic reconstruction with sparse point cloud from VIO.
104103
/// \param V, F: optional output vertex and face arrays in ElasticFusion frame
105104
/// \param G: optional output array of object poses aligned to ElasticFusion frame
106-
void AssembleResult(const folly::dynamic &config,
105+
void AssembleResult(const Json::Value &config,
107106
Eigen::Matrix<double, Eigen::Dynamic, 3> *V=nullptr,
108107
Eigen::Matrix<int, Eigen::Dynamic, 3> *F=nullptr,
109108
std::vector<Eigen::Matrix<double, 3, 4>> *G=nullptr);
110-
void VisualizeResult(const folly::dynamic &config);
109+
void VisualizeResult(const Json::Value &config);
111110
/// \brief: Visualize ground truth with annotation.
112111
/// \param V, F: optional output vertex and face arrays in ElasticFusion frame
113112
/// \param G: optional output array of object poses aligned to ElasticFusion frame
114-
void AssembleGroundTruth(const folly::dynamic &config,
113+
void AssembleGroundTruth(const Json::Value &config,
115114
Eigen::Matrix<double, Eigen::Dynamic, 3> *V=nullptr,
116115
Eigen::Matrix<int, Eigen::Dynamic, 3> *F=nullptr,
117116
std::vector<Eigen::Matrix<double, 3, 4>> *G=nullptr);
118117
/// \brief: Entrance to quantitative evaluation of surface reconstruction.
119118
/// MeasureSurfaceError is called internally to compute error measure.
120-
void QuantitativeEvaluation(folly::dynamic config);
119+
void QuantitativeEvaluation(Json::Value config);
121120

122121
}

0 commit comments

Comments
 (0)