(
pcd,
size=(64, 1024),
fov=(3, -25),
depth_range=(1.0, 56.0),
remission=None,
labels=None,
**kwargs
)
| 1028 | return collated |
| 1029 | |
| 1030 | def pcd2range( |
| 1031 | pcd, |
| 1032 | size=(64, 1024), |
| 1033 | fov=(3, -25), |
| 1034 | depth_range=(1.0, 56.0), |
| 1035 | remission=None, |
| 1036 | labels=None, |
| 1037 | **kwargs |
| 1038 | ): |
| 1039 | # pcd : [N,3] |
| 1040 | |
| 1041 | # laser parameters |
| 1042 | fov_up = fov[0] / 180.0 * np.pi # field of view up in rad |
| 1043 | fov_down = fov[1] / 180.0 * np.pi # field of view down in rad |
| 1044 | fov_range = abs(fov_down) + abs(fov_up) # get field of view total in rad |
| 1045 | |
| 1046 | # get depth (distance) of all points |
| 1047 | depth = np.linalg.norm(pcd, 2, axis=1) |
| 1048 | |
| 1049 | # mask points out of range |
| 1050 | mask = np.logical_and(depth > depth_range[0], depth < depth_range[1]) |
| 1051 | depth, pcd = depth[mask], pcd[mask] |
| 1052 | |
| 1053 | # get scan components |
| 1054 | scan_x, scan_y, scan_z = pcd[:, 0], pcd[:, 1], pcd[:, 2] |
| 1055 | |
| 1056 | # get angles of all points |
| 1057 | yaw = -np.arctan2(scan_y, scan_x) |
| 1058 | pitch = np.arcsin(scan_z / depth) |
| 1059 | |
| 1060 | # get projections in image coords |
| 1061 | proj_x = 0.5 * (yaw / np.pi + 1.0) # in [0.0, 1.0] |
| 1062 | proj_y = 1.0 - (pitch + abs(fov_down)) / fov_range # in [0.0, 1.0] |
| 1063 | |
| 1064 | # scale to image size using angular resolution |
| 1065 | proj_x *= size[1] # in [0.0, W] |
| 1066 | proj_y *= size[0] # in [0.0, H] |
| 1067 | |
| 1068 | # round and clamp for use as index |
| 1069 | proj_x = np.maximum(0, np.minimum(size[1] - 1, np.floor(proj_x))).astype(np.int32) # in [0,W-1] |
| 1070 | proj_y = np.maximum(0, np.minimum(size[0] - 1, np.floor(proj_y))).astype(np.int32) # in [0,H-1] |
| 1071 | |
| 1072 | # order in decreasing depth |
| 1073 | order = np.argsort(depth)[::-1] |
| 1074 | proj_x, proj_y = proj_x[order], proj_y[order] |
| 1075 | |
| 1076 | # project depth |
| 1077 | depth = depth[order] |
| 1078 | range_img = np.full(size, -1, dtype=np.float32) |
| 1079 | range_img[proj_y, proj_x] = depth |
| 1080 | |
| 1081 | # project point feature |
| 1082 | if remission is not None: |
| 1083 | remission = remission[mask][order] |
| 1084 | proj_feature = np.full(size, -1, dtype=np.float32) |
| 1085 | proj_feature[proj_y, proj_x] = remission |
| 1086 | elif labels is not None: |
| 1087 | labels = labels[mask][order] |
no outgoing calls
no test coverage detected