使用Ceres-solver最小化reprojection error和photometric loss
install (on Mac + Clion)
- CMD
brew install ceres-solver
brew install opencv
- CMakeList.txt
find_package(Ceres REQUIRED)
include_directories(${CERES_INCLUDE_DIRS})
target_link_libraries(helloworld ${CERES_LIBRARIES})
Rotation Vector
- Three dimensions
- Direction is the axis and magnitude is the angle in radians (counter clockwise, axis centered)
- Use Rodrigues’ rotation formula to calculate (k is the unit vector of the rotation axis):
v r o t = v cos θ + ( k × v ) sin θ + k ( k ⋅ v ) ( 1 − cos θ ) v_{rot} = v\cos\theta + (k \times v)\sin\theta + k(k \cdot v)(1-\cos\theta) vrot=vcosθ+(k×v)sinθ+k(k⋅v)(1−cosθ)
Local Coordinate of an Aruco Marker
- A detected marker: 4 corners, [top-left, top-right, down-right, down-left]
- Let length of one square side be L, corners’ coordinate:
- Top-left: [-L/2, L/2, 0]
- Top-right: [L/2, L/2, 0]
- Down-right: [L/2, -L/2, 0]
- Down-left: [-L/2, -L/2, 0]
Minimize Reprojection Error
(Ceres-solver优化时,需要计算loss function对各参数的偏导的解析解,因此在构造reprojection error时不能使用外部的库,只能使用直接的代数计算和ceres-solver提供的函数)
Optimize 6 parameters:
-
R: 3 paramaters for rotation using Rodrigues’ rotation formula
-
t: 3 parameters for translation
Convert from world to camera coordinate, (P: point in camera coordinate, X: point in world coordinate):
P = R ∗ X + t (1) P = R * X + t \tag{1} P=R∗X+t(1)
Perspective projection:
p = P / P . z (2) p = P / P.z \tag{2} p=P/P.z(2)
Radial distortion:
d i s t o r t ( p ) = 1.0 + k 1 ∗ ∣ ∣ p ∣ ∣ 2 + k 2 ∗ ∣ ∣ p ∣ ∣ 4 (3) distort(p) = 1.0 + k_1 * ||p||^2 + k_2 * ||p||^4 \tag{3} distort(p)=1.0+k1