13
13
14
14
15
15
def cameras_from_opencv_projection (
16
- rvec : torch .Tensor ,
16
+ R : torch .Tensor ,
17
17
tvec : torch .Tensor ,
18
18
camera_matrix : torch .Tensor ,
19
19
image_size : torch .Tensor ,
20
20
) -> PerspectiveCameras :
21
21
"""
22
22
Converts a batch of OpenCV-conventioned cameras parametrized with the
23
- axis-angle rotation vectors `rvec `, translation vectors `tvec`, and the camera
23
+ rotation matrices `R `, translation vectors `tvec`, and the camera
24
24
calibration matrices `camera_matrix` to `PerspectiveCameras` in PyTorch3D
25
25
convention.
26
26
@@ -32,16 +32,20 @@ def cameras_from_opencv_projection(
32
32
More specifically, the OpenCV convention projects points to the OpenCV screen
33
33
space as follows:
34
34
```
35
- x_screen_opencv = camera_matrix @ (exp(rvec) @ x_world + tvec)
35
+ x_screen_opencv = camera_matrix @ (R @ x_world + tvec)
36
36
```
37
37
followed by the homogenization of `x_screen_opencv`.
38
38
39
39
Note:
40
- The parameters `rvec, tvec, camera_matrix` correspond, e.g., to the inputs
41
- of `cv2.projectPoints`, or to the ouputs of `cv2.calibrateCamera`.
40
+ The parameters `R, tvec, camera_matrix` correspond to the outputs of
41
+ `cv2.decomposeProjectionMatrix`.
42
+
43
+ The `rvec` parameter of the `cv2.projectPoints` is an axis-angle vector
44
+ that can be converted to the rotation matrix `R` expected here by
45
+ calling the `so3_exp_map` function.
42
46
43
47
Args:
44
- rvec : A batch of axis-angle rotation vectors of shape `(N, 3)`.
48
+ R : A batch of rotation matrices of shape `(N, 3 , 3)`.
45
49
tvec: A batch of translation vectors of shape `(N, 3)`.
46
50
camera_matrix: A batch of camera calibration matrices of shape `(N, 3, 3)`.
47
51
image_size: A tensor of shape `(N, 2)` containing the sizes of the images
@@ -51,7 +55,6 @@ def cameras_from_opencv_projection(
51
55
cameras_pytorch3d: A batch of `N` cameras in the PyTorch3D convention.
52
56
"""
53
57
54
- R = so3_exp_map (rvec )
55
58
focal_length = torch .stack ([camera_matrix [:, 0 , 0 ], camera_matrix [:, 1 , 1 ]], dim = - 1 )
56
59
principal_point = camera_matrix [:, :2 , 2 ]
57
60
@@ -84,21 +87,25 @@ def opencv_from_cameras_projection(
84
87
) -> Tuple [torch .Tensor , torch .Tensor , torch .Tensor ]:
85
88
"""
86
89
Converts a batch of `PerspectiveCameras` into OpenCV-convention
87
- axis-angle rotation vectors `rvec `, translation vectors `tvec`, and the camera
90
+ rotation matrices `R `, translation vectors `tvec`, and the camera
88
91
calibration matrices `camera_matrix`. This operation is exactly the inverse
89
92
of `cameras_from_opencv_projection`.
90
93
91
94
Note:
92
- The parameters `rvec, tvec, camera_matrix` correspond, e.g., to the inputs
93
- of `cv2.projectPoints`, or to the ouputs of `cv2.calibrateCamera`.
95
+ The outputs `R, tvec, camera_matrix` correspond to the outputs of
96
+ `cv2.decomposeProjectionMatrix`.
97
+
98
+ The `rvec` parameter of the `cv2.projectPoints` is an axis-angle vector
99
+ that can be converted from the returned rotation matrix `R` here by
100
+ calling the `so3_log_map` function.
94
101
95
102
Args:
96
103
cameras: A batch of `N` cameras in the PyTorch3D convention.
97
104
image_size: A tensor of shape `(N, 2)` containing the sizes of the images
98
105
(height, width) attached to each camera.
99
106
100
107
Returns:
101
- rvec : A batch of axis-angle rotation vectors of shape `(N, 3)`.
108
+ R : A batch of rotation matrices of shape `(N, 3 , 3)`.
102
109
tvec: A batch of translation vectors of shape `(N, 3)`.
103
110
camera_matrix: A batch of camera calibration matrices of shape `(N, 3, 3)`.
104
111
"""
@@ -122,5 +129,4 @@ def opencv_from_cameras_projection(
122
129
camera_matrix [:, 2 , 2 ] = 1.0
123
130
camera_matrix [:, 0 , 0 ] = focal_length [:, 0 ]
124
131
camera_matrix [:, 1 , 1 ] = focal_length [:, 1 ]
125
- rvec = so3_log_map (R )
126
- return rvec , tvec , camera_matrix
132
+ return R , tvec , camera_matrix
0 commit comments