Skip to content

Commit

Permalink
[Fix] Bugs in camera param
Browse files Browse the repository at this point in the history
  • Loading branch information
HaiyiMei committed Oct 30, 2023
1 parent c0534b5 commit 312cc34
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion xrfeitoria/camera/camera_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def dump_params(self, output_path: PathLike) -> None:

# dump
K, R, T = self.get_KRT()
camera_param = CameraParameter(K=K, R=R, T=T)
camera_param = CameraParameter(K=K, R=R, T=T, world2cam=True)
camera_param.dump(output_path.as_posix())
logger.debug(f'Camera parameters dumped to "{output_path.as_posix()}"')

Expand Down
5 changes: 2 additions & 3 deletions xrfeitoria/camera/camera_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ def fromfile(cls, file: PathLike) -> 'CameraParameter':
"""
file = str(file)
ret_cam = PinholeCameraParameter.fromfile(file)
ret_cam.load(file)
return cls._from_pinhole(ret_cam)

@classmethod
Expand Down Expand Up @@ -158,11 +157,11 @@ def from_bin(cls, file: PathLike) -> 'CameraParameter':
# extrinsic matrix RT
x, y, z = -rotation[1], -rotation[2], -rotation[0]
R = rotation_matrix([x, y, z], order='xyz', degrees=True)
T = np.array([location[1], -location[2], location[0]]) / 100.0 # unit: meter
_T = np.array([location[1], -location[2], location[0]]) / 100.0 # unit: meter
T = -R @ _T

# construct camera parameter
cam_param = cls(K=K, R=R, T=T, world2cam=True)
cam_param.inverse_extrinsic()
return cam_param

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion xrfeitoria/utils/projector.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def project_points3d(points3d: np.ndarray, camera_param: CameraParameter) -> np.

# convert to opencv convention, and cam2world
_camera_param = camera_param.clone()
if _camera_param.world2cam:
if not _camera_param.world2cam:
_camera_param.inverse_extrinsic()
if _camera_param.convention != 'opencv':
_camera_param.convert_convention(dst='opencv')
Expand Down

0 comments on commit 312cc34

Please sign in to comment.