RobotsIO
Loading...
Searching...
No Matches
CameraDeprojectionMatrix.cpp
1/*
2 * Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT)
3 *
4 * This software may be modified and distributed under the terms of the
5 * BSD 3-Clause license. See the accompanying LICENSE file for details.
6 */
7
8#include <RobotsIO/Camera/CameraDeprojectionMatrix.h>
9
10using namespace Eigen;
11
12
13MatrixXd RobotsIO::Camera::deprojection_matrix(const std::size_t& width, const std::size_t& height, const double& fx, const double& fy, const double& cx, const double& cy)
14{
15 MatrixXd deprojection_matrix(3, width * height);
16
17 std::size_t i = 0;
18 for (std::size_t u = 0; u < width; u++)
19 {
20 for (std::size_t v = 0; v < height; v++)
21 {
22 deprojection_matrix(0, i) = (u - cx) / fx;
23 deprojection_matrix(1, i) = (v - cy) / fy;
24 deprojection_matrix(2, i) = 1.0;
25
26 i++;
27 }
28 }
29
30 return deprojection_matrix;
31}
32
33
34Eigen::MatrixXd RobotsIO::Camera::deprojection_matrix(const CameraParameters& parameters)
35{
36 return RobotsIO::Camera::deprojection_matrix(parameters.width(), parameters.height(), parameters.fx(), parameters.fy(), parameters.cx(), parameters.cy());
37}