3 This is a 1:1 transcription of CameraResectioning.cpp.
6 from gtsam
import Cal3_S2, CustomFactor, LevenbergMarquardtOptimizer, KeyVector
7 from gtsam
import NonlinearFactor, NonlinearFactorGraph
8 from gtsam
import PinholeCameraCal3_S2, Point2, Point3, Pose3, Rot3, Values
14 model: SharedNoiseModel,
21 def error_func(this: CustomFactor, v: Values, H: list[np.ndarray]) -> np.ndarray:
22 pose = v.atPose3(this.keys()[0])
25 return camera.project(P) - p
26 Dpose = np.zeros((2, 6), order=
"F")
27 Dpoint = np.zeros((2, 3), order=
"F")
28 Dcal = np.zeros((2, 5), order=
"F")
29 result = camera.project(P, Dpose, Dpoint, Dcal) - p
38 Camera: f = 1, Image: 100x100, center: 50, 50.0
39 Pose (ground truth): (Xw, -Yw, -Zw, [0,0,2.0]')
41 3D Points: (10,10,0) (-10,10,0) (-10,-10,0) (10,-10,0)
43 2D Point: (55,45) (45,45) (45,55) (55,55)
47 calib =
Cal3_S2(1, 1, 0, 50, 50)
53 measurement_noise = Diagonal.Sigmas(np.array([0.5, 0.5]))
56 measurement_noise,
X(1), calib,
Point2(55, 45),
Point3(10, 10, 0)
61 measurement_noise,
X(1), calib,
Point2(45, 45),
Point3(-10, 10, 0)
66 measurement_noise,
X(1), calib,
Point2(45, 55),
Point3(-10, -10, 0)
71 measurement_noise,
X(1), calib,
Point2(55, 55),
Point3(10, -10, 0)
77 initial.insert(
X(1),
Pose3(
Rot3(1, 0, 0, 0, -1, 0, 0, 0, -1),
Point3(0, 0, 1)))
81 result.print(
"Final result:\n")
84 if __name__ ==
"__main__":