Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
mmdetection3d
Commits
63aa8f66
Commit
63aa8f66
authored
Jun 13, 2020
by
liyinhao
Browse files
change doc string, delete unnecessary funcs
parent
f2b01720
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
40 deletions
+77
-40
data/scannet/load_scannet_data.py
data/scannet/load_scannet_data.py
+1
-1
data/scannet/scannet_utils.py
data/scannet/scannet_utils.py
+22
-4
data/sunrgbd/sunrgbd_utils.py
data/sunrgbd/sunrgbd_utils.py
+54
-35
No files found.
data/scannet/load_scannet_data.py
View file @
63aa8f66
...
@@ -69,7 +69,7 @@ def export(mesh_file,
...
@@ -69,7 +69,7 @@ def export(mesh_file,
output_file(str): Path of the output folder.
output_file(str): Path of the output folder.
Default: None.
Default: None.
Return:
Return
s
:
ndarray: Vertices of points data.
ndarray: Vertices of points data.
ndarray: Indexes of label.
ndarray: Indexes of label.
ndarray: Indexes of instance.
ndarray: Indexes of instance.
...
...
data/scannet/scannet_utils.py
View file @
63aa8f66
...
@@ -11,7 +11,14 @@ from plyfile import PlyData
...
@@ -11,7 +11,14 @@ from plyfile import PlyData
def
represents_int
(
s
):
def
represents_int
(
s
):
''' if string s represents an int. '''
"""Judge whether string s represents an int.
Args:
s(str): The input string to be judged.
Returns:
bool: Whether s represents int or not.
"""
try
:
try
:
int
(
s
)
int
(
s
)
return
True
return
True
...
@@ -34,7 +41,13 @@ def read_label_mapping(filename,
...
@@ -34,7 +41,13 @@ def read_label_mapping(filename,
def
read_mesh_vertices
(
filename
):
def
read_mesh_vertices
(
filename
):
""" read XYZ for each vertex.
"""Read XYZ for each vertex.
Args:
filename(str): The name of the mesh vertices file.
Returns:
ndarray: Vertices.
"""
"""
assert
os
.
path
.
isfile
(
filename
)
assert
os
.
path
.
isfile
(
filename
)
with
open
(
filename
,
'rb'
)
as
f
:
with
open
(
filename
,
'rb'
)
as
f
:
...
@@ -48,8 +61,13 @@ def read_mesh_vertices(filename):
...
@@ -48,8 +61,13 @@ def read_mesh_vertices(filename):
def
read_mesh_vertices_rgb
(
filename
):
def
read_mesh_vertices_rgb
(
filename
):
""" read XYZ RGB for each vertex.
"""Read XYZ and RGB for each vertex.
Note: RGB values are in 0-255
Args:
filename(str): The name of the mesh vertices file.
Returns:
Vertices. Note that RGB values are in 0-255.
"""
"""
assert
os
.
path
.
isfile
(
filename
)
assert
os
.
path
.
isfile
(
filename
)
with
open
(
filename
,
'rb'
)
as
f
:
with
open
(
filename
,
'rb'
)
as
f
:
...
...
data/sunrgbd/sunrgbd_utils.py
View file @
63aa8f66
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
#
#
# This source code is licensed under the MIT license found in the
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
# LICENSE file in the root directory of this source tree.
'''
Provides Python helper function to read My SUNRGBD dataset.
"""
Provides Python helper function to read My SUNRGBD dataset.
Author: Charles R. Qi
Author: Charles R. Qi
Date: October, 2017
Date: October, 2017
...
@@ -10,7 +10,7 @@ Date: October, 2017
...
@@ -10,7 +10,7 @@ Date: October, 2017
Updated by Charles R. Qi
Updated by Charles R. Qi
Date: December, 2018
Date: December, 2018
Note: removed basis loading.
Note: removed basis loading.
'''
"""
import
cv2
import
cv2
import
numpy
as
np
import
numpy
as
np
...
@@ -39,7 +39,7 @@ def flip_axis_to_camera(pc):
...
@@ -39,7 +39,7 @@ def flip_axis_to_camera(pc):
Args:
Args:
pc(ndarray): points in depth axis.
pc(ndarray): points in depth axis.
Return:
Return
s
:
ndarray: points in camera axis.
ndarray: points in camera axis.
"""
"""
pc2
=
np
.
copy
(
pc
)
pc2
=
np
.
copy
(
pc
)
...
@@ -79,20 +79,22 @@ class SUNObject3d(object):
...
@@ -79,20 +79,22 @@ class SUNObject3d(object):
class
SUNRGBD_Calibration
(
object
):
class
SUNRGBD_Calibration
(
object
):
''' Calibration matrices and utils
"""Calibration matrices and utils
We define five coordinate system in SUN RGBD dataset
We define five coordinate system in SUN RGBD dataset:
camera coodinate:
camera coodinate:
Z is forward, Y is downward, X is rightward
Z is forward, Y is downward, X is rightward
.
depth coordinate:
depth coordinate:
Just change axis order and flip up-down axis from camera coord
Just change axis order and flip up-down axis from camera coord
.
upright depth coordinate: tilted depth coordinate by Rtilt such that
upright depth coordinate: tilted depth coordinate by Rtilt such that
Z is gravity direction, Z is up-axis, Y is forward, X is right-ward
Z is gravity direction, Z is up-axis, Y is forward,
X is right-ward.
upright camera coordinate:
upright camera coordinate:
Just change axis order and flip up-down axis from upright
Just change axis order and flip up-down axis from upright
.
depth coordinate
depth coordinate
image coordinate:
image coordinate:
...
@@ -106,8 +108,12 @@ class SUNRGBD_Calibration(object):
...
@@ -106,8 +108,12 @@ class SUNRGBD_Calibration(object):
depth coordinate.
depth coordinate.
2d boxes are in image coordinate
2d boxes are in image coordinate
We generate frustum point cloud and 3d box in upright camera coordinate
We generate frustum point cloud and 3d box
'''
in upright camera coordinate.
Args:
calib_filepath(str): Path of the calib file.
"""
def
__init__
(
self
,
calib_filepath
):
def
__init__
(
self
,
calib_filepath
):
lines
=
[
line
.
rstrip
()
for
line
in
open
(
calib_filepath
)]
lines
=
[
line
.
rstrip
()
for
line
in
open
(
calib_filepath
)]
...
@@ -121,28 +127,35 @@ class SUNRGBD_Calibration(object):
...
@@ -121,28 +127,35 @@ class SUNRGBD_Calibration(object):
self
.
c_v
=
self
.
K
[
1
,
2
]
self
.
c_v
=
self
.
K
[
1
,
2
]
def
project_upright_depth_to_camera
(
self
,
pc
):
def
project_upright_depth_to_camera
(
self
,
pc
):
''' project point cloud from depth coord to camera coordinate
"""Convert pc coordinate from depth to image.
Input: (N,3) Output: (N,3)
'''
Args:
pc(ndarray): Point cloud in depth coordinate.
Returns:
pc(ndarray): Point cloud in camera coordinate.
"""
# Project upright depth to depth coordinate
# Project upright depth to depth coordinate
pc2
=
np
.
dot
(
np
.
transpose
(
self
.
Rtilt
),
np
.
transpose
(
pc
[:,
pc2
=
np
.
dot
(
np
.
transpose
(
self
.
Rtilt
),
np
.
transpose
(
pc
[:,
0
:
3
]))
# (3,n)
0
:
3
]))
# (3,n)
return
flip_axis_to_camera
(
np
.
transpose
(
pc2
))
return
flip_axis_to_camera
(
np
.
transpose
(
pc2
))
def
project_upright_depth_to_image
(
self
,
pc
):
def
project_upright_depth_to_image
(
self
,
pc
):
''' Input: (N,3) Output: (N,2) UV and (N,) depth '''
"""Convert pc coordinate from depth to image.
Args:
pc(ndarray): Point cloud in depth coordinate.
Returns:
ndarray: [N, 2] uv.
ndarray: [n,] depth.
"""
pc2
=
self
.
project_upright_depth_to_camera
(
pc
)
pc2
=
self
.
project_upright_depth_to_camera
(
pc
)
uv
=
np
.
dot
(
pc2
,
np
.
transpose
(
self
.
K
))
# (n,3)
uv
=
np
.
dot
(
pc2
,
np
.
transpose
(
self
.
K
))
# (n,3)
uv
[:,
0
]
/=
uv
[:,
2
]
uv
[:,
0
]
/=
uv
[:,
2
]
uv
[:,
1
]
/=
uv
[:,
2
]
uv
[:,
1
]
/=
uv
[:,
2
]
return
uv
[:,
0
:
2
],
pc2
[:,
2
]
return
uv
[:,
0
:
2
],
pc2
[:,
2
]
def
project_upright_depth_to_upright_camera
(
self
,
pc
):
return
flip_axis_to_camera
(
pc
)
def
project_upright_camera_to_upright_depth
(
self
,
pc
):
return
flip_axis_to_depth
(
pc
)
def
project_image_to_camera
(
self
,
uv_depth
):
def
project_image_to_camera
(
self
,
uv_depth
):
n
=
uv_depth
.
shape
[
0
]
n
=
uv_depth
.
shape
[
0
]
x
=
((
uv_depth
[:,
0
]
-
self
.
c_u
)
*
uv_depth
[:,
2
])
/
self
.
f_u
x
=
((
uv_depth
[:,
0
]
-
self
.
c_u
)
*
uv_depth
[:,
2
])
/
self
.
f_u
...
@@ -153,14 +166,6 @@ class SUNRGBD_Calibration(object):
...
@@ -153,14 +166,6 @@ class SUNRGBD_Calibration(object):
pts_3d_camera
[:,
2
]
=
uv_depth
[:,
2
]
pts_3d_camera
[:,
2
]
=
uv_depth
[:,
2
]
return
pts_3d_camera
return
pts_3d_camera
def
project_image_to_upright_camerea
(
self
,
uv_depth
):
pts_3d_camera
=
self
.
project_image_to_camera
(
uv_depth
)
pts_3d_depth
=
flip_axis_to_depth
(
pts_3d_camera
)
pts_3d_upright_depth
=
np
.
transpose
(
np
.
dot
(
self
.
Rtilt
,
np
.
transpose
(
pts_3d_depth
)))
return
self
.
project_upright_depth_to_upright_camera
(
pts_3d_upright_depth
)
def
rotz
(
t
):
def
rotz
(
t
):
"""Rotation about the z-axis."""
"""Rotation about the z-axis."""
...
@@ -204,7 +209,16 @@ def in_hull(p, hull):
...
@@ -204,7 +209,16 @@ def in_hull(p, hull):
def
extract_pc_in_box3d
(
pc
,
box3d
):
def
extract_pc_in_box3d
(
pc
,
box3d
):
''' pc: (N,3), box3d: (8,3) '''
"""Extract point cloud in box3d.
Args:
pc(ndarray): [N, 3] Point cloud.
box3d(ndarray): [8,3] 3d box.
Returns:
ndarray: Selected point cloud.
ndarray: Indices of selected point cloud.
"""
box3d_roi_inds
=
in_hull
(
pc
[:,
0
:
3
],
box3d
)
box3d_roi_inds
=
in_hull
(
pc
[:,
0
:
3
],
box3d
)
return
pc
[
box3d_roi_inds
,
:],
box3d_roi_inds
return
pc
[
box3d_roi_inds
,
:],
box3d_roi_inds
...
@@ -223,12 +237,17 @@ def my_compute_box_3d(center, size, heading_angle):
...
@@ -223,12 +237,17 @@ def my_compute_box_3d(center, size, heading_angle):
def
compute_box_3d
(
obj
,
calib
):
def
compute_box_3d
(
obj
,
calib
):
'''
Takes an object and a projection matrix (P) and projects the 3d
"""
Takes an object and a projection matrix (P) and projects the 3d
bounding box into the image plane.
bounding box into the image plane.
Args:
obj(SUNObject3d): Instance of SUNObject3d.
calib(SUNRGBD_Calibration): Instance of SUNRGBD_Calibration.
Returns:
Returns:
corners_2d
:
(
8,2
)
array in image coord.
ndarray
:
[
8,2
]
array in image coord.
corners_3d:
(
8,3
)
array in in upright depth coord.
corners_3d:
[
8,3
]
array in in upright depth coord.
'''
"""
center
=
obj
.
centroid
center
=
obj
.
centroid
# compute rotational matrix around yaw axis
# compute rotational matrix around yaw axis
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment