Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
galgibly committed Jun 20, 2023
1 parent cea6d82 commit 671c6ce
Show file tree
Hide file tree
Showing 9 changed files with 331 additions and 267 deletions.
55 changes: 50 additions & 5 deletions modules/rgbd/src/FramePose/FramePose.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,64 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef _H_FRAME_POSE
#define _H_FRAME_POSE
#ifdef HAVE_EIGEN
#ifdef HAVE_EIGEN
#include <Eigen/Dense>
#include <opencv2/core.hpp>
#include <opencv2/core/eigen.hpp>

class FramePose {
class FramePose
{

public:
FramePose() {}

FramePose(Eigen::Matrix3d &r_mat, Eigen::Vector3d &t_vec) {
FramePose(Eigen::Matrix3d &r_mat, Eigen::Vector3d &t_vec)
{
set_values(r_mat, t_vec);
}

void set_values(Eigen::Matrix3d &r_mat, Eigen::Vector3d &t_vec) {
void set_values(Eigen::Matrix3d &r_mat, Eigen::Vector3d &t_vec)
{
this->rmat = r_mat;
this->tvec = t_vec;

Expand All @@ -30,7 +74,8 @@ class FramePose {
cv::Mat cam_pose_mat;

private:
void calculate_values() {
void calculate_values()
{
eigen2cv(rmat, R);
eigen2cv(tvec, t);
R.convertTo(R, CV_32F);
Expand Down
2 changes: 1 addition & 1 deletion modules/rgbd/src/NPnP/NPnpInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace NPnP
std::vector<Eigen::Vector3d> lines,
std::vector<double> weights,
std::vector<int> indices);

static std::shared_ptr<PnpInput> parse_input(int argc, char **pString);
};
} // namespace NPnP
Expand Down
358 changes: 179 additions & 179 deletions modules/rgbd/src/NPnP/NPnpObjective.cpp

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions modules/rgbd/src/Utils_Npnp/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
#include <Eigen/Dense>
#include <Eigen/Sparse>

namespace NPnP {
template <int ROWS>
using ColVector = Eigen::Matrix<double, ROWS, 1, Eigen::ColMajor>;
template <int COLS>
using RowVector = Eigen::Matrix<double, 1, COLS, Eigen::RowMajor>;
namespace NPnP
{
template <int ROWS>
using ColVector = Eigen::Matrix<double, ROWS, 1, Eigen::ColMajor>;
template <int COLS>
using RowVector = Eigen::Matrix<double, 1, COLS, Eigen::RowMajor>;

template <int ROWS, int COLS>
using ColMatrix = Eigen::Matrix<double, ROWS, COLS, Eigen::ColMajor>;
template <int ROWS, int COLS>
using RowMatrix = Eigen::Matrix<double, ROWS, COLS, Eigen::RowMajor>;
template <int ROWS, int COLS>
using ColMatrix = Eigen::Matrix<double, ROWS, COLS, Eigen::ColMajor>;
template <int ROWS, int COLS>
using RowMatrix = Eigen::Matrix<double, ROWS, COLS, Eigen::RowMajor>;

typedef Eigen::SparseMatrix<double, Eigen::RowMajor> SparseRowMatrix;
typedef Eigen::SparseMatrix<double, Eigen::ColMajor> SparseColMatrix;
typedef Eigen::SparseMatrix<double, Eigen::RowMajor> SparseRowMatrix;
typedef Eigen::SparseMatrix<double, Eigen::ColMajor> SparseColMatrix;

#define Y_SIZE 69
#define NUM_CONSTRAINTS 15
Expand Down
31 changes: 17 additions & 14 deletions modules/rgbd/src/Utils_Npnp/GeneralUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
#ifdef HAVE_EIGEN
#include "GeneralUtils.h"

namespace NPnP {
double find_zero_bin_search(const std::function<double(double)> &func,
double min, double max, int depth) {
while (true) {
double mid = (min + max) / 2.0;
if (depth-- == 0)
return mid;
if (func(max) <= 0)
return max;
if (func(mid) < 0)
min = mid;
else
max = mid;
namespace NPnP
{
double find_zero_bin_search(const std::function<double(double)> &func,
double min, double max, int depth)
{
while (true)
{
double mid = (min + max) / 2.0;
if (depth-- == 0)
return mid;
if (func(max) <= 0)
return max;
if (func(mid) < 0)
min = mid;
else
max = mid;
}
}
}
} // namespace NPnP
#endif
15 changes: 9 additions & 6 deletions modules/rgbd/src/Utils_Npnp/GeneralUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
#include "Definitions.h"
#include "functional"

namespace NPnP {
double find_zero_bin_search(const std::function<double(double)> &func,
double min, double max, int depth);
namespace NPnP
{
double find_zero_bin_search(const std::function<double(double)> &func,
double min, double max, int depth);

template <typename T> inline T min2(T one, T two) {
return one < two ? one : two;
}
template <typename T>
inline T min2(T one, T two)
{
return one < two ? one : two;
}
} // namespace NPnP

#endif
Expand Down
11 changes: 7 additions & 4 deletions modules/rgbd/src/Utils_Npnp/MatrixUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
#ifdef HAVE_EIGEN
#include "Definitions.h"

namespace NPnP {
template <int Size> void symmetrize(RowMatrix<Size, Size> &matrix) {
matrix = 0.5 * (matrix + matrix.transpose().eval());
}
namespace NPnP
{
template <int Size>
void symmetrize(RowMatrix<Size, Size> &matrix)
{
matrix = 0.5 * (matrix + matrix.transpose().eval());
}
} // namespace NPnP
#endif
#endif // PNP_USING_EIGEN_LIBRARY_MATRIXUTILS_H
77 changes: 42 additions & 35 deletions modules/rgbd/src/Utils_Npnp/Parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,52 @@
#include <string>
#include <vector>

namespace NPnP {
std::vector<Eigen::Vector3d> parse_csv_vector_3d(const std::string &csv_path) {
std::vector<Eigen::Vector3d> data;
std::ifstream input_file(csv_path);
std::string line;
while (input_file >> line) {
std::stringstream lineStream(line);
std::vector<double> current_vec;
std::string cell;
while (std::getline(lineStream, cell, ',')) {
current_vec.push_back(std::stod(cell));
namespace NPnP
{
std::vector<Eigen::Vector3d> parse_csv_vector_3d(const std::string &csv_path)
{
std::vector<Eigen::Vector3d> data;
std::ifstream input_file(csv_path);
std::string line;
while (input_file >> line)
{
std::stringstream lineStream(line);
std::vector<double> current_vec;
std::string cell;
while (std::getline(lineStream, cell, ','))
{
current_vec.push_back(std::stod(cell));
}
data.emplace_back(current_vec[0], current_vec[1], current_vec[2]);
}
data.emplace_back(current_vec[0], current_vec[1], current_vec[2]);
}

return std::move(data);
}
return std::move(data);
}

Eigen::MatrixXd parse_csv_matrix(const std::string &csv_path) {
std::vector<std::vector<double>> data;
std::ifstream input_file(csv_path);
std::string line;
while (input_file >> line) {
std::stringstream lineStream(line);
std::vector<double> current_vec;
std::string cell;
while (std::getline(lineStream, cell, ',')) {
current_vec.push_back(std::stod(cell));
Eigen::MatrixXd parse_csv_matrix(const std::string &csv_path)
{
std::vector<std::vector<double>> data;
std::ifstream input_file(csv_path);
std::string line;
while (input_file >> line)
{
std::stringstream lineStream(line);
std::vector<double> current_vec;
std::string cell;
while (std::getline(lineStream, cell, ','))
{
current_vec.push_back(std::stod(cell));
}
Eigen::VectorXd vector = Eigen::Map<Eigen::VectorXd, Eigen::Unaligned>(
current_vec.data(), current_vec.size());
data.emplace_back(std::move(current_vec));
}
Eigen::VectorXd vector = Eigen::Map<Eigen::VectorXd, Eigen::Unaligned>(
current_vec.data(), current_vec.size());
data.emplace_back(std::move(current_vec));
}
Eigen::MatrixXd matrix(data.size(), data[0].size());
for (int i = 0; i < data.size(); i++)
for (int j = 0; j < data[i].size(); j++)
matrix(i, j) = data[i][j];
Eigen::MatrixXd matrix(data.size(), data[0].size());
for (int i = 0; i < data.size(); i++)
for (int j = 0; j < data[i].size(); j++)
matrix(i, j) = data[i][j];

return matrix;
}
return matrix;
}
} // namespace NPnP
#endif
26 changes: 14 additions & 12 deletions modules/rgbd/src/Utils_Npnp/Parsing.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@
#include <string>
#include <vector>

namespace NPnP {
template <typename T>
std::vector<T> parse_csv_array(const std::string &csv_path) {
std::vector<T> data;
std::ifstream input_file(csv_path);
T value;
while (input_file >> value)
data.push_back(value);
namespace NPnP
{
template <typename T>
std::vector<T> parse_csv_array(const std::string &csv_path)
{
std::vector<T> data;
std::ifstream input_file(csv_path);
T value;
while (input_file >> value)
data.push_back(value);

return std::move(data);
}
return std::move(data);
}

std::vector<Eigen::Vector3d> parse_csv_vector_3d(const std::string &csv_path);
std::vector<Eigen::Vector3d> parse_csv_vector_3d(const std::string &csv_path);

Eigen::MatrixXd parse_csv_matrix(const std::string &csv_path);
Eigen::MatrixXd parse_csv_matrix(const std::string &csv_path);
} // namespace NPnP
#endif
#endif // PNP_USING_EIGEN_LIBRARY_PARSING_H

0 comments on commit 671c6ce

Please sign in to comment.