Skip to content

Commit 12d60e2

Browse files
authored
Merge pull request #1727 from alicevision/dev/distortionCalibration
Undistortion Calibration
2 parents 0a7a7d7 + ce18220 commit 12d60e2

15 files changed

+1312
-366
lines changed

src/aliceVision/calibration/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ set(calibration_files_headers
55
patternDetect.hpp
66
exportData.hpp
77
distortionEstimation.hpp
8+
distortionEstimationLine.hpp
9+
distortionEstimationPoint.hpp
10+
distortionEstimationGeometry.hpp
811
checkerDetector.hpp
912
checkerDetector_io.hpp
1013
)
1114

1215
# Sources
1316
set(calibration_files_sources
14-
distortionEstimation.cpp
17+
distortionEstimationLine.cpp
18+
distortionEstimationPoint.cpp
19+
distortionEstimationGeometry.cpp
1520
checkerDetector.cpp
1621
checkerDetector_io.cpp
1722
)

src/aliceVision/calibration/checkerDetector.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,43 @@ bool CheckerDetector::removeInvalidCheckerboards()
14461446

14471447
const Vec2i delta = horizontal ? Vec2i{1, 0} : Vec2i{0, 1};
14481448

1449+
/**
1450+
* Check squares for not too important angles
1451+
*/
1452+
for (int i = 0; i < board.rows() - 1; ++i)
1453+
{
1454+
for (int j = 0; j < board.cols() - 1; j++)
1455+
{
1456+
const IndexT c00 = board(i, j);
1457+
const IndexT c01 = board(i, j + 1);
1458+
const IndexT c10 = board(i + 1, j);
1459+
const IndexT c11 = board(i + 1, j + 1);
1460+
1461+
if (c00 == UndefinedIndexT || c01 == UndefinedIndexT || c10 == UndefinedIndexT || c11 == UndefinedIndexT)
1462+
{
1463+
continue;
1464+
}
1465+
1466+
Vec2 dir1 = (_corners[c01].center - _corners[c00].center).normalized();
1467+
Vec2 dir2 = (_corners[c10].center - _corners[c00].center).normalized();
1468+
Vec2 dir3 = (_corners[c10].center - _corners[c11].center).normalized();
1469+
Vec2 dir4 = (_corners[c01].center - _corners[c11].center).normalized();
1470+
1471+
double a1 = std::acos(dir1.dot(dir2));
1472+
double a2 = std::acos(dir1.dot(dir2));
1473+
1474+
if (a1 < M_PI_4 || a1 > 3.0 * M_PI_4)
1475+
{
1476+
return true;
1477+
}
1478+
1479+
if (a2 < M_PI_4 || a2 > 3.0 * M_PI_4)
1480+
{
1481+
return true;
1482+
}
1483+
}
1484+
}
1485+
14491486
for (int i = 0; i < board.rows() - delta.y(); ++i)
14501487
{
14511488
Vec2 sum{0, 0};
@@ -1610,9 +1647,8 @@ void CheckerDetector::filterNestedCheckerBoards(const size_t& height, const size
16101647
}
16111648

16121649
double mean_area = mean_squares / count_squares;
1613-
16141650
// Check that square size function is increasing
1615-
if (mean_area < previous_area * 0.8)
1651+
if (mean_area < previous_area * 0.5)
16161652
continue;
16171653

16181654
previous_area = mean_area;

src/aliceVision/calibration/distortionEstimation.hpp

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,12 @@
99
#include <aliceVision/numeric/numeric.hpp>
1010
#include <aliceVision/camera/Pinhole.hpp>
1111
#include <aliceVision/camera/Undistortion.hpp>
12-
1312
#include <vector>
1413
#include <memory>
1514

1615
namespace aliceVision {
1716
namespace calibration {
1817

19-
/**
20-
* @brief Set of 2D points that belong to the same line.
21-
*
22-
* The 2D points correspond to real-world points that are aligned and evenly spaced
23-
* observed with a camera which applies some distortion on them.
24-
*
25-
* Therefore these 2D points may not actually be aligned and evenly spaced,
26-
* and this difference with the ideal line model is used to estimate distortion.
27-
*/
28-
struct LineWithPoints
29-
{
30-
double angle;
31-
double dist;
32-
std::vector<Vec2> points;
33-
};
34-
35-
/**
36-
* @brief a pair of points coordinates
37-
*
38-
* One vector for the distorted coordinates
39-
* One vector from the undistorted coordinates
40-
*/
41-
struct PointPair
42-
{
43-
Vec2 distortedPoint;
44-
Vec2 undistortedPoint;
45-
};
46-
4718
/**
4819
* @brief Statistics on distortion parameters estimation error.
4920
*/
@@ -52,45 +23,9 @@ struct Statistics
5223
double mean;
5324
double stddev;
5425
double median;
26+
double lastDecile;
5527
double max;
5628
};
5729

58-
/**
59-
* @brief Estimate the undistortion parameters of a camera using a set of line aligned points.
60-
*
61-
* This algorithms minimizes a distance between points and lines using distortion.
62-
*
63-
* @param[out] undistortionToEstimate Undistortion object with the parameters to estimate.
64-
* @param[out] statistics Statistics on the estimation error.
65-
* @param[in] lines Set of line aligned points used to estimate distortion.
66-
* @param[in] lockCenter Lock the distortion offset during optimization.
67-
* @param[in] lockDistortions Distortion parameters to lock during optimization.
68-
* @return False if the estimation failed, otherwise true.
69-
*/
70-
bool estimate(std::shared_ptr<camera::Undistortion> undistortionToEstimate,
71-
Statistics& statistics,
72-
std::vector<LineWithPoints>& lines,
73-
bool lockCenter,
74-
const std::vector<bool>& lockDistortions);
75-
76-
77-
/**
78-
* @brief Estimate the undistortion parameters of a camera using a set of pair of undistorted/distorted points.
79-
*
80-
* This algorithms minimizes a distance between points and points using distortion.
81-
*
82-
* @param[out] undistortionToEstimate Undistortion object with the parameters to estimate.
83-
* @param[out] statistics Statistics on the estimation error.
84-
* @param[in] pointpairs Set of pair of points used to estimate distortion.
85-
* @param[in] lockCenter Lock the distortion offset during optimization.
86-
* @param[in] lockDistortions Distortion parameters to lock during optimization.
87-
* @return False if the estimation failed, otherwise true.
88-
*/
89-
bool estimate(std::shared_ptr<camera::Undistortion> undistortionToEstimate,
90-
Statistics& statistics,
91-
const std::vector<PointPair>& pointpairs,
92-
bool lockCenter,
93-
const std::vector<bool>& lockDistortions);
94-
9530
} // namespace calibration
9631
} // namespace aliceVision

0 commit comments

Comments
 (0)