Skip to content

Free Motion Capture for Everyone πŸ’€βœ¨

TypeScript

commit before switch to main

jonmatthis0907e954c3b1
diff --git a/freemocap/pipelines/calibration_pipeline/positional_6dof.py b/freemocap/pipelines/calibration_pipeline/positional_6dof.py
index 08aea742..f5606b23 100644
--- a/freemocap/pipelines/calibration_pipeline/positional_6dof.py
+++ b/freemocap/pipelines/calibration_pipeline/positional_6dof.py
@@ -12,6 +12,9 @@ class Positional6DoF(BaseModel):
@property
def transformation_matrix(self) -> TransformationMatrix:
+ return self.get_transformation_matrix()
+
+ def get_transformation_matrix(self, return_jacobian:bool=False) -> TransformationMatrix | tuple[TransformationMatrix, NDArray[Shape['3, 9'], np.float32]]:
"""
Returns the transformation matrix for this 6DoF pose in the form of a 4x4 matrix (homogeneous coordinates)
the left upper 3x3 matrix is the rotation matrix, and the rightmost column is the translation vector.
@@ -20,14 +23,15 @@ class Positional6DoF(BaseModel):
transformation_matrix = np.zeros((4, 4))
- transformation_matrix[:3, :3], _ = cv2.Rodrigues(self.rotation)
+ transformation_matrix[:3, :3], jacobian = cv2.Rodrigues(self.rotation)
transformation_matrix[:3, 3] = self.translation.flatten()
transformation_matrix[3, 3] = 1
+ if return_jacobian:
+ return transformation_matrix, jacobian
return transformation_matrix
if __name__ == "__main__":
positional_6dof = Positional6DoF()
print(positional_6dof.transformation_matrix)
- print(positional_6dof.transformation_matrix.shape)
print(positional_6dof.model_dump_json(indent=2))
\ No newline at end of file
diff --git a/freemocap/pipelines/calibration_pipeline/single_camera_calibrator.py b/freemocap/pipelines/calibration_pipeline/single_camera_calibrator.py
index 96a8b689..4fafbe83 100644
--- a/freemocap/pipelines/calibration_pipeline/single_camera_calibrator.py
+++ b/freemocap/pipelines/calibration_pipeline/single_camera_calibrator.py
@@ -47,12 +47,14 @@ class SingleCameraCalibrator(BaseModel):
charuco_observations: CharucoObservations = Field(default_factory=CharucoObservations)
reprojection_error_by_view: list[float]
- mean_reprojection_errors: list[float]
+ reprojection_error_per_point_by_view: list[NDArray[Shape["* n_points, 2 xy"], np.float32]]
+ mean_reprojection_error: float|None = None
+
camera_calibration_residuals: list[float]
@property
def has_calibration(self):
- return len(self.mean_reprojection_errors) > 0
+ return self.mean_reprojection_error is not None
@property
def current_estimate(self) -> SingleCameraCalibrationEstimate:
@@ -121,7 +123,8 @@ class SingleCameraCalibrator(BaseModel):
rotation_vectors=[],
translation_vectors=[],
reprojection_error_by_view=[],
- mean_reprojection_errors=[],
+ mean_reprojection_error=0,
+ reprojection_error_per_point_by_view=[],
camera_calibration_residuals=[],
)
@@ -168,8 +171,6 @@ class SingleCameraCalibrator(BaseModel):
self._update_reprojection_error()
self._drop_suboptimal_views()
-
-
def get_board_pose(self, object_points: np.ndarray[..., 3], image_points: np.ndarray[..., 2]) -> tuple[
np.ndarray[..., 3], np.ndarray[..., 3]]:
if len(object_points) < 6:
@@ -231,21 +232,23 @@ class SingleCameraCalibrator(BaseModel):
if len(self.image_points_views) == 0:
raise ValueError("No image points provided")
error = None
- jacobian = None #2Nx(10+) jacobian
+ jacobian = None
+ self.reprojection_error_per_point_by_view = []
self.reprojection_error_by_view = []
for view_index in range(len(self.image_points_views)):
- projected_image_points, jacobian = cv2.projectPoints(objectPoints= self.object_points_views[view_index],
- rvec= self.rotation_vectors[view_index],
- tvec= self.translation_vectors[view_index],
- cameraMatrix= self.camera_matrix,
- distCoeffs= self.distortion_coefficients,
- aspectRatio=self.image_size[0]/self.image_size[1]
+ projected_image_points, jacobian = cv2.projectPoints(objectPoints=self.object_points_views[view_index],
+ rvec=self.rotation_vectors[view_index],
+ tvec=self.translation_vectors[view_index],
+ cameraMatrix=self.camera_matrix,
+ distCoeffs=self.distortion_coefficients,
+ aspectRatio=self.image_size[0] / self.image_size[1]
)
- self.reprojection_error_by_view.append(
- np.mean(np.abs(self.image_points_views[view_index] - np.squeeze(projected_image_points))))
+ self.reprojection_error_per_point_by_view.append(
+ np.abs(self.image_points_views[view_index] - np.squeeze(projected_image_points)))
+
+ self.reprojection_error_by_view.append(np.nanmean(self.reprojection_error_per_point_by_view[-1]))
- self.mean_reprojection_errors.append(
- np.mean(self.reprojection_error_by_view) if self.reprojection_error_by_view else -1)
+ self.mean_reprojection_error = float(np.nanmean(self.reprojection_error_by_view))
- print(f"Mean reprojection errors: {self.mean_reprojection_errors}")
+ print(f"Mean reprojection error: {self.mean_reprojection_error:.3f} pixels, reprojection error by view: {self.reprojection_error_by_view}")