Galaxis Codebase
1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
CameraCalibration.cpp
Go to the documentation of this file.
1
#include "
galaxis/CameraCalibration.hpp
"
2
#include <vector>
3
#include <opencv2/imgproc.hpp>
4
#include <iostream>
5
6
cv::Mat
galaxis::camera::getOptimalCameraMatrix
() {
7
// https://docs.opencv.org/3.4/d9/d0c/group__calib3d.html#ga7a6c4e032c97f03ba747966e6ad862b1
8
return
cv::getOptimalNewCameraMatrix(
matrixD_mtx
,
matrixK_dist
, cv::Size(256,512), 1);
//, cv::Size(256,512));
9
}
10
11
cv::Mat
galaxis::camera::getPerspectiveTransform
() {
12
// top view
13
// pts1 = np.float32( [[112.0,123.5],[437.0,130.0],[327.5,46.0],[213.0,44.5]])
14
// pts2 = np.float32( [[148, 174], [148+256, 174], [148+256, 174-152], [148, 174-152]])
15
// cv::Mat matrixTopView_1 = (cv::Mat1d(2, 4) << 112.0,123.5, 437.0,130.0, 327.5,46.0, 213.0,44.5);
16
// cv::Mat matrixTopView_2 = (cv::Mat1d(2, 4) << 148, 174, 148+256, 174, 148+256, 174-152, 148, 174-152);
17
18
// std::cout << matrixTopView_1.size() << std::endl;
19
// std::cout << matrixTopView_2.size() << std::endl;
20
// return cv::getPerspectiveTransform(matrixTopView_1, matrixTopView_2);
21
22
// top view transform matrix:
23
// [[ 6.04105082e+01 1.70937149e+02 -1.63898624e+04]
24
// [-2.05272012e+00 1.60637541e+02 -6.10401861e+03]
25
// [-5.84629918e-03 6.25657111e-01 1.00000000e+00]]
26
return
(cv::Mat1d(3, 3) <<
27
6.04105082e+01, 1.70937149e+02, -1.63898624e+04,
28
-2.05272012e+00, 1.60637541e+02, -6.10401861e+03,
29
-5.84629918e-03, 6.25657111e-01, 1.00000000e+00
30
);
31
32
// inverted top view transform matrix
33
// [[ 1.57596937e-02, -4.12850966e-02, 6.29421326e+00],
34
// [ 1.49447281e-04, -1.40223872e-04, 1.59349124e+00],
35
// [-1.36686947e-06, -1.53632964e-04, 3.98187279e-02]]
36
37
// backwards
38
// _, IM = cv2.invert(M)
39
// x1 = 159
40
// y1 = 99
41
// coord = [x1, y1] + [1]
42
// P = np.float32(coord)
43
44
// x, y, z = np.dot(IM, P)
45
// #Divide x and y by z to get 2D in frame {A}
46
// new_x = x/z
47
// new_y = y/z
48
}
CameraCalibration.hpp
galaxis::camera::getPerspectiveTransform
cv::Mat getPerspectiveTransform()
Definition:
CameraCalibration.cpp:11
galaxis::camera::matrixK_dist
const cv::Mat matrixK_dist
Definition:
CameraCalibration.hpp:30
galaxis::camera::matrixD_mtx
const cv::Mat matrixD_mtx
Definition:
CameraCalibration.hpp:28
galaxis::camera::getOptimalCameraMatrix
cv::Mat getOptimalCameraMatrix()
Definition:
CameraCalibration.cpp:6
utilities
src
CameraCalibration.cpp
Generated by
1.8.17