Upload remaining 24 MCD files (skip LFS pointers)
Browse files- .gitattributes +4 -0
- Annotated_Lidar/ntu_day_01/inL_labelled/cloud_0165.pcd +3 -0
- Annotated_Lidar/ntu_day_01/inL_labelled/cloud_1645.pcd +3 -0
- Annotated_Lidar/ntu_day_01/inL_labelled/cloud_3724.pcd +3 -0
- Annotated_Lidar/ntu_day_01/inL_labelled/cloud_4536.pcd +3 -0
- Annotated_Lidar/ntu_day_01/pypcd-master/pypcd-master/build/lib/pypcd/__init__.py +2 -0
- Annotated_Lidar/ntu_day_01/pypcd-master/pypcd-master/build/lib/pypcd/nea_pc_format.py +278 -0
- Annotated_Lidar/ntu_day_01/pypcd-master/pypcd-master/build/lib/pypcd/numpy_pc2.py +319 -0
- Annotated_Lidar/ntu_day_01/pypcd-master/pypcd-master/build/lib/pypcd/pdutil.py +31 -0
- Annotated_Lidar/ntu_day_01/pypcd-master/pypcd-master/build/lib/pypcd/pypcd.py +745 -0
- Annotated_Lidar/ntu_day_01/pypcd-master/pypcd-master/build/lib/pypcd/sautil.py +75 -0
- Annotated_Lidar/ntu_day_01/pypcd-master/pypcd-master/build/lib/pypcd/version.py +69 -0
- Annotated_Lidar/ntu_day_01/pypcd-master/pypcd-master/pypcd/test_data/get_data.sh +2 -0
- Annotated_Lidar/ntu_day_01/pypcd-master/pypcd-master/pypcd/tests/__init__.py +0 -0
- Annotated_Lidar/ntu_day_01/pypcd-master/pypcd-master/pypcd/tests/test_pypcd.py +206 -0
- mcd_cluster_ntu_day01_sgpr/keypoints_cloud_2923.npy +3 -0
- mcd_cluster_ntu_day01_sgpr/keypoints_cloud_3487.npy +3 -0
- mcd_cluster_ntu_day01_sgpr/keypoints_cloud_4224.npy +3 -0
- mcd_cluster_ntu_day01_sgpr/keypoints_cloud_5884.npy +3 -0
- mcd_cluster_ntu_day01_sgpr/keypoints_cloud_5918.npy +3 -0
- tgfz7_ablation_runs/exp1_no_dynamic_ms072/ntu_day_01/keypoints_cloud_0766.npy +3 -0
- tgfz7_ablation_runs/exp1_no_dynamic_ms072/ntu_day_01/keypoints_cloud_2801.npy +3 -0
- tgfz7_ablation_runs/exp1_no_dynamic_ms072/ntu_day_01/keypoints_cloud_3867.npy +3 -0
- tgfz7_ablation_runs/exp1_no_dynamic_ms072/ntu_day_01/keypoints_cloud_4572.npy +3 -0
- tgfz7_ablation_runs/exp1_no_dynamic_ms072/ntu_day_01/keypoints_cloud_5467.npy +3 -0
.gitattributes
CHANGED
|
@@ -8588,3 +8588,7 @@ Annotated_Lidar/ntu_day_01/inL_labelled/cloud_5608.pcd filter=lfs diff=lfs merge
|
|
| 8588 |
Annotated_Lidar/ntu_day_01/inL_labelled/cloud_3234.pcd filter=lfs diff=lfs merge=lfs -text
|
| 8589 |
Annotated_Lidar/ntu_day_01/inL_labelled/cloud_1344.pcd filter=lfs diff=lfs merge=lfs -text
|
| 8590 |
Annotated_Lidar/ntu_day_01/inL_labelled/cloud_3555.pcd filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8588 |
Annotated_Lidar/ntu_day_01/inL_labelled/cloud_3234.pcd filter=lfs diff=lfs merge=lfs -text
|
| 8589 |
Annotated_Lidar/ntu_day_01/inL_labelled/cloud_1344.pcd filter=lfs diff=lfs merge=lfs -text
|
| 8590 |
Annotated_Lidar/ntu_day_01/inL_labelled/cloud_3555.pcd filter=lfs diff=lfs merge=lfs -text
|
| 8591 |
+
Annotated_Lidar/ntu_day_01/inL_labelled/cloud_0165.pcd filter=lfs diff=lfs merge=lfs -text
|
| 8592 |
+
Annotated_Lidar/ntu_day_01/inL_labelled/cloud_1645.pcd filter=lfs diff=lfs merge=lfs -text
|
| 8593 |
+
Annotated_Lidar/ntu_day_01/inL_labelled/cloud_3724.pcd filter=lfs diff=lfs merge=lfs -text
|
| 8594 |
+
Annotated_Lidar/ntu_day_01/inL_labelled/cloud_4536.pcd filter=lfs diff=lfs merge=lfs -text
|
Annotated_Lidar/ntu_day_01/inL_labelled/cloud_0165.pcd
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:604e41107caab271e826fa653fdb01e949c27c8a46d681da4c7d3e2a73d244ff
|
| 3 |
+
size 125709
|
Annotated_Lidar/ntu_day_01/inL_labelled/cloud_1645.pcd
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e13077c919b2099d52e8f3d599d154a0c803d9e46daaff6695d253301638b56e
|
| 3 |
+
size 128686
|
Annotated_Lidar/ntu_day_01/inL_labelled/cloud_3724.pcd
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c4235ac8009692d4e3093a764e013e2e77918eb4942b5b6f164cfe2bb9c9e70b
|
| 3 |
+
size 140203
|
Annotated_Lidar/ntu_day_01/inL_labelled/cloud_4536.pcd
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b5c62dd9cbd84618b85d5820d2b3330b57e23b8dbe7599ccae3418ec813b3d8a
|
| 3 |
+
size 122557
|
Annotated_Lidar/ntu_day_01/pypcd-master/pypcd-master/build/lib/pypcd/__init__.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from pypcd import *
|
Annotated_Lidar/ntu_day_01/pypcd-master/pypcd-master/build/lib/pypcd/nea_pc_format.py
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import copy
|
| 3 |
+
import numpy as np
|
| 4 |
+
from sensor_msgs.msg import PointField
|
| 5 |
+
|
| 6 |
+
# these are from numpy_pc2
|
| 7 |
+
_pftype_to_nptype = dict([(PointField.INT8, np.dtype('int8')),
|
| 8 |
+
(PointField.UINT8, np.dtype('uint8')),
|
| 9 |
+
(PointField.INT16, np.dtype('int16')),
|
| 10 |
+
(PointField.UINT16, np.dtype('uint16')),
|
| 11 |
+
(PointField.INT32, np.dtype('int32')),
|
| 12 |
+
(PointField.UINT32, np.dtype('uint32')),
|
| 13 |
+
(PointField.FLOAT32, np.dtype('float32')),
|
| 14 |
+
(PointField.FLOAT64, np.dtype('float64'))])
|
| 15 |
+
|
| 16 |
+
_pftype_to_pcd_letter = dict([(PointField.INT8, 'I'),
|
| 17 |
+
(PointField.UINT8, 'U'),
|
| 18 |
+
(PointField.INT16, 'I'),
|
| 19 |
+
(PointField.UINT16, 'U'),
|
| 20 |
+
(PointField.INT32, 'I'),
|
| 21 |
+
(PointField.UINT32, 'U'),
|
| 22 |
+
(PointField.FLOAT32, 'F'),
|
| 23 |
+
(PointField.FLOAT64, 'F')])
|
| 24 |
+
|
| 25 |
+
_pftype_to_size = dict([(PointField.INT8, 1),
|
| 26 |
+
(PointField.UINT8, 1),
|
| 27 |
+
(PointField.INT16, 2),
|
| 28 |
+
(PointField.UINT16, 2),
|
| 29 |
+
(PointField.INT32, 4),
|
| 30 |
+
(PointField.UINT32, 4),
|
| 31 |
+
(PointField.FLOAT32, 4),
|
| 32 |
+
(PointField.FLOAT64, 8)])
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
_nea_field_dicts =[\
|
| 36 |
+
{'name':'x',
|
| 37 |
+
'offset': 0,
|
| 38 |
+
'datatype': PointField.FLOAT64,
|
| 39 |
+
'count': 1
|
| 40 |
+
},
|
| 41 |
+
{'name':'y',
|
| 42 |
+
'offset': 8,
|
| 43 |
+
'datatype': PointField.FLOAT64,
|
| 44 |
+
'count': 1
|
| 45 |
+
},
|
| 46 |
+
{'name':'z',
|
| 47 |
+
'offset': 16,
|
| 48 |
+
'datatype': PointField.FLOAT64,
|
| 49 |
+
'count': 1
|
| 50 |
+
},
|
| 51 |
+
{'name':'x_origin',
|
| 52 |
+
'offset': 24,
|
| 53 |
+
'datatype': PointField.FLOAT64,
|
| 54 |
+
'count': 1
|
| 55 |
+
},
|
| 56 |
+
{'name':'y_origin',
|
| 57 |
+
'offset': 32,
|
| 58 |
+
'datatype': PointField.FLOAT64,
|
| 59 |
+
'count': 1
|
| 60 |
+
},
|
| 61 |
+
{'name':'z_origin',
|
| 62 |
+
'offset': 40,
|
| 63 |
+
'datatype': PointField.FLOAT64,
|
| 64 |
+
'count': 1
|
| 65 |
+
},
|
| 66 |
+
{'name':'range_variance',
|
| 67 |
+
'offset': 48,
|
| 68 |
+
'datatype': PointField.FLOAT32,
|
| 69 |
+
'count': 1
|
| 70 |
+
},
|
| 71 |
+
{'name':'x_variance',
|
| 72 |
+
'offset': 52,
|
| 73 |
+
'datatype': PointField.FLOAT32,
|
| 74 |
+
'count': 1
|
| 75 |
+
},
|
| 76 |
+
{'name':'y_variance',
|
| 77 |
+
'offset': 56,
|
| 78 |
+
'datatype': PointField.FLOAT32,
|
| 79 |
+
'count': 1
|
| 80 |
+
},
|
| 81 |
+
{'name':'z_variance',
|
| 82 |
+
'offset': 60,
|
| 83 |
+
'datatype': PointField.FLOAT32,
|
| 84 |
+
'count': 1
|
| 85 |
+
},
|
| 86 |
+
{'name':'reflectance',
|
| 87 |
+
'offset': 64,
|
| 88 |
+
'datatype': PointField.FLOAT32,
|
| 89 |
+
'count': 1
|
| 90 |
+
},
|
| 91 |
+
{'name':'time_sec',
|
| 92 |
+
'offset': 68,
|
| 93 |
+
'datatype': PointField.UINT32,
|
| 94 |
+
'count': 1
|
| 95 |
+
},
|
| 96 |
+
{'name':'time_nsec',
|
| 97 |
+
'offset': 72,
|
| 98 |
+
'datatype': PointField.UINT32,
|
| 99 |
+
'count': 1
|
| 100 |
+
},
|
| 101 |
+
{'name':'return_type',
|
| 102 |
+
'offset': 76,
|
| 103 |
+
'datatype': PointField.UINT8,
|
| 104 |
+
'count': 1
|
| 105 |
+
}]
|
| 106 |
+
|
| 107 |
+
_nea_float_fields_dicts =[\
|
| 108 |
+
{'name':'x',
|
| 109 |
+
'offset': 0,
|
| 110 |
+
'datatype': PointField.FLOAT32,
|
| 111 |
+
'count': 1
|
| 112 |
+
},
|
| 113 |
+
{'name':'y',
|
| 114 |
+
'offset': 4,
|
| 115 |
+
'datatype': PointField.FLOAT32,
|
| 116 |
+
'count': 1
|
| 117 |
+
},
|
| 118 |
+
{'name':'z',
|
| 119 |
+
'offset': 8,
|
| 120 |
+
'datatype': PointField.FLOAT32,
|
| 121 |
+
'count': 1
|
| 122 |
+
},
|
| 123 |
+
{'name':'x_origin',
|
| 124 |
+
'offset': 12,
|
| 125 |
+
'datatype': PointField.FLOAT32,
|
| 126 |
+
'count': 1
|
| 127 |
+
},
|
| 128 |
+
{'name':'y_origin',
|
| 129 |
+
'offset': 16,
|
| 130 |
+
'datatype': PointField.FLOAT32,
|
| 131 |
+
'count': 1
|
| 132 |
+
},
|
| 133 |
+
{'name':'z_origin',
|
| 134 |
+
'offset': 20,
|
| 135 |
+
'datatype': PointField.FLOAT32,
|
| 136 |
+
'count': 1
|
| 137 |
+
},
|
| 138 |
+
{'name':'range_variance',
|
| 139 |
+
'offset': 24,
|
| 140 |
+
'datatype': PointField.FLOAT32,
|
| 141 |
+
'count': 1
|
| 142 |
+
},
|
| 143 |
+
{'name':'x_variance',
|
| 144 |
+
'offset': 28,
|
| 145 |
+
'datatype': PointField.FLOAT32,
|
| 146 |
+
'count': 1
|
| 147 |
+
},
|
| 148 |
+
{'name':'y_variance',
|
| 149 |
+
'offset': 32,
|
| 150 |
+
'datatype': PointField.FLOAT32,
|
| 151 |
+
'count': 1
|
| 152 |
+
},
|
| 153 |
+
{'name':'z_variance',
|
| 154 |
+
'offset': 36,
|
| 155 |
+
'datatype': PointField.FLOAT32,
|
| 156 |
+
'count': 1
|
| 157 |
+
},
|
| 158 |
+
{'name':'reflectance',
|
| 159 |
+
'offset': 40,
|
| 160 |
+
'datatype': PointField.FLOAT32,
|
| 161 |
+
'count': 1
|
| 162 |
+
},
|
| 163 |
+
{'name':'time_sec',
|
| 164 |
+
'offset': 44,
|
| 165 |
+
'datatype': PointField.UINT32,
|
| 166 |
+
'count': 1
|
| 167 |
+
},
|
| 168 |
+
{'name':'time_nsec',
|
| 169 |
+
'offset': 48,
|
| 170 |
+
'datatype': PointField.UINT32,
|
| 171 |
+
'count': 1
|
| 172 |
+
},
|
| 173 |
+
{'name':'return_type',
|
| 174 |
+
'offset': 52,
|
| 175 |
+
'datatype': PointField.UINT8,
|
| 176 |
+
'count': 1
|
| 177 |
+
}]
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
_label_field_dict = {'name':'label',
|
| 181 |
+
'offset':0,
|
| 182 |
+
'datatype': PointField.UINT8,
|
| 183 |
+
'count':1}
|
| 184 |
+
|
| 185 |
+
# TODO if I use '_' for padding, like pcl, there are weird
|
| 186 |
+
# interactions when using binary_compressed. PCL assumes
|
| 187 |
+
# padding is not included in compressed files (which makes sense).
|
| 188 |
+
_padding_field_dict = {'name': '_PAD',
|
| 189 |
+
'offset':0,
|
| 190 |
+
'datatype': PointField.UINT8,
|
| 191 |
+
'count': 0}
|
| 192 |
+
|
| 193 |
+
def datatype_to_size(datatype):
|
| 194 |
+
""" ROS pointfield datatype to size in bytes
|
| 195 |
+
"""
|
| 196 |
+
if datatype in (PointField.INT8, PointField.UINT8):
|
| 197 |
+
return 1
|
| 198 |
+
elif datatype in (PointField.INT16, PointField.UINT16):
|
| 199 |
+
return 2
|
| 200 |
+
elif datatype in (PointField.INT32, PointField.UINT32, PointField.FLOAT32):
|
| 201 |
+
return 4
|
| 202 |
+
elif datatype in (PointField.FLOAT64,):
|
| 203 |
+
return 8
|
| 204 |
+
|
| 205 |
+
def make_nea_fields_dicts(with_label=True, with_padding=True):
|
| 206 |
+
field_dicts = copy.deepcopy(_nea_field_dicts)
|
| 207 |
+
if with_label:
|
| 208 |
+
label_field_dict_copy = copy.deepcopy(_label_field_dict)
|
| 209 |
+
# TODO this assumes last field is return_type
|
| 210 |
+
label_field_dict_copy['offset'] = field_dicts[-1]['offset']+1
|
| 211 |
+
field_dicts.append(label_field_dict_copy)
|
| 212 |
+
if with_padding:
|
| 213 |
+
padding_field_dict_copy = copy.deepcopy(_padding_field_dict)
|
| 214 |
+
# TODO this assumes last field is return_type or label
|
| 215 |
+
padding_field_dict_copy['offset'] = field_dicts[-1]['offset']+1
|
| 216 |
+
if with_label:
|
| 217 |
+
padding_field_dict_copy['count'] = 2
|
| 218 |
+
else:
|
| 219 |
+
padding_field_dict_copy['count'] = 3
|
| 220 |
+
field_dicts.append(padding_field_dict_copy)
|
| 221 |
+
return field_dicts
|
| 222 |
+
|
| 223 |
+
def make_nea_float_fields_dicts(with_label=True, with_padding=True):
|
| 224 |
+
field_dicts = copy.deepcopy(_nea_float_fields_dicts)
|
| 225 |
+
if with_label:
|
| 226 |
+
label_field_dict_copy = copy.deepcopy(_label_field_dict)
|
| 227 |
+
# TODO this assumes last field is return_type
|
| 228 |
+
label_field_dict_copy['offset'] = field_dicts[-1]['offset']+1
|
| 229 |
+
field_dicts.append(label_field_dict_copy)
|
| 230 |
+
if with_padding:
|
| 231 |
+
padding_field_dict_copy = copy.deepcopy(_padding_field_dict)
|
| 232 |
+
# TODO this assumes last field is return_type or label
|
| 233 |
+
padding_field_dict_copy['offset'] = field_dicts[-1]['offset']+1
|
| 234 |
+
if with_label:
|
| 235 |
+
padding_field_dict_copy['count'] = 9
|
| 236 |
+
else:
|
| 237 |
+
padding_field_dict_copy['count'] = 10
|
| 238 |
+
field_dicts.append(padding_field_dict_copy)
|
| 239 |
+
return field_dicts
|
| 240 |
+
|
| 241 |
+
def field_dict_list_to_dtypes(field_dicts):
|
| 242 |
+
dtypes = []
|
| 243 |
+
for f in field_dicts:
|
| 244 |
+
count = f['count']
|
| 245 |
+
if count > 1:
|
| 246 |
+
for c in xrange(count):
|
| 247 |
+
name = '%s_%04d'%(f['name'], c)
|
| 248 |
+
nptype = _pftype_to_nptype[f['datatype']]
|
| 249 |
+
dtypes.append( (name, nptype) )
|
| 250 |
+
else:
|
| 251 |
+
name = f['name']
|
| 252 |
+
nptype = _pftype_to_nptype[f['datatype']]
|
| 253 |
+
dtypes.append( (name, nptype) )
|
| 254 |
+
return dtypes
|
| 255 |
+
|
| 256 |
+
def make_nea_dtypes(with_label=True, with_padding=True):
|
| 257 |
+
fl = make_nea_fields_dicts(with_label=with_label, with_padding=with_padding)
|
| 258 |
+
return field_dict_list_to_dtypes(fl)
|
| 259 |
+
|
| 260 |
+
def make_nea_float_dtypes(with_label=True, with_padding=True):
|
| 261 |
+
fl = make_nea_float_fields_dicts(with_label=with_label, with_padding=with_padding)
|
| 262 |
+
return field_dict_list_to_dtypes(fl)
|
| 263 |
+
|
| 264 |
+
def field_dict_list_to_pcd_metadata(field_dict_list):
|
| 265 |
+
pcd_md = {'version':.7,
|
| 266 |
+
'fields':[f['name'] for f in field_dict_list],
|
| 267 |
+
'size':[ _pftype_to_size[f['datatype']] for f in field_dict_list],
|
| 268 |
+
'type':[ _pftype_to_pcd_letter[f['datatype']] for f in field_dict_list],
|
| 269 |
+
'count':[ f['count'] for f in field_dict_list ],
|
| 270 |
+
'width':0,
|
| 271 |
+
'height':1,
|
| 272 |
+
'viewpoint':[0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
|
| 273 |
+
'points':0,
|
| 274 |
+
'data':'ASCII'}
|
| 275 |
+
return pcd_md
|
| 276 |
+
|
| 277 |
+
#nea_fields = [ PointField(**d) for d in nea_fields_dicts]
|
| 278 |
+
|
Annotated_Lidar/ntu_day_01/pypcd-master/pypcd-master/build/lib/pypcd/numpy_pc2.py
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Software License Agreement (BSD License)
|
| 2 |
+
#
|
| 3 |
+
# Copyright (c) 2008, Willow Garage, Inc.
|
| 4 |
+
# All rights reserved.
|
| 5 |
+
#
|
| 6 |
+
# Redistribution and use in source and binary forms, with or without
|
| 7 |
+
# modification, are permitted provided that the following conditions
|
| 8 |
+
# are met:
|
| 9 |
+
#
|
| 10 |
+
# * Redistributions of source code must retain the above copyright
|
| 11 |
+
# notice, this list of conditions and the following disclaimer.
|
| 12 |
+
# * Redistributions in binary form must reproduce the above
|
| 13 |
+
# copyright notice, this list of conditions and the following
|
| 14 |
+
# disclaimer in the documentation and/or other materials provided
|
| 15 |
+
# with the distribution.
|
| 16 |
+
# * Neither the name of Willow Garage, Inc. nor the names of its
|
| 17 |
+
# contributors may be used to endorse or promote products derived
|
| 18 |
+
# from this software without specific prior written permission.
|
| 19 |
+
#
|
| 20 |
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 21 |
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 22 |
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
| 23 |
+
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
| 24 |
+
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
| 25 |
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
| 26 |
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 27 |
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 28 |
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 29 |
+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
| 30 |
+
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 31 |
+
# POSSIBILITY OF SUCH DAMAGE.
|
| 32 |
+
#
|
| 33 |
+
# Author: Jon Binney
|
| 34 |
+
# Updates: Daniel Maturana
|
| 35 |
+
|
| 36 |
+
'''
|
| 37 |
+
Functions for working with PointCloud2.
|
| 38 |
+
'''
|
| 39 |
+
__docformat__ = "restructuredtext en"
|
| 40 |
+
|
| 41 |
+
import numpy as np
|
| 42 |
+
|
| 43 |
+
from sensor_msgs.msg import PointField
|
| 44 |
+
from sensor_msgs.msg import PointCloud2
|
| 45 |
+
|
| 46 |
+
# prefix to the names of dummy fields we add to get byte alignment correct. this needs to not
|
| 47 |
+
# clash with any actual field names
|
| 48 |
+
DUMMY_FIELD_PREFIX = '__'
|
| 49 |
+
|
| 50 |
+
# mappings between PointField types and numpy types
|
| 51 |
+
type_mappings = [(PointField.INT8, np.dtype('int8')),
|
| 52 |
+
(PointField.UINT8, np.dtype('uint8')),
|
| 53 |
+
(PointField.INT16, np.dtype('int16')),
|
| 54 |
+
(PointField.UINT16, np.dtype('uint16')),
|
| 55 |
+
(PointField.INT32, np.dtype('int32')),
|
| 56 |
+
(PointField.UINT32, np.dtype('uint32')),
|
| 57 |
+
(PointField.FLOAT32, np.dtype('float32')),
|
| 58 |
+
(PointField.FLOAT64, np.dtype('float64'))]
|
| 59 |
+
|
| 60 |
+
pftype_to_nptype = dict(type_mappings)
|
| 61 |
+
nptype_to_pftype = dict((nptype, pftype) for pftype, nptype in type_mappings)
|
| 62 |
+
|
| 63 |
+
# sizes (in bytes) of PointField types
|
| 64 |
+
pftype_sizes = {PointField.INT8: 1, PointField.UINT8: 1, PointField.INT16: 2, PointField.UINT16: 2,
|
| 65 |
+
PointField.INT32: 4, PointField.UINT32: 4, PointField.FLOAT32: 4, PointField.FLOAT64: 8}
|
| 66 |
+
|
| 67 |
+
def pointfields_to_dtype(point_fields):
|
| 68 |
+
'''Convert a list of PointFields to a numpy record datatype.
|
| 69 |
+
'''
|
| 70 |
+
offset = 0
|
| 71 |
+
np_dtype_list = []
|
| 72 |
+
for f in point_fields:
|
| 73 |
+
while offset < f.offset:
|
| 74 |
+
# might be extra padding between fields
|
| 75 |
+
np_dtype_list.append(('%s%d' % (DUMMY_FIELD_PREFIX, offset), np.uint8))
|
| 76 |
+
offset += 1
|
| 77 |
+
np_dtype_list.append((f.name, pftype_to_nptype[f.datatype]))
|
| 78 |
+
offset += pftype_sizes[f.datatype]
|
| 79 |
+
|
| 80 |
+
# might be extra padding between points
|
| 81 |
+
#while offset < cloud_msg.point_step:
|
| 82 |
+
#np_dtype_list.append(('%s%d' % (DUMMY_FIELD_PREFIX, offset), np.uint8))
|
| 83 |
+
#offset += 1
|
| 84 |
+
|
| 85 |
+
return np_dtype_list
|
| 86 |
+
|
| 87 |
+
def pointcloud2_to_dtype(cloud_msg):
|
| 88 |
+
'''Convert a list of PointFields to a numpy record datatype.
|
| 89 |
+
'''
|
| 90 |
+
offset = 0
|
| 91 |
+
np_dtype_list = []
|
| 92 |
+
for f in cloud_msg.fields:
|
| 93 |
+
while offset < f.offset:
|
| 94 |
+
# might be extra padding between fields
|
| 95 |
+
np_dtype_list.append(('%s%d' % (DUMMY_FIELD_PREFIX, offset), np.uint8))
|
| 96 |
+
offset += 1
|
| 97 |
+
np_dtype_list.append((f.name, pftype_to_nptype[f.datatype]))
|
| 98 |
+
offset += pftype_sizes[f.datatype]
|
| 99 |
+
|
| 100 |
+
# might be extra padding between points
|
| 101 |
+
while offset < cloud_msg.point_step:
|
| 102 |
+
np_dtype_list.append(('%s%d' % (DUMMY_FIELD_PREFIX, offset), np.uint8))
|
| 103 |
+
offset += 1
|
| 104 |
+
|
| 105 |
+
return np_dtype_list
|
| 106 |
+
|
| 107 |
+
def arr_to_fields(cloud_arr):
|
| 108 |
+
'''Convert a numpy record datatype into a list of PointFields.
|
| 109 |
+
'''
|
| 110 |
+
fields = []
|
| 111 |
+
for field_name in cloud_arr.dtype.names:
|
| 112 |
+
np_field_type, field_offset = cloud_arr.dtype.fields[field_name]
|
| 113 |
+
pf = PointField()
|
| 114 |
+
pf.name = field_name
|
| 115 |
+
pf.datatype = nptype_to_pftype[np_field_type]
|
| 116 |
+
pf.offset = field_offset
|
| 117 |
+
pf.count = 1 # is this ever more than one?
|
| 118 |
+
fields.append(pf)
|
| 119 |
+
return fields
|
| 120 |
+
|
| 121 |
+
def pointcloud2_to_array(cloud_msg, split_rgb=False, remove_padding=True):
|
| 122 |
+
''' Converts a rospy PointCloud2 message to a numpy recordarray
|
| 123 |
+
|
| 124 |
+
Reshapes the returned array to have shape (height, width), even if the height is 1.
|
| 125 |
+
|
| 126 |
+
The reason for using np.fromstring rather than struct.unpack is speed... especially
|
| 127 |
+
for large point clouds, this will be <much> faster.
|
| 128 |
+
'''
|
| 129 |
+
# construct a numpy record type equivalent to the point type of this cloud
|
| 130 |
+
dtype_list = pointcloud2_to_dtype(cloud_msg)
|
| 131 |
+
|
| 132 |
+
# parse the cloud into an array
|
| 133 |
+
cloud_arr = np.fromstring(cloud_msg.data, dtype_list)
|
| 134 |
+
|
| 135 |
+
# remove the dummy fields that were added
|
| 136 |
+
if remove_padding:
|
| 137 |
+
cloud_arr = cloud_arr[
|
| 138 |
+
[fname for fname, _type in dtype_list if not (fname[:len(DUMMY_FIELD_PREFIX)] == DUMMY_FIELD_PREFIX)]]
|
| 139 |
+
|
| 140 |
+
if split_rgb:
|
| 141 |
+
cloud_arr = split_rgb_field(cloud_arr)
|
| 142 |
+
|
| 143 |
+
return np.reshape(cloud_arr, (cloud_msg.height, cloud_msg.width))
|
| 144 |
+
|
| 145 |
+
def array_to_xyz_pointcloud2f(cloud_arr, stamp=None, frame_id=None, merge_rgb=False):
|
| 146 |
+
""" convert an Nx3 float array to an xyz point cloud.
|
| 147 |
+
beware of numerical issues when casting from other types to float32.
|
| 148 |
+
"""
|
| 149 |
+
cloud_arr = np.asarray(cloud_arr, dtype=np.float32)
|
| 150 |
+
if not cloud_arr.ndim==2: raise ValueError('cloud_arr must be 2D array')
|
| 151 |
+
if not cloud_arr.shape[1]==3: raise ValueError('cloud_arr shape must be Nx3')
|
| 152 |
+
xyz = cloud_arr.view(np.dtype([('x', np.float32), ('y', np.float32), ('z', np.float32)])).squeeze()
|
| 153 |
+
return array_to_pointcloud2(xyz, stamp=stamp, frame_id=frame_id, merge_rgb=merge_rgb)
|
| 154 |
+
|
| 155 |
+
def array_to_xyzi_pointcloud2f(cloud_arr, stamp=None, frame_id=None, merge_rgb=False):
|
| 156 |
+
""" convert an Nx4 float array to an xyzi point cloud.
|
| 157 |
+
beware of numerical issues when casting from other types to float32.
|
| 158 |
+
"""
|
| 159 |
+
cloud_arr = np.asarray(cloud_arr, dtype=np.float32)
|
| 160 |
+
if not cloud_arr.ndim==2: raise ValueError('cloud_arr must be 2D array')
|
| 161 |
+
if not cloud_arr.shape[1]==4: raise ValueError('cloud_arr shape must be Nx4')
|
| 162 |
+
xyzi = cloud_arr.view(np.dtype([
|
| 163 |
+
('x', np.float32), ('y', np.float32), ('z', np.float32), ('intensity', np.float32)
|
| 164 |
+
])).squeeze()
|
| 165 |
+
return array_to_pointcloud2(xyzi, stamp=stamp, frame_id=frame_id, merge_rgb=merge_rgb)
|
| 166 |
+
|
| 167 |
+
def arrays_to_xyzi_pointcloud2f(cloud_arr, intensity_array, stamp=None, frame_id=None, merge_rgb=False):
|
| 168 |
+
""" convert an Nx3 float array and N array to an xyzi point cloud.
|
| 169 |
+
beware of numerical issues when casting from other types to float32.
|
| 170 |
+
"""
|
| 171 |
+
cloud_arr = np.asarray(cloud_arr, dtype=np.float32)
|
| 172 |
+
if not cloud_arr.ndim==2: raise ValueError('cloud_arr must be 2D array')
|
| 173 |
+
if not cloud_arr.shape[1]==3: raise ValueError('cloud_arr shape must be Nx3')
|
| 174 |
+
if not intensity_array.size == cloud_arr.shape[0]: raise ValueError('wrong intensity shape')
|
| 175 |
+
xyzi = np.zeros( (len(cloud_arr), 4) , dtype=np.float32 )
|
| 176 |
+
xyzi[:,0:3] = cloud_arr
|
| 177 |
+
xyzi[:,3] = intensity_array
|
| 178 |
+
xyzi = xyzi.view(np.dtype([
|
| 179 |
+
('x', np.float32), ('y', np.float32), ('z', np.float32), ('intensity', np.float32)
|
| 180 |
+
])).squeeze()
|
| 181 |
+
return array_to_pointcloud2(xyzi, stamp=stamp, frame_id=frame_id, merge_rgb=merge_rgb)
|
| 182 |
+
|
| 183 |
+
def array_to_xyzl_pointcloud2f(cloud_arr, stamp=None, frame_id=None, merge_rgb=False):
|
| 184 |
+
""" convert an Nx4 float array to an xyzi point cloud.
|
| 185 |
+
beware of numerical issues when casting from other types to float32.
|
| 186 |
+
"""
|
| 187 |
+
cloud_arr = np.asarray(cloud_arr, dtype=np.float32)
|
| 188 |
+
if not cloud_arr.ndim==2: raise ValueError('cloud_arr must be 2D array')
|
| 189 |
+
if not cloud_arr.shape[1]==4: raise ValueError('cloud_arr shape must be Nx3')
|
| 190 |
+
xyzi = cloud_arr.view(np.dtype([
|
| 191 |
+
('x', np.float32), ('y', np.float32), ('z', np.float32), ('intensity', np.float32)
|
| 192 |
+
])).squeeze()
|
| 193 |
+
return array_to_pointcloud2(xyzi, stamp=stamp, frame_id=frame_id, merge_rgb=merge_rgb)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def array_to_xyz_pointcloud2(cloud_arr, stamp=None, frame_id=None, merge_rgb=False):
|
| 197 |
+
""" convert an Nx3 float array to an xyz point cloud.
|
| 198 |
+
preserves (scalar) dtype of input.
|
| 199 |
+
TODO: untested
|
| 200 |
+
"""
|
| 201 |
+
cloud_arr = np.asarray(cloud_arr)
|
| 202 |
+
if not cloud_arr.ndim==2: raise ValueError('cloud_arr must be 2D array')
|
| 203 |
+
if not cloud_arr.shape[1]==3: raise ValueError('cloud_arr shape must be Nx3')
|
| 204 |
+
xyz = cloud_arr.view(np.dtype([('x', cloud_arr.dtype), ('y', cloud_arr.dtype), ('z', cloud_arr.dtype)])).squeeze()
|
| 205 |
+
return array_to_pointcloud2(xyz, stamp=stamp, frame_id=frame_id, merge_rgb=merge_rgb)
|
| 206 |
+
|
| 207 |
+
def array_to_pointcloud2(cloud_arr, stamp=None, frame_id=None, merge_rgb=False):
|
| 208 |
+
'''Converts a numpy record array to a sensor_msgs.msg.PointCloud2.
|
| 209 |
+
'''
|
| 210 |
+
if merge_rgb:
|
| 211 |
+
cloud_arr = merge_rgb_fields(cloud_arr)
|
| 212 |
+
|
| 213 |
+
# make it 2d (even if height will be 1)
|
| 214 |
+
cloud_arr = np.atleast_2d(cloud_arr)
|
| 215 |
+
|
| 216 |
+
cloud_msg = PointCloud2()
|
| 217 |
+
|
| 218 |
+
if stamp is not None:
|
| 219 |
+
cloud_msg.header.stamp = stamp
|
| 220 |
+
if frame_id is not None:
|
| 221 |
+
cloud_msg.header.frame_id = frame_id
|
| 222 |
+
cloud_msg.height = cloud_arr.shape[0]
|
| 223 |
+
cloud_msg.width = cloud_arr.shape[1]
|
| 224 |
+
cloud_msg.fields = arr_to_fields(cloud_arr)
|
| 225 |
+
cloud_msg.is_bigendian = False # assumption
|
| 226 |
+
cloud_msg.point_step = cloud_arr.dtype.itemsize
|
| 227 |
+
cloud_msg.row_step = cloud_msg.point_step*cloud_arr.shape[1]
|
| 228 |
+
cloud_msg.is_dense = all([np.isfinite(cloud_arr[fname]).all() for fname in cloud_arr.dtype.names])
|
| 229 |
+
cloud_msg.data = cloud_arr.tostring()
|
| 230 |
+
return cloud_msg
|
| 231 |
+
|
| 232 |
+
def merge_rgb_fields(cloud_arr):
|
| 233 |
+
'''Takes an array with named np.uint8 fields 'r', 'g', and 'b', and returns an array in
|
| 234 |
+
which they have been merged into a single np.float32 'rgb' field. The first byte of this
|
| 235 |
+
field is the 'r' uint8, the second is the 'g', uint8, and the third is the 'b' uint8.
|
| 236 |
+
|
| 237 |
+
This is the way that pcl likes to handle RGB colors for some reason.
|
| 238 |
+
'''
|
| 239 |
+
r = np.asarray(cloud_arr['r'], dtype=np.uint32)
|
| 240 |
+
g = np.asarray(cloud_arr['g'], dtype=np.uint32)
|
| 241 |
+
b = np.asarray(cloud_arr['b'], dtype=np.uint32)
|
| 242 |
+
rgb_arr = np.array((r << 16) | (g << 8) | (b << 0), dtype=np.uint32)
|
| 243 |
+
|
| 244 |
+
# not sure if there is a better way to do this. i'm changing the type of the array
|
| 245 |
+
# from uint32 to float32, but i don't want any conversion to take place -jdb
|
| 246 |
+
rgb_arr.dtype = np.float32
|
| 247 |
+
|
| 248 |
+
# create a new array, without r, g, and b, but with rgb float32 field
|
| 249 |
+
new_dtype = []
|
| 250 |
+
for field_name in cloud_arr.dtype.names:
|
| 251 |
+
field_type, field_offset = cloud_arr.dtype.fields[field_name]
|
| 252 |
+
if field_name not in ('r', 'g', 'b'):
|
| 253 |
+
new_dtype.append((field_name, field_type))
|
| 254 |
+
new_dtype.append(('rgb', np.float32))
|
| 255 |
+
new_cloud_arr = np.zeros(cloud_arr.shape, new_dtype)
|
| 256 |
+
|
| 257 |
+
# fill in the new array
|
| 258 |
+
for field_name in new_cloud_arr.dtype.names:
|
| 259 |
+
if field_name == 'rgb':
|
| 260 |
+
new_cloud_arr[field_name] = rgb_arr
|
| 261 |
+
else:
|
| 262 |
+
new_cloud_arr[field_name] = cloud_arr[field_name]
|
| 263 |
+
|
| 264 |
+
return new_cloud_arr
|
| 265 |
+
|
| 266 |
+
def split_rgb_field(cloud_arr):
|
| 267 |
+
'''Takes an array with a named 'rgb' float32 field, and returns an array in which
|
| 268 |
+
this has been split into 3 uint 8 fields: 'r', 'g', and 'b'.
|
| 269 |
+
|
| 270 |
+
(pcl stores rgb in packed 32 bit floats)
|
| 271 |
+
'''
|
| 272 |
+
rgb_arr = cloud_arr['rgb'].copy()
|
| 273 |
+
rgb_arr.dtype = np.uint32
|
| 274 |
+
r = np.asarray((rgb_arr >> 16) & 255, dtype=np.uint8)
|
| 275 |
+
g = np.asarray((rgb_arr >> 8) & 255, dtype=np.uint8)
|
| 276 |
+
b = np.asarray(rgb_arr & 255, dtype=np.uint8)
|
| 277 |
+
|
| 278 |
+
# create a new array, without rgb, but with r, g, and b fields
|
| 279 |
+
new_dtype = []
|
| 280 |
+
for field_name in cloud_arr.dtype.names:
|
| 281 |
+
field_type, field_offset = cloud_arr.dtype.fields[field_name]
|
| 282 |
+
if not field_name == 'rgb':
|
| 283 |
+
new_dtype.append((field_name, field_type))
|
| 284 |
+
new_dtype.append(('r', np.uint8))
|
| 285 |
+
new_dtype.append(('g', np.uint8))
|
| 286 |
+
new_dtype.append(('b', np.uint8))
|
| 287 |
+
new_cloud_arr = np.zeros(cloud_arr.shape, new_dtype)
|
| 288 |
+
|
| 289 |
+
# fill in the new array
|
| 290 |
+
for field_name in new_cloud_arr.dtype.names:
|
| 291 |
+
if field_name == 'r':
|
| 292 |
+
new_cloud_arr[field_name] = r
|
| 293 |
+
elif field_name == 'g':
|
| 294 |
+
new_cloud_arr[field_name] = g
|
| 295 |
+
elif field_name == 'b':
|
| 296 |
+
new_cloud_arr[field_name] = b
|
| 297 |
+
else:
|
| 298 |
+
new_cloud_arr[field_name] = cloud_arr[field_name]
|
| 299 |
+
return new_cloud_arr
|
| 300 |
+
|
| 301 |
+
def get_xyz_points(cloud_array, remove_nans=True, dtype=float):
|
| 302 |
+
'''Pulls out x, y, and z columns from the cloud recordarray, and returns
|
| 303 |
+
a 3xN matrix.
|
| 304 |
+
'''
|
| 305 |
+
# remove crap points
|
| 306 |
+
if remove_nans:
|
| 307 |
+
mask = np.isfinite(cloud_array['x']) & np.isfinite(cloud_array['y']) & np.isfinite(cloud_array['z'])
|
| 308 |
+
cloud_array = cloud_array[mask]
|
| 309 |
+
|
| 310 |
+
# pull out x, y, and z values
|
| 311 |
+
points = np.zeros(list(cloud_array.shape) + [3], dtype=dtype)
|
| 312 |
+
points[...,0] = cloud_array['x']
|
| 313 |
+
points[...,1] = cloud_array['y']
|
| 314 |
+
points[...,2] = cloud_array['z']
|
| 315 |
+
|
| 316 |
+
return points
|
| 317 |
+
|
| 318 |
+
def pointcloud2_to_xyz_array(cloud_msg, remove_nans=True):
|
| 319 |
+
return get_xyz_points(pointcloud2_to_array(cloud_msg))
|
Annotated_Lidar/ntu_day_01/pypcd-master/pypcd-master/build/lib/pypcd/pdutil.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pypcd import pypcd
|
| 2 |
+
from pypcd import numpy_pc2
|
| 3 |
+
def data_frame_to_point_cloud(df):
|
| 4 |
+
""" create a PointCloud object from a dataframe.
|
| 5 |
+
"""
|
| 6 |
+
pc_data = df.to_records(index=False)
|
| 7 |
+
md = {'version':.7,
|
| 8 |
+
'fields': [],
|
| 9 |
+
'size': [],
|
| 10 |
+
'count': [],
|
| 11 |
+
'width': 0,
|
| 12 |
+
'height':1,
|
| 13 |
+
'viewpoint':[0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
|
| 14 |
+
'points': 0,
|
| 15 |
+
'type': [],
|
| 16 |
+
'data':'binary_compressed'}
|
| 17 |
+
md['fields'] = df.columns.tolist()
|
| 18 |
+
for field in md['fields']:
|
| 19 |
+
type_, size_ = pypcd.numpy_type_to_pcd_type[ pc_data.dtype.fields[field][0] ]
|
| 20 |
+
md['type'].append( type_ )
|
| 21 |
+
md['size'].append( size_ )
|
| 22 |
+
# TODO handle multicount
|
| 23 |
+
md['count'].append( 1 )
|
| 24 |
+
md['width'] = len(pc_data)
|
| 25 |
+
md['points'] = len(pc_data)
|
| 26 |
+
pc = pypcd.PointCloud(md, pc_data)
|
| 27 |
+
return pc
|
| 28 |
+
|
| 29 |
+
def data_frame_to_message(df, stamp=None, frame_id=None):
|
| 30 |
+
pc_data = df.to_records(index=False)
|
| 31 |
+
return numpy_pc2.array_to_pointcloud2(pc_data, stamp=stamp, frame_id=frame_id)
|
Annotated_Lidar/ntu_day_01/pypcd-master/pypcd-master/build/lib/pypcd/pypcd.py
ADDED
|
@@ -0,0 +1,745 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
| 5 |
+
TODO deal properly with padding
|
| 6 |
+
TODO deal properly with multicount fields
|
| 7 |
+
TODO better support for rgb nonsense
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import re
|
| 11 |
+
import struct
|
| 12 |
+
import copy
|
| 13 |
+
from io import StringIO as sio
|
| 14 |
+
import numpy as np
|
| 15 |
+
import warnings
|
| 16 |
+
import lzf
|
| 17 |
+
|
| 18 |
+
HAS_SENSOR_MSGS = True
|
| 19 |
+
try:
|
| 20 |
+
from sensor_msgs.msg import PointField
|
| 21 |
+
from . import numpy_pc2 # needs sensor_msgs
|
| 22 |
+
except ImportError:
|
| 23 |
+
HAS_SENSOR_MSGS = False
|
| 24 |
+
|
| 25 |
+
__all__ = ['PointCloud',
|
| 26 |
+
'point_cloud_to_path',
|
| 27 |
+
'point_cloud_to_buffer',
|
| 28 |
+
'point_cloud_to_fileobj',
|
| 29 |
+
'point_cloud_from_path',
|
| 30 |
+
'point_cloud_from_buffer',
|
| 31 |
+
'point_cloud_from_fileobj',
|
| 32 |
+
'make_xyz_point_cloud',
|
| 33 |
+
'make_xyz_rgb_point_cloud',
|
| 34 |
+
'make_xyz_label_point_cloud',
|
| 35 |
+
'save_txt',
|
| 36 |
+
'cat_point_clouds',
|
| 37 |
+
'add_fields',
|
| 38 |
+
'update_field',
|
| 39 |
+
'build_ascii_fmtstr',
|
| 40 |
+
'encode_rgb_for_pcl',
|
| 41 |
+
'decode_rgb_from_pcl',
|
| 42 |
+
'save_point_cloud',
|
| 43 |
+
'save_point_cloud_bin',
|
| 44 |
+
'save_point_cloud_bin_compressed',
|
| 45 |
+
'pcd_type_to_numpy_type',
|
| 46 |
+
'numpy_type_to_pcd_type',
|
| 47 |
+
]
|
| 48 |
+
|
| 49 |
+
if HAS_SENSOR_MSGS:
|
| 50 |
+
pc2_pcd_type_mappings = [(PointField.INT8, ('I', 1)),
|
| 51 |
+
(PointField.UINT8, ('U', 1)),
|
| 52 |
+
(PointField.INT16, ('I', 2)),
|
| 53 |
+
(PointField.UINT16, ('U', 2)),
|
| 54 |
+
(PointField.INT32, ('I', 4)),
|
| 55 |
+
(PointField.UINT32, ('U', 4)),
|
| 56 |
+
(PointField.FLOAT32, ('F', 4)),
|
| 57 |
+
(PointField.FLOAT64, ('F', 8))]
|
| 58 |
+
pc2_type_to_pcd_type = dict(pc2_pcd_type_mappings)
|
| 59 |
+
pcd_type_to_pc2_type = dict((q, p) for (p, q) in pc2_pcd_type_mappings)
|
| 60 |
+
__all__.extend(['pcd_type_to_pc2_type', 'pc2_type_to_pcd_type'])
|
| 61 |
+
|
| 62 |
+
numpy_pcd_type_mappings = [(np.dtype('float32'), ('F', 4)),
|
| 63 |
+
(np.dtype('float64'), ('F', 8)),
|
| 64 |
+
(np.dtype('uint8'), ('U', 1)),
|
| 65 |
+
(np.dtype('uint16'), ('U', 2)),
|
| 66 |
+
(np.dtype('uint32'), ('U', 4)),
|
| 67 |
+
(np.dtype('uint64'), ('U', 8)),
|
| 68 |
+
(np.dtype('int16'), ('I', 2)),
|
| 69 |
+
(np.dtype('int32'), ('I', 4)),
|
| 70 |
+
(np.dtype('int64'), ('I', 8))]
|
| 71 |
+
numpy_type_to_pcd_type = dict(numpy_pcd_type_mappings)
|
| 72 |
+
pcd_type_to_numpy_type = dict((q, p) for (p, q) in numpy_pcd_type_mappings)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def parse_header(lines):
|
| 76 |
+
metadata = {}
|
| 77 |
+
for ln in lines:
|
| 78 |
+
if ln.startswith('#') or len(ln) < 2:
|
| 79 |
+
continue
|
| 80 |
+
ln = ln.replace(' _ ',' s ',1)
|
| 81 |
+
ln = ln.replace(' _ ',' m ',1)
|
| 82 |
+
match = re.match('(\w+)\s+([\w\s\.]+)', ln)
|
| 83 |
+
if not match:
|
| 84 |
+
warnings.warn("warning: can't understand line: %s" % ln)
|
| 85 |
+
continue
|
| 86 |
+
key, value = match.group(1).lower(), match.group(2)
|
| 87 |
+
if key == 'version':
|
| 88 |
+
metadata[key] = value
|
| 89 |
+
elif key in ('fields', 'type'):
|
| 90 |
+
metadata[key] = value.split()
|
| 91 |
+
elif key in ('size', 'count'):
|
| 92 |
+
metadata[key] = list(map(int, value.split()))
|
| 93 |
+
elif key in ('width', 'height', 'points'):
|
| 94 |
+
metadata[key] = int(value)
|
| 95 |
+
elif key == 'viewpoint':
|
| 96 |
+
metadata[key] = list(map(float, value.split()))
|
| 97 |
+
elif key == 'data':
|
| 98 |
+
metadata[key] = value.strip().lower()
|
| 99 |
+
# TODO apparently count is not required?
|
| 100 |
+
# add some reasonable defaults
|
| 101 |
+
if 'count' not in metadata:
|
| 102 |
+
metadata['count'] = [1]*len(metadata['fields'])
|
| 103 |
+
if 'viewpoint' not in metadata:
|
| 104 |
+
metadata['viewpoint'] = [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]
|
| 105 |
+
if 'version' not in metadata:
|
| 106 |
+
metadata['version'] = '.7'
|
| 107 |
+
return metadata
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def write_header(metadata, rename_padding=False):
|
| 111 |
+
""" given metadata as dictionary return a string header.
|
| 112 |
+
"""
|
| 113 |
+
template = """\
|
| 114 |
+
VERSION {version}
|
| 115 |
+
FIELDS {fields}
|
| 116 |
+
SIZE {size}
|
| 117 |
+
TYPE {type}
|
| 118 |
+
COUNT {count}
|
| 119 |
+
WIDTH {width}
|
| 120 |
+
HEIGHT {height}
|
| 121 |
+
VIEWPOINT {viewpoint}
|
| 122 |
+
POINTS {points}
|
| 123 |
+
DATA {data}
|
| 124 |
+
"""
|
| 125 |
+
str_metadata = metadata.copy()
|
| 126 |
+
|
| 127 |
+
if not rename_padding:
|
| 128 |
+
str_metadata['fields'] = ' '.join(metadata['fields'])
|
| 129 |
+
else:
|
| 130 |
+
new_fields = []
|
| 131 |
+
for f in metadata['fields']:
|
| 132 |
+
if f == '_':
|
| 133 |
+
new_fields.append('padding')
|
| 134 |
+
else:
|
| 135 |
+
new_fields.append(f)
|
| 136 |
+
str_metadata['fields'] = ' '.join(new_fields)
|
| 137 |
+
str_metadata['size'] = ' '.join(map(str, metadata['size']))
|
| 138 |
+
str_metadata['type'] = ' '.join(metadata['type'])
|
| 139 |
+
str_metadata['count'] = ' '.join(map(str, metadata['count']))
|
| 140 |
+
str_metadata['width'] = str(metadata['width'])
|
| 141 |
+
str_metadata['height'] = str(metadata['height'])
|
| 142 |
+
str_metadata['viewpoint'] = ' '.join(map(str, metadata['viewpoint']))
|
| 143 |
+
str_metadata['points'] = str(metadata['points'])
|
| 144 |
+
tmpl = template.format(**str_metadata)
|
| 145 |
+
return tmpl
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def _metadata_is_consistent(metadata):
|
| 149 |
+
""" sanity check for metadata. just some basic checks.
|
| 150 |
+
"""
|
| 151 |
+
checks = []
|
| 152 |
+
required = ('version', 'fields', 'size', 'width', 'height', 'points',
|
| 153 |
+
'viewpoint', 'data')
|
| 154 |
+
for f in required:
|
| 155 |
+
if f not in metadata:
|
| 156 |
+
print('%s required' % f)
|
| 157 |
+
checks.append((lambda m: all([k in m for k in required]),
|
| 158 |
+
'missing field'))
|
| 159 |
+
checks.append((lambda m: len(m['type']) == len(m['count']) ==
|
| 160 |
+
len(m['fields']),
|
| 161 |
+
'length of type, count and fields must be equal'))
|
| 162 |
+
checks.append((lambda m: m['height'] > 0,
|
| 163 |
+
'height must be greater than 0'))
|
| 164 |
+
checks.append((lambda m: m['width'] > 0,
|
| 165 |
+
'width must be greater than 0'))
|
| 166 |
+
checks.append((lambda m: m['points'] > 0,
|
| 167 |
+
'points must be greater than 0'))
|
| 168 |
+
checks.append((lambda m: m['data'].lower() in ('ascii', 'binary',
|
| 169 |
+
'binary_compressed'),
|
| 170 |
+
'unknown data type:'
|
| 171 |
+
'should be ascii/binary/binary_compressed'))
|
| 172 |
+
ok = True
|
| 173 |
+
for check, msg in checks:
|
| 174 |
+
if not check(metadata):
|
| 175 |
+
print('error:', msg)
|
| 176 |
+
ok = False
|
| 177 |
+
return ok
|
| 178 |
+
|
| 179 |
+
# def pcd_type_to_numpy(pcd_type, pcd_sz):
|
| 180 |
+
# """ convert from a pcd type string and size to numpy dtype."""
|
| 181 |
+
# typedict = {'F' : { 4:np.float32, 8:np.float64 },
|
| 182 |
+
# 'I' : { 1:np.int8, 2:np.int16, 4:np.int32, 8:np.int64 },
|
| 183 |
+
# 'U' : { 1:np.uint8, 2:np.uint16, 4:np.uint32 , 8:np.uint64 }}
|
| 184 |
+
# return typedict[pcd_type][pcd_sz]
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def _build_dtype(metadata):
|
| 188 |
+
""" build numpy structured array dtype from pcl metadata.
|
| 189 |
+
note that fields with count > 1 are 'flattened' by creating multiple
|
| 190 |
+
single-count fields.
|
| 191 |
+
TODO: allow 'proper' multi-count fields.
|
| 192 |
+
"""
|
| 193 |
+
fieldnames = []
|
| 194 |
+
typenames = []
|
| 195 |
+
for f, c, t, s in zip(metadata['fields'],
|
| 196 |
+
metadata['count'],
|
| 197 |
+
metadata['type'],
|
| 198 |
+
metadata['size']):
|
| 199 |
+
np_type = pcd_type_to_numpy_type[(t, s)]
|
| 200 |
+
if c == 1:
|
| 201 |
+
fieldnames.append(f)
|
| 202 |
+
typenames.append(np_type)
|
| 203 |
+
else:
|
| 204 |
+
fieldnames.extend(['%s_%04d' % (f, i) for i in range(c)])
|
| 205 |
+
typenames.extend([np_type]*c)
|
| 206 |
+
dtype = np.dtype(list(zip(fieldnames, typenames)))
|
| 207 |
+
return dtype
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
def build_ascii_fmtstr(pc):
|
| 211 |
+
""" make a format string for printing to ascii, using fields
|
| 212 |
+
%.8f minimum for rgb
|
| 213 |
+
%.10f for more general use?
|
| 214 |
+
"""
|
| 215 |
+
fmtstr = []
|
| 216 |
+
for t, cnt in zip(pc.type, pc.count):
|
| 217 |
+
if t == 'F':
|
| 218 |
+
fmtstr.extend(['%.10f']*cnt)
|
| 219 |
+
elif t == 'I':
|
| 220 |
+
fmtstr.extend(['%d']*cnt)
|
| 221 |
+
elif t == 'U':
|
| 222 |
+
fmtstr.extend(['%u']*cnt)
|
| 223 |
+
else:
|
| 224 |
+
raise ValueError("don't know about type %s" % t)
|
| 225 |
+
return fmtstr
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
def parse_ascii_pc_data(f, dtype, metadata):
|
| 229 |
+
return np.loadtxt(f, dtype=dtype, delimiter=' ')
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
def parse_binary_pc_data(f, dtype, metadata):
|
| 233 |
+
rowstep = metadata['points']*dtype.itemsize
|
| 234 |
+
# for some reason pcl adds empty space at the end of files
|
| 235 |
+
buf = f.read(rowstep)
|
| 236 |
+
return np.fromstring(buf, dtype=dtype)
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
def parse_binary_compressed_pc_data(f, dtype, metadata):
|
| 240 |
+
# compressed size of data (uint32)
|
| 241 |
+
# uncompressed size of data (uint32)
|
| 242 |
+
# compressed data
|
| 243 |
+
# junk
|
| 244 |
+
fmt = 'II'
|
| 245 |
+
compressed_size, uncompressed_size =\
|
| 246 |
+
struct.unpack(fmt, f.read(struct.calcsize(fmt)))
|
| 247 |
+
compressed_data = f.read(compressed_size)
|
| 248 |
+
# TODO what to use as second argument? if buf is None
|
| 249 |
+
# (compressed > uncompressed)
|
| 250 |
+
# should we read buf as raw binary?
|
| 251 |
+
buf = lzf.decompress(compressed_data, uncompressed_size)
|
| 252 |
+
if len(buf) != uncompressed_size:
|
| 253 |
+
raise Exception('Error decompressing data')
|
| 254 |
+
# the data is stored field-by-field
|
| 255 |
+
pc_data = np.zeros(metadata['width'], dtype=dtype)
|
| 256 |
+
ix = 0
|
| 257 |
+
for dti in range(len(dtype)):
|
| 258 |
+
dt = dtype[dti]
|
| 259 |
+
bytes = dt.itemsize * metadata['width']
|
| 260 |
+
column = np.fromstring(buf[ix:(ix+bytes)], dt)
|
| 261 |
+
pc_data[dtype.names[dti]] = column
|
| 262 |
+
ix += bytes
|
| 263 |
+
return pc_data
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
def point_cloud_from_fileobj(f):
|
| 267 |
+
""" parse pointcloud coming from file object f
|
| 268 |
+
"""
|
| 269 |
+
header = []
|
| 270 |
+
while True:
|
| 271 |
+
ln = f.readline().strip()
|
| 272 |
+
if not isinstance(ln, str):
|
| 273 |
+
ln = ln.decode('utf-8')
|
| 274 |
+
header.append(ln)
|
| 275 |
+
if ln.startswith('DATA'):
|
| 276 |
+
metadata = parse_header(header)
|
| 277 |
+
dtype = _build_dtype(metadata)
|
| 278 |
+
break
|
| 279 |
+
if metadata['data'] == 'ascii':
|
| 280 |
+
pc_data = parse_ascii_pc_data(f, dtype, metadata)
|
| 281 |
+
elif metadata['data'] == 'binary':
|
| 282 |
+
pc_data = parse_binary_pc_data(f, dtype, metadata)
|
| 283 |
+
elif metadata['data'] == 'binary_compressed':
|
| 284 |
+
pc_data = parse_binary_compressed_pc_data(f, dtype, metadata)
|
| 285 |
+
else:
|
| 286 |
+
print('DATA field is neither "ascii" or "binary" or\
|
| 287 |
+
"binary_compressed"')
|
| 288 |
+
return PointCloud(metadata, pc_data)
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
def point_cloud_from_path(fname):
|
| 292 |
+
""" load point cloud in binary format
|
| 293 |
+
"""
|
| 294 |
+
with open(fname, 'rb') as f:
|
| 295 |
+
pc = point_cloud_from_fileobj(f)
|
| 296 |
+
return pc
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
def point_cloud_from_buffer(buf):
|
| 300 |
+
fileobj = sio.StringIO(buf)
|
| 301 |
+
pc = point_cloud_from_fileobj(fileobj)
|
| 302 |
+
fileobj.close() # necessary?
|
| 303 |
+
return pc
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
def point_cloud_to_fileobj(pc, fileobj, data_compression=None):
|
| 307 |
+
""" write pointcloud as .pcd to fileobj.
|
| 308 |
+
if data_compression is not None it overrides pc.data.
|
| 309 |
+
"""
|
| 310 |
+
metadata = pc.get_metadata()
|
| 311 |
+
if data_compression is not None:
|
| 312 |
+
data_compression = data_compression.lower()
|
| 313 |
+
assert(data_compression in ('ascii', 'binary', 'binary_compressed'))
|
| 314 |
+
metadata['data'] = data_compression
|
| 315 |
+
|
| 316 |
+
header = write_header(metadata).encode('utf-8')
|
| 317 |
+
fileobj.write(header)
|
| 318 |
+
if metadata['data'].lower() == 'ascii':
|
| 319 |
+
fmtstr = build_ascii_fmtstr(pc)
|
| 320 |
+
np.savetxt(fileobj, pc.pc_data, fmt=fmtstr)
|
| 321 |
+
elif metadata['data'].lower() == 'binary':
|
| 322 |
+
fileobj.write(pc.pc_data.tostring())
|
| 323 |
+
elif metadata['data'].lower() == 'binary_compressed':
|
| 324 |
+
# TODO
|
| 325 |
+
# a '_' field is ignored by pcl and breakes compressed point clouds.
|
| 326 |
+
# changing '_' to '_padding' or other name fixes this.
|
| 327 |
+
# admittedly padding shouldn't be compressed in the first place
|
| 328 |
+
# reorder to column-by-column
|
| 329 |
+
uncompressed_lst = []
|
| 330 |
+
for fieldname in pc.pc_data.dtype.names:
|
| 331 |
+
column = np.ascontiguousarray(pc.pc_data[fieldname]).tostring()
|
| 332 |
+
uncompressed_lst.append(column)
|
| 333 |
+
uncompressed = b''.join(uncompressed_lst)
|
| 334 |
+
uncompressed_size = len(uncompressed)
|
| 335 |
+
# print("uncompressed_size = %r"%(uncompressed_size))
|
| 336 |
+
buf = lzf.compress(uncompressed)
|
| 337 |
+
if buf is None:
|
| 338 |
+
# compression didn't shrink the file
|
| 339 |
+
# TODO what do to do in this case when reading?
|
| 340 |
+
buf = uncompressed
|
| 341 |
+
compressed_size = uncompressed_size
|
| 342 |
+
else:
|
| 343 |
+
compressed_size = len(buf)
|
| 344 |
+
fmt = 'II'
|
| 345 |
+
fileobj.write(struct.pack(fmt, compressed_size, uncompressed_size))
|
| 346 |
+
fileobj.write(buf)
|
| 347 |
+
else:
|
| 348 |
+
raise ValueError('unknown DATA type')
|
| 349 |
+
# we can't close because if it's stringio buf then we can't get value after
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
def point_cloud_to_path(pc, fname):
|
| 353 |
+
with open(fname, 'w') as f:
|
| 354 |
+
point_cloud_to_fileobj(pc, f)
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
def point_cloud_to_buffer(pc, data_compression=None):
|
| 358 |
+
fileobj = sio.StringIO()
|
| 359 |
+
point_cloud_to_fileobj(pc, fileobj, data_compression)
|
| 360 |
+
return fileobj.getvalue()
|
| 361 |
+
|
| 362 |
+
|
| 363 |
+
def save_point_cloud(pc, fname):
|
| 364 |
+
""" save pointcloud to fname in ascii format
|
| 365 |
+
"""
|
| 366 |
+
with open(fname, 'wb') as f:
|
| 367 |
+
point_cloud_to_fileobj(pc, f, 'ascii')
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
def save_point_cloud_bin(pc, fname):
|
| 371 |
+
""" save pointcloud to fname in binary format
|
| 372 |
+
"""
|
| 373 |
+
with open(fname, 'wb') as f:
|
| 374 |
+
point_cloud_to_fileobj(pc, f, 'binary')
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
def save_point_cloud_bin_compressed(pc, fname):
|
| 378 |
+
with open(fname, 'wb') as f:
|
| 379 |
+
point_cloud_to_fileobj(pc, f, 'binary_compressed')
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
def save_xyz_label(pc, fname, use_default_lbl=False):
|
| 383 |
+
""" save a simple (x y z label) pointcloud, ignoring all other features.
|
| 384 |
+
label is initialized to 1000, for jptview.
|
| 385 |
+
"""
|
| 386 |
+
md = pc.get_metadata()
|
| 387 |
+
if not use_default_lbl and ('label' not in md['fields']):
|
| 388 |
+
raise Exception('label is not a field in this point cloud')
|
| 389 |
+
with open(fname, 'w') as f:
|
| 390 |
+
for i in xrange(pc.points):
|
| 391 |
+
x, y, z = ['%.4f' % d for d in (
|
| 392 |
+
pc.pc_data['x'][i], pc.pc_data['y'][i], pc.pc_data['z'][i]
|
| 393 |
+
)]
|
| 394 |
+
lbl = '1000' if use_default_lbl else pc.pc_data['label'][i]
|
| 395 |
+
f.write(' '.join((x, y, z, lbl))+'\n')
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def save_xyz_intensity_label(pc, fname, use_default_lbl=False):
|
| 399 |
+
md = pc.get_metadata()
|
| 400 |
+
if not use_default_lbl and ('label' not in md['fields']):
|
| 401 |
+
raise Exception('label is not a field in this point cloud')
|
| 402 |
+
if 'intensity' not in md['fields']:
|
| 403 |
+
raise Exception('intensity is not a field in this point cloud')
|
| 404 |
+
with open(fname, 'w') as f:
|
| 405 |
+
for i in xrange(pc.points):
|
| 406 |
+
x, y, z = ['%.4f' % d for d in (
|
| 407 |
+
pc.pc_data['x'][i], pc.pc_data['y'][i], pc.pc_data['z'][i]
|
| 408 |
+
)]
|
| 409 |
+
intensity = '%.4f' % pc.pc_data['intensity'][i]
|
| 410 |
+
lbl = '1000' if use_default_lbl else pc.pc_data['label'][i]
|
| 411 |
+
f.write(' '.join((x, y, z, intensity, lbl))+'\n')
|
| 412 |
+
|
| 413 |
+
|
| 414 |
+
def save_txt(pc, fname, header=True):
|
| 415 |
+
""" TODO support multi-count fields
|
| 416 |
+
"""
|
| 417 |
+
with open(fname, 'w') as f:
|
| 418 |
+
if header:
|
| 419 |
+
header_lst = []
|
| 420 |
+
for field_name, cnt in zip(pc.fields, pc.count):
|
| 421 |
+
if cnt == 1:
|
| 422 |
+
header_lst.append(field_name)
|
| 423 |
+
else:
|
| 424 |
+
for c in xrange(cnt):
|
| 425 |
+
header_lst.append('%s_%04d' % (field_name, c))
|
| 426 |
+
f.write(' '.join(header_lst)+'\n')
|
| 427 |
+
fmtstr = build_ascii_fmtstr(pc)
|
| 428 |
+
np.savetxt(f, pc.pc_data, fmt=fmtstr)
|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
def update_field(pc, field, pc_data):
|
| 432 |
+
""" updates field in-place.
|
| 433 |
+
"""
|
| 434 |
+
pc.pc_data[field] = pc_data
|
| 435 |
+
return pc
|
| 436 |
+
|
| 437 |
+
|
| 438 |
+
def add_fields(pc, metadata, pc_data):
|
| 439 |
+
""" builds copy of pointcloud with extra fields
|
| 440 |
+
multi-count fields are sketchy
|
| 441 |
+
"""
|
| 442 |
+
if len(set(metadata['fields']).intersection(set(pc.fields))) > 0:
|
| 443 |
+
raise Exception("Fields with that name exist.")
|
| 444 |
+
|
| 445 |
+
if pc.points != len(pc_data):
|
| 446 |
+
raise Exception("Mismatch in number of points.")
|
| 447 |
+
|
| 448 |
+
new_metadata = pc.get_metadata()
|
| 449 |
+
new_metadata['fields'].extend(metadata['fields'])
|
| 450 |
+
new_metadata['count'].extend(metadata['count'])
|
| 451 |
+
new_metadata['size'].extend(metadata['size'])
|
| 452 |
+
new_metadata['type'].extend(metadata['type'])
|
| 453 |
+
|
| 454 |
+
# parse metadata to add
|
| 455 |
+
# TODO factor this
|
| 456 |
+
fieldnames, typenames = [], []
|
| 457 |
+
for f, c, t, s in zip(metadata['fields'],
|
| 458 |
+
metadata['count'],
|
| 459 |
+
metadata['type'],
|
| 460 |
+
metadata['size']):
|
| 461 |
+
np_type = pcd_type_to_numpy_type[(t, s)]
|
| 462 |
+
if c == 1:
|
| 463 |
+
fieldnames.append(f)
|
| 464 |
+
typenames.append(np_type)
|
| 465 |
+
else:
|
| 466 |
+
fieldnames.extend(['%s_%04d' % (f, i) for i in xrange(c)])
|
| 467 |
+
typenames.extend([np_type]*c)
|
| 468 |
+
dtype = list(zip(fieldnames, typenames))
|
| 469 |
+
# new dtype. could be inferred?
|
| 470 |
+
new_dtype = [(f, pc.pc_data.dtype[f])
|
| 471 |
+
for f in pc.pc_data.dtype.names] + dtype
|
| 472 |
+
|
| 473 |
+
new_data = np.empty(len(pc.pc_data), new_dtype)
|
| 474 |
+
for n in pc.pc_data.dtype.names:
|
| 475 |
+
new_data[n] = pc.pc_data[n]
|
| 476 |
+
for n, n_tmp in zip(fieldnames, pc_data.dtype.names):
|
| 477 |
+
new_data[n] = pc_data[n_tmp]
|
| 478 |
+
|
| 479 |
+
# TODO maybe just all the metadata in the dtype.
|
| 480 |
+
# TODO maybe use composite structured arrays for fields with count > 1
|
| 481 |
+
newpc = PointCloud(new_metadata, new_data)
|
| 482 |
+
return newpc
|
| 483 |
+
|
| 484 |
+
|
| 485 |
+
def cat_point_clouds(pc1, pc2):
|
| 486 |
+
if len(pc1.fields) != len(pc2.fields):
|
| 487 |
+
raise ValueError("Pointclouds must have same fields")
|
| 488 |
+
new_metadata = pc1.get_metadata()
|
| 489 |
+
new_data = np.concatenate((pc1.pc_data, pc2.pc_data))
|
| 490 |
+
# TODO this only makes sense for unstructured pc?
|
| 491 |
+
new_metadata['width'] = pc1.width+pc2.width
|
| 492 |
+
new_metadata['points'] = pc1.points+pc2.points
|
| 493 |
+
pc3 = PointCloud(new_metadata, new_data)
|
| 494 |
+
return pc3
|
| 495 |
+
|
| 496 |
+
|
| 497 |
+
def make_xyz_point_cloud(xyz, metadata=None):
|
| 498 |
+
""" Make a pointcloud object from xyz array.
|
| 499 |
+
xyz array is cast to float32.
|
| 500 |
+
"""
|
| 501 |
+
md = {'version': .7,
|
| 502 |
+
'fields': ['x', 'y', 'z'],
|
| 503 |
+
'size': [4, 4, 4],
|
| 504 |
+
'type': ['F', 'F', 'F'],
|
| 505 |
+
'count': [1, 1, 1],
|
| 506 |
+
'width': len(xyz),
|
| 507 |
+
'height': 1,
|
| 508 |
+
'viewpoint': [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
|
| 509 |
+
'points': len(xyz),
|
| 510 |
+
'data': 'binary'}
|
| 511 |
+
if metadata is not None:
|
| 512 |
+
md.update(metadata)
|
| 513 |
+
xyz = xyz.astype(np.float32)
|
| 514 |
+
pc_data = xyz.view(np.dtype([('x', np.float32),
|
| 515 |
+
('y', np.float32),
|
| 516 |
+
('z', np.float32)]))
|
| 517 |
+
# pc_data = np.rec.fromarrays([xyz[:,0], xyz[:,1], xyz[:,2]], dtype=dt)
|
| 518 |
+
# data = np.rec.fromarrays([xyz.T], dtype=dt)
|
| 519 |
+
pc = PointCloud(md, pc_data)
|
| 520 |
+
return pc
|
| 521 |
+
|
| 522 |
+
|
| 523 |
+
def make_xyz_rgb_point_cloud(xyz_rgb, metadata=None):
|
| 524 |
+
""" Make a pointcloud object from xyz array.
|
| 525 |
+
xyz array is assumed to be float32.
|
| 526 |
+
rgb is assumed to be encoded as float32 according to pcl conventions.
|
| 527 |
+
"""
|
| 528 |
+
md = {'version': .7,
|
| 529 |
+
'fields': ['x', 'y', 'z', 'rgb'],
|
| 530 |
+
'count': [1, 1, 1, 1],
|
| 531 |
+
'width': len(xyz_rgb),
|
| 532 |
+
'height': 1,
|
| 533 |
+
'viewpoint': [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
|
| 534 |
+
'points': len(xyz_rgb),
|
| 535 |
+
'type': ['F', 'F', 'F', 'F'],
|
| 536 |
+
'size': [4, 4, 4, 4],
|
| 537 |
+
'data': 'binary'}
|
| 538 |
+
if xyz_rgb.dtype != np.float32:
|
| 539 |
+
raise ValueError('array must be float32')
|
| 540 |
+
if metadata is not None:
|
| 541 |
+
md.update(metadata)
|
| 542 |
+
pc_data = xyz_rgb.view(np.dtype([('x', np.float32),
|
| 543 |
+
('y', np.float32),
|
| 544 |
+
('z', np.float32),
|
| 545 |
+
('rgb', np.float32)])).squeeze()
|
| 546 |
+
# pc_data = np.rec.fromarrays([xyz[:,0], xyz[:,1], xyz[:,2]], dtype=dt)
|
| 547 |
+
# data = np.rec.fromarrays([xyz.T], dtype=dt)
|
| 548 |
+
pc = PointCloud(md, pc_data)
|
| 549 |
+
return pc
|
| 550 |
+
|
| 551 |
+
|
| 552 |
+
def encode_rgb_for_pcl(rgb):
|
| 553 |
+
""" Input is Nx3 uint8 array with RGB values.
|
| 554 |
+
Output is Nx1 float32 array with bit-packed RGB, for PCL.
|
| 555 |
+
"""
|
| 556 |
+
assert(rgb.dtype == np.uint8)
|
| 557 |
+
assert(rgb.ndim == 2)
|
| 558 |
+
assert(rgb.shape[1] == 3)
|
| 559 |
+
rgb = rgb.astype(np.uint32)
|
| 560 |
+
rgb = np.array((rgb[:, 0] << 16) | (rgb[:, 1] << 8) | (rgb[:, 2] << 0),
|
| 561 |
+
dtype=np.uint32)
|
| 562 |
+
rgb.dtype = np.float32
|
| 563 |
+
return rgb
|
| 564 |
+
|
| 565 |
+
|
| 566 |
+
def decode_rgb_from_pcl(rgb):
|
| 567 |
+
rgb = rgb.copy()
|
| 568 |
+
rgb.dtype = np.uint32
|
| 569 |
+
r = np.asarray((rgb >> 16) & 255, dtype=np.uint8)
|
| 570 |
+
g = np.asarray((rgb >> 8) & 255, dtype=np.uint8)
|
| 571 |
+
b = np.asarray(rgb & 255, dtype=np.uint8)
|
| 572 |
+
rgb_arr = np.zeros((len(rgb), 3), dtype=np.uint8)
|
| 573 |
+
rgb_arr[:, 0] = r
|
| 574 |
+
rgb_arr[:, 1] = g
|
| 575 |
+
rgb_arr[:, 2] = b
|
| 576 |
+
return rgb_arr
|
| 577 |
+
|
| 578 |
+
|
| 579 |
+
def make_xyz_label_point_cloud(xyzl, label_type='f'):
|
| 580 |
+
""" TODO i labels? """
|
| 581 |
+
md = {'version': .7,
|
| 582 |
+
'fields': ['x', 'y', 'z', 'label'],
|
| 583 |
+
'count': [1, 1, 1, 1],
|
| 584 |
+
'width': len(xyzl),
|
| 585 |
+
'height': 1,
|
| 586 |
+
'viewpoint': [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
|
| 587 |
+
'points': len(xyzl),
|
| 588 |
+
'data': 'ASCII'}
|
| 589 |
+
if label_type.lower() == 'f':
|
| 590 |
+
md['size'] = [4, 4, 4, 4]
|
| 591 |
+
md['type'] = ['F', 'F', 'F', 'F']
|
| 592 |
+
elif label_type.lower() == 'u':
|
| 593 |
+
md['size'] = [4, 4, 4, 1]
|
| 594 |
+
md['type'] = ['F', 'F', 'F', 'U']
|
| 595 |
+
else:
|
| 596 |
+
raise ValueError('label type must be F or U')
|
| 597 |
+
# TODO use .view()
|
| 598 |
+
xyzl = xyzl.astype(np.float32)
|
| 599 |
+
dt = np.dtype([('x', np.float32), ('y', np.float32), ('z', np.float32),
|
| 600 |
+
('label', np.float32)])
|
| 601 |
+
pc_data = np.rec.fromarrays([xyzl[:, 0], xyzl[:, 1], xyzl[:, 2],
|
| 602 |
+
xyzl[:, 3]], dtype=dt)
|
| 603 |
+
pc = PointCloud(md, pc_data)
|
| 604 |
+
return pc
|
| 605 |
+
|
| 606 |
+
|
| 607 |
+
class PointCloud(object):
|
| 608 |
+
def __init__(self, metadata, pc_data):
|
| 609 |
+
self.metadata_keys = metadata.keys()
|
| 610 |
+
self.__dict__.update(metadata)
|
| 611 |
+
self.pc_data = pc_data
|
| 612 |
+
self.check_sanity()
|
| 613 |
+
|
| 614 |
+
def get_metadata(self):
|
| 615 |
+
""" returns copy of metadata """
|
| 616 |
+
metadata = {}
|
| 617 |
+
for k in self.metadata_keys:
|
| 618 |
+
metadata[k] = copy.copy(getattr(self, k))
|
| 619 |
+
return metadata
|
| 620 |
+
|
| 621 |
+
def check_sanity(self):
|
| 622 |
+
# pdb.set_trace()
|
| 623 |
+
md = self.get_metadata()
|
| 624 |
+
assert(_metadata_is_consistent(md))
|
| 625 |
+
assert(len(self.pc_data) == self.points)
|
| 626 |
+
assert(self.width*self.height == self.points)
|
| 627 |
+
assert(len(self.fields) == len(self.count))
|
| 628 |
+
assert(len(self.fields) == len(self.type))
|
| 629 |
+
|
| 630 |
+
def save(self, fname):
|
| 631 |
+
self.save_pcd(fname, 'ascii')
|
| 632 |
+
|
| 633 |
+
def save_pcd(self, fname, compression=None, **kwargs):
|
| 634 |
+
if 'data_compression' in kwargs:
|
| 635 |
+
warnings.warn('data_compression keyword is deprecated for'
|
| 636 |
+
' compression')
|
| 637 |
+
compression = kwargs['data_compression']
|
| 638 |
+
with open(fname, 'wb') as f:
|
| 639 |
+
point_cloud_to_fileobj(self, f, compression)
|
| 640 |
+
|
| 641 |
+
def save_pcd_to_fileobj(self, fileobj, compression=None, **kwargs):
|
| 642 |
+
if 'data_compression' in kwargs:
|
| 643 |
+
warnings.warn('data_compression keyword is deprecated for'
|
| 644 |
+
' compression')
|
| 645 |
+
compression = kwargs['data_compression']
|
| 646 |
+
point_cloud_to_fileobj(self, fileobj, compression)
|
| 647 |
+
|
| 648 |
+
def save_pcd_to_buffer(self, compression=None, **kwargs):
|
| 649 |
+
if 'data_compression' in kwargs:
|
| 650 |
+
warnings.warn('data_compression keyword is deprecated for'
|
| 651 |
+
' compression')
|
| 652 |
+
compression = kwargs['data_compression']
|
| 653 |
+
return point_cloud_to_buffer(self, compression)
|
| 654 |
+
|
| 655 |
+
def save_txt(self, fname):
|
| 656 |
+
save_txt(self, fname)
|
| 657 |
+
|
| 658 |
+
def save_xyz_label(self, fname, **kwargs):
|
| 659 |
+
save_xyz_label(self, fname, **kwargs)
|
| 660 |
+
|
| 661 |
+
def save_xyz_intensity_label(self, fname, **kwargs):
|
| 662 |
+
save_xyz_intensity_label(self, fname, **kwargs)
|
| 663 |
+
|
| 664 |
+
def copy(self):
|
| 665 |
+
new_pc_data = np.copy(self.pc_data)
|
| 666 |
+
new_metadata = self.get_metadata()
|
| 667 |
+
return PointCloud(new_metadata, new_pc_data)
|
| 668 |
+
|
| 669 |
+
def to_msg(self):
|
| 670 |
+
if not HAS_SENSOR_MSGS:
|
| 671 |
+
raise NotImplementedError('ROS sensor_msgs not found')
|
| 672 |
+
# TODO is there some metadata we want to attach?
|
| 673 |
+
return numpy_pc2.array_to_pointcloud2(self.pc_data)
|
| 674 |
+
|
| 675 |
+
@staticmethod
|
| 676 |
+
def from_path(fname):
|
| 677 |
+
return point_cloud_from_path(fname)
|
| 678 |
+
|
| 679 |
+
@staticmethod
|
| 680 |
+
def from_fileobj(fileobj):
|
| 681 |
+
return point_cloud_from_fileobj(fileobj)
|
| 682 |
+
|
| 683 |
+
@staticmethod
|
| 684 |
+
def from_buffer(buf):
|
| 685 |
+
return point_cloud_from_buffer(buf)
|
| 686 |
+
|
| 687 |
+
@staticmethod
|
| 688 |
+
def from_array(arr):
|
| 689 |
+
""" create a PointCloud object from an array.
|
| 690 |
+
"""
|
| 691 |
+
pc_data = arr.copy()
|
| 692 |
+
md = {'version': .7,
|
| 693 |
+
'fields': [],
|
| 694 |
+
'size': [],
|
| 695 |
+
'count': [],
|
| 696 |
+
'width': 0,
|
| 697 |
+
'height': 1,
|
| 698 |
+
'viewpoint': [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
|
| 699 |
+
'points': 0,
|
| 700 |
+
'type': [],
|
| 701 |
+
'data': 'binary_compressed'}
|
| 702 |
+
md['fields'] = pc_data.dtype.names
|
| 703 |
+
for field in md['fields']:
|
| 704 |
+
type_, size_ =\
|
| 705 |
+
numpy_type_to_pcd_type[pc_data.dtype.fields[field][0]]
|
| 706 |
+
md['type'].append(type_)
|
| 707 |
+
md['size'].append(size_)
|
| 708 |
+
# TODO handle multicount
|
| 709 |
+
md['count'].append(1)
|
| 710 |
+
md['width'] = len(pc_data)
|
| 711 |
+
md['points'] = len(pc_data)
|
| 712 |
+
pc = PointCloud(md, pc_data)
|
| 713 |
+
return pc
|
| 714 |
+
|
| 715 |
+
@staticmethod
|
| 716 |
+
def from_msg(msg, squeeze=True):
|
| 717 |
+
""" from pointcloud2 msg
|
| 718 |
+
squeeze: fix when clouds get 1 as first dim
|
| 719 |
+
"""
|
| 720 |
+
if not HAS_SENSOR_MSGS:
|
| 721 |
+
raise NotImplementedError('ROS sensor_msgs not found')
|
| 722 |
+
md = {'version': .7,
|
| 723 |
+
'fields': [],
|
| 724 |
+
'size': [],
|
| 725 |
+
'count': [],
|
| 726 |
+
'width': 0,
|
| 727 |
+
'height': 1,
|
| 728 |
+
'viewpoint': [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
|
| 729 |
+
'points': 0,
|
| 730 |
+
'type': [],
|
| 731 |
+
'data': 'binary_compressed'}
|
| 732 |
+
for field in msg.fields:
|
| 733 |
+
md['fields'].append(field.name)
|
| 734 |
+
t, s = pc2_type_to_pcd_type[field.datatype]
|
| 735 |
+
md['type'].append(t)
|
| 736 |
+
md['size'].append(s)
|
| 737 |
+
# TODO handle multicount correctly
|
| 738 |
+
if field.count > 1:
|
| 739 |
+
warnings.warn('fields with count > 1 are not well tested')
|
| 740 |
+
md['count'].append(field.count)
|
| 741 |
+
pc_data = np.squeeze(numpy_pc2.pointcloud2_to_array(msg))
|
| 742 |
+
md['width'] = len(pc_data)
|
| 743 |
+
md['points'] = len(pc_data)
|
| 744 |
+
pc = PointCloud(md, pc_data)
|
| 745 |
+
return pc
|
Annotated_Lidar/ntu_day_01/pypcd-master/pypcd-master/build/lib/pypcd/sautil.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
#from sensor_msgs.msg import PointCloud2
|
| 5 |
+
#import pygeom
|
| 6 |
+
#from pypcd import pypcd
|
| 7 |
+
#from pypcd import numpy_pc2
|
| 8 |
+
|
| 9 |
+
def transform_xyz(T_a_b, xyz):
|
| 10 |
+
""" Transforms an Nx3 array xyz in frame a to frame b
|
| 11 |
+
T_a_b is a 4x4 matrix s.t. xyz_b = T_a_b * xyz_a
|
| 12 |
+
conversely, T_a_b is the pose a in the frame b
|
| 13 |
+
"""
|
| 14 |
+
# xyz in frame a, homogeneous
|
| 15 |
+
xyz1_a = np.vstack([xyz.T, np.ones((1, xyz.shape[0]))])
|
| 16 |
+
# xyz in b frame
|
| 17 |
+
xyz1_b = np.dot(T_a_b, xyz1_a)
|
| 18 |
+
xyz_b = np.ascontiguousarray((xyz1_b[:3]).T)
|
| 19 |
+
return xyz_b
|
| 20 |
+
|
| 21 |
+
def transform_cloud_array(T_a_b, pc_data):
|
| 22 |
+
""" transforms structured array. looks for xyz and xyz_origin """
|
| 23 |
+
xyz = get_xyz_array(pc_data, dtype=pc_data.dtype[0])
|
| 24 |
+
xyz_b = transform_xyz(T_a_b, xyz)
|
| 25 |
+
pc_data['x'] = xyz_b[:,0]
|
| 26 |
+
pc_data['y'] = xyz_b[:,1]
|
| 27 |
+
pc_data['z'] = xyz_b[:,2]
|
| 28 |
+
if 'x_origin' in pc_data:
|
| 29 |
+
xyz_origin = get_xyz_viewpoint_array(pc_data, dtype=pc_data.dtype[0])
|
| 30 |
+
xyz_origin_b = transform_xyz(T_a_b, xyz_origin)
|
| 31 |
+
pc_data['x_origin'] = xyz_origin_b[:,0]
|
| 32 |
+
pc_data['y_origin'] = xyz_origin_b[:,1]
|
| 33 |
+
pc_data['z_origin'] = xyz_origin_b[:,2]
|
| 34 |
+
return pc_data
|
| 35 |
+
|
| 36 |
+
def flip_around_x(pc_data):
|
| 37 |
+
""" flip a structured array around x, in place"""
|
| 38 |
+
pc_data['y'] = -pc_data['y']
|
| 39 |
+
pc_data['z'] = -pc_data['z']
|
| 40 |
+
|
| 41 |
+
if 'x_origin' in pc_data:
|
| 42 |
+
pc_data['y_origin'] = -pc_data['y_origin']
|
| 43 |
+
pc_data['z_origin'] = -pc_data['z_origin']
|
| 44 |
+
|
| 45 |
+
def get_xyz_array(pc_data, dtype=np.float32):
|
| 46 |
+
""" get Nx3 array from structured array """
|
| 47 |
+
if pc_data.ndim==2 and pc_data.shape[0]==1:
|
| 48 |
+
pc_data = pc_data.squeeze()
|
| 49 |
+
xyz = np.empty((len(pc_data),3), dtype=dtype)
|
| 50 |
+
xyz[:,0] = pc_data['x']
|
| 51 |
+
xyz[:,1] = pc_data['y']
|
| 52 |
+
xyz[:,2] = pc_data['z']
|
| 53 |
+
return xyz
|
| 54 |
+
|
| 55 |
+
def get_xyz_viewpoint_array(pc_data, dtype=np.float32):
|
| 56 |
+
""" get Nx3 array from structured array """
|
| 57 |
+
if pc_data.ndim==2 and pc_data.shape[0]==1:
|
| 58 |
+
pc_data = pc_data.squeeze()
|
| 59 |
+
xyz = np.empty((len(pc_data),3), dtype=dtype)
|
| 60 |
+
xyz[:,0] = pc_data['x_origin']
|
| 61 |
+
xyz[:,1] = pc_data['y_origin']
|
| 62 |
+
xyz[:,2] = pc_data['z_origin']
|
| 63 |
+
return xyz
|
| 64 |
+
|
| 65 |
+
def get_xyzl_array(pc_data, dtype=np.float32):
|
| 66 |
+
if pc_data.ndim==2 and pc_data.shape[0]==1:
|
| 67 |
+
pc_data = pc_data.squeeze()
|
| 68 |
+
xyzl = np.empty((len(pc_data),4), dtype=dtype)
|
| 69 |
+
xyzl[:,0] = pc_data['x']
|
| 70 |
+
xyzl[:,1] = pc_data['y']
|
| 71 |
+
xyzl[:,2] = pc_data['z']
|
| 72 |
+
xyzl[:,3] = pc_data['label']
|
| 73 |
+
return xyzl
|
| 74 |
+
|
| 75 |
+
|
Annotated_Lidar/ntu_day_01/pypcd-master/pypcd-master/build/lib/pypcd/version.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from os.path import join as pjoin
|
| 2 |
+
|
| 3 |
+
# Format expected by setup.py and doc/source/conf.py: string of form "X.Y.Z"
|
| 4 |
+
_version_major = 0
|
| 5 |
+
_version_minor = 1
|
| 6 |
+
_version_micro = 1 # use '' for first of series, number for 1 and above
|
| 7 |
+
_version_extra = None # Uncomment this for full releases
|
| 8 |
+
|
| 9 |
+
# Construct full version string from these.
|
| 10 |
+
_ver = [_version_major, _version_minor]
|
| 11 |
+
if _version_micro:
|
| 12 |
+
_ver.append(_version_micro)
|
| 13 |
+
if _version_extra:
|
| 14 |
+
_ver.append(_version_extra)
|
| 15 |
+
|
| 16 |
+
__version__ = '.'.join(map(str, _ver))
|
| 17 |
+
|
| 18 |
+
CLASSIFIERS = ["Development Status :: 3 - Alpha",
|
| 19 |
+
"Environment :: Console",
|
| 20 |
+
"Intended Audience :: Science/Research",
|
| 21 |
+
"License :: OSI Approved :: MIT License",
|
| 22 |
+
"Operating System :: OS Independent",
|
| 23 |
+
"Programming Language :: Python",
|
| 24 |
+
"Topic :: Scientific/Engineering"]
|
| 25 |
+
|
| 26 |
+
# Description should be a one-liner:
|
| 27 |
+
description = "Pure Python PCD reader/writer"
|
| 28 |
+
|
| 29 |
+
# Long description will go up on the pypi page
|
| 30 |
+
long_description = """\
|
| 31 |
+
pypcd
|
| 32 |
+
========
|
| 33 |
+
|
| 34 |
+
Pure Python reader/writer for the PCL ``pcd`` data format for point clouds.
|
| 35 |
+
|
| 36 |
+
Please go to the repository README_.
|
| 37 |
+
|
| 38 |
+
.. _README: https://github.com/dimatura/pypcd/blob/master/README.md
|
| 39 |
+
|
| 40 |
+
License
|
| 41 |
+
=======
|
| 42 |
+
``pypcd`` is licensed under the terms of the MIT license. See the file
|
| 43 |
+
"LICENSE" for information on the history of this software, terms & conditions
|
| 44 |
+
for usage, and a DISCLAIMER OF ALL WARRANTIES.
|
| 45 |
+
|
| 46 |
+
All trademarks referenced herein are property of their respective holders.
|
| 47 |
+
|
| 48 |
+
Copyright (c) 2015--, Daniel Maturana
|
| 49 |
+
"""
|
| 50 |
+
|
| 51 |
+
NAME = "pypcd"
|
| 52 |
+
MAINTAINER = "Daniel Maturana"
|
| 53 |
+
MAINTAINER_EMAIL = "dimatura@cmu.edu"
|
| 54 |
+
DESCRIPTION = description
|
| 55 |
+
LONG_DESCRIPTION = long_description
|
| 56 |
+
URL = "http://github.com/dimatura/pypcd"
|
| 57 |
+
DOWNLOAD_URL = ""
|
| 58 |
+
LICENSE = "MIT"
|
| 59 |
+
AUTHOR = "Daniel Maturana"
|
| 60 |
+
AUTHOR_EMAIL = "dimatura@cmu.edu"
|
| 61 |
+
PLATFORMS = "OS Independent"
|
| 62 |
+
MAJOR = _version_major
|
| 63 |
+
MINOR = _version_minor
|
| 64 |
+
MICRO = _version_micro
|
| 65 |
+
VERSION = __version__
|
| 66 |
+
PACKAGES = ['pypcd',
|
| 67 |
+
'pypcd.tests']
|
| 68 |
+
PACKAGE_DATA = {'pypcd': [pjoin('data', '*')]}
|
| 69 |
+
INSTALL_REQUIRES = ["numpy", "python-lzf"]
|
Annotated_Lidar/ntu_day_01/pypcd-master/pypcd-master/pypcd/test_data/get_data.sh
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
wget http://pr.willowgarage.com/data/pcl/partial_cup_model_new.pcd
|
| 2 |
+
mv partial_cup_model_new.pcd partial_cup_model.pcd
|
Annotated_Lidar/ntu_day_01/pypcd-master/pypcd-master/pypcd/tests/__init__.py
ADDED
|
File without changes
|
Annotated_Lidar/ntu_day_01/pypcd-master/pypcd-master/pypcd/tests/test_pypcd.py
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
this is just a basic sanity check, not a really legit test suite.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import pytest
|
| 6 |
+
import numpy as np
|
| 7 |
+
import os
|
| 8 |
+
import shutil
|
| 9 |
+
import tempfile
|
| 10 |
+
|
| 11 |
+
header1 = """\
|
| 12 |
+
# .PCD v0.7 - Point Cloud Data file format
|
| 13 |
+
VERSION 0.7
|
| 14 |
+
FIELDS x y z i
|
| 15 |
+
SIZE 4 4 4 4
|
| 16 |
+
TYPE F F F F
|
| 17 |
+
COUNT 1 1 1 1
|
| 18 |
+
WIDTH 500028
|
| 19 |
+
HEIGHT 1
|
| 20 |
+
VIEWPOINT 0 0 0 1 0 0 0
|
| 21 |
+
POINTS 500028
|
| 22 |
+
DATA binary_compressed
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
header2 = """\
|
| 26 |
+
VERSION .7
|
| 27 |
+
FIELDS x y z normal_x normal_y normal_z curvature boundary k vp_x vp_y vp_z principal_curvature_x principal_curvature_y principal_curvature_z pc1 pc2
|
| 28 |
+
SIZE 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
|
| 29 |
+
TYPE F F F F F F F F F F F F F F F F F
|
| 30 |
+
COUNT 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
|
| 31 |
+
WIDTH 19812
|
| 32 |
+
HEIGHT 1
|
| 33 |
+
VIEWPOINT 0.0 0.0 0.0 1.0 0.0 0.0 0.0
|
| 34 |
+
POINTS 19812
|
| 35 |
+
DATA ascii
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
@pytest.fixture
|
| 39 |
+
def pcd_fname():
|
| 40 |
+
import pypcd
|
| 41 |
+
return os.path.join(pypcd.__path__[0], 'test_data',
|
| 42 |
+
'partial_cup_model.pcd')
|
| 43 |
+
|
| 44 |
+
@pytest.fixture
|
| 45 |
+
def ascii_pcd_fname():
|
| 46 |
+
import pypcd
|
| 47 |
+
return os.path.join(pypcd.__path__[0], 'test_data',
|
| 48 |
+
'ascii.pcd')
|
| 49 |
+
|
| 50 |
+
@pytest.fixture
|
| 51 |
+
def bin_pcd_fname():
|
| 52 |
+
import pypcd
|
| 53 |
+
return os.path.join(pypcd.__path__[0], 'test_data',
|
| 54 |
+
'bin.pcd')
|
| 55 |
+
|
| 56 |
+
def cloud_centroid(pc):
|
| 57 |
+
xyz = np.empty((pc.points, 3), dtype=float)
|
| 58 |
+
xyz[:,0] = pc.pc_data['x']
|
| 59 |
+
xyz[:,1] = pc.pc_data['y']
|
| 60 |
+
xyz[:,2] = pc.pc_data['z']
|
| 61 |
+
return xyz.mean(0)
|
| 62 |
+
|
| 63 |
+
def test_parse_header():
|
| 64 |
+
from pypcd.pypcd import parse_header
|
| 65 |
+
lines = header1.split('\n')
|
| 66 |
+
md = parse_header(lines)
|
| 67 |
+
assert (md['version'] == '0.7')
|
| 68 |
+
assert (md['fields'] == ['x', 'y', 'z', 'i'])
|
| 69 |
+
assert (md['size'] == [4, 4, 4, 4])
|
| 70 |
+
assert (md['type'] == ['F', 'F', 'F', 'F'])
|
| 71 |
+
assert (md['count'] == [1, 1, 1, 1])
|
| 72 |
+
assert (md['width'] == 500028)
|
| 73 |
+
assert (md['height'] == 1)
|
| 74 |
+
assert (md['viewpoint'] == [0, 0, 0, 1, 0, 0, 0])
|
| 75 |
+
assert (md['points'] == 500028)
|
| 76 |
+
assert (md['data'] == 'binary_compressed')
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def test_from_path(pcd_fname):
|
| 80 |
+
from pypcd import pypcd
|
| 81 |
+
pc = pypcd.PointCloud.from_path(pcd_fname)
|
| 82 |
+
|
| 83 |
+
fields = 'x y z normal_x normal_y normal_z curvature boundary k vp_x vp_y vp_z principal_curvature_x principal_curvature_y principal_curvature_z pc1 pc2'.split()
|
| 84 |
+
for fld1, fld2 in zip(pc.fields, fields):
|
| 85 |
+
assert(fld1 == fld2)
|
| 86 |
+
assert (pc.width == 19812)
|
| 87 |
+
assert (len(pc.pc_data) == 19812)
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def test_add_fields(pcd_fname):
|
| 91 |
+
from pypcd import pypcd
|
| 92 |
+
pc = pypcd.PointCloud.from_path(pcd_fname)
|
| 93 |
+
|
| 94 |
+
old_md = pc.get_metadata()
|
| 95 |
+
# new_dt = [(f, pc.pc_data.dtype[f]) for f in pc.pc_data.dtype.fields]
|
| 96 |
+
# new_data = [pc.pc_data[n] for n in pc.pc_data.dtype.names]
|
| 97 |
+
md = {'fields': ['bla', 'bar'], 'count': [1, 1], 'size': [4, 4],
|
| 98 |
+
'type': ['F', 'F']}
|
| 99 |
+
d = np.rec.fromarrays((np.random.random(len(pc.pc_data)),
|
| 100 |
+
np.random.random(len(pc.pc_data))))
|
| 101 |
+
newpc = pypcd.add_fields(pc, md, d)
|
| 102 |
+
|
| 103 |
+
new_md = newpc.get_metadata()
|
| 104 |
+
# print len(old_md['fields']), len(md['fields']), len(new_md['fields'])
|
| 105 |
+
# print old_md['fields'], md['fields'], new_md['fields']
|
| 106 |
+
assert(len(old_md['fields'])+len(md['fields']) == len(new_md['fields']))
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def test_path_roundtrip_ascii(pcd_fname):
|
| 110 |
+
from pypcd import pypcd
|
| 111 |
+
pc = pypcd.PointCloud.from_path(pcd_fname)
|
| 112 |
+
md = pc.get_metadata()
|
| 113 |
+
|
| 114 |
+
tmp_dirname = tempfile.mkdtemp(suffix='_pypcd', prefix='tmp')
|
| 115 |
+
|
| 116 |
+
tmp_fname = os.path.join(tmp_dirname, 'out.pcd')
|
| 117 |
+
|
| 118 |
+
pc.save_pcd(tmp_fname, compression='ascii')
|
| 119 |
+
|
| 120 |
+
assert(os.path.exists(tmp_fname))
|
| 121 |
+
|
| 122 |
+
pc2 = pypcd.PointCloud.from_path(tmp_fname)
|
| 123 |
+
md2 = pc2.get_metadata()
|
| 124 |
+
assert(md == md2)
|
| 125 |
+
|
| 126 |
+
np.testing.assert_equal(pc.pc_data, pc2.pc_data)
|
| 127 |
+
|
| 128 |
+
if os.path.exists(tmp_fname):
|
| 129 |
+
os.unlink(tmp_fname)
|
| 130 |
+
os.removedirs(tmp_dirname)
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def test_path_roundtrip_binary(pcd_fname):
|
| 134 |
+
from pypcd import pypcd
|
| 135 |
+
pc = pypcd.PointCloud.from_path(pcd_fname)
|
| 136 |
+
md = pc.get_metadata()
|
| 137 |
+
|
| 138 |
+
tmp_dirname = tempfile.mkdtemp(suffix='_pypcd', prefix='tmp')
|
| 139 |
+
|
| 140 |
+
tmp_fname = os.path.join(tmp_dirname, 'out.pcd')
|
| 141 |
+
|
| 142 |
+
pc.save_pcd(tmp_fname, compression='binary')
|
| 143 |
+
|
| 144 |
+
assert(os.path.exists(tmp_fname))
|
| 145 |
+
|
| 146 |
+
pc2 = pypcd.PointCloud.from_path(tmp_fname)
|
| 147 |
+
md2 = pc2.get_metadata()
|
| 148 |
+
for k, v in md2.items():
|
| 149 |
+
if k == 'data':
|
| 150 |
+
assert v == 'binary'
|
| 151 |
+
else:
|
| 152 |
+
assert v == md[k]
|
| 153 |
+
|
| 154 |
+
np.testing.assert_equal(pc.pc_data, pc2.pc_data)
|
| 155 |
+
|
| 156 |
+
if os.path.exists(tmp_fname):
|
| 157 |
+
os.unlink(tmp_fname)
|
| 158 |
+
os.removedirs(tmp_dirname)
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def test_path_roundtrip_binary_compressed(pcd_fname):
|
| 162 |
+
from pypcd import pypcd
|
| 163 |
+
pc = pypcd.PointCloud.from_path(pcd_fname)
|
| 164 |
+
md = pc.get_metadata()
|
| 165 |
+
|
| 166 |
+
tmp_dirname = tempfile.mkdtemp(suffix='_pypcd', prefix='tmp')
|
| 167 |
+
|
| 168 |
+
tmp_fname = os.path.join(tmp_dirname, 'out.pcd')
|
| 169 |
+
|
| 170 |
+
pc.save_pcd(tmp_fname, compression='binary_compressed')
|
| 171 |
+
|
| 172 |
+
assert(os.path.exists(tmp_fname))
|
| 173 |
+
|
| 174 |
+
pc2 = pypcd.PointCloud.from_path(tmp_fname)
|
| 175 |
+
md2 = pc2.get_metadata()
|
| 176 |
+
for k, v in md2.items():
|
| 177 |
+
if k == 'data':
|
| 178 |
+
assert v == 'binary_compressed'
|
| 179 |
+
else:
|
| 180 |
+
assert v == md[k]
|
| 181 |
+
|
| 182 |
+
np.testing.assert_equal(pc.pc_data, pc2.pc_data)
|
| 183 |
+
|
| 184 |
+
if os.path.exists(tmp_dirname):
|
| 185 |
+
shutil.rmtree(tmp_dirname)
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
def test_cat_pointclouds(pcd_fname):
|
| 189 |
+
from pypcd import pypcd
|
| 190 |
+
pc = pypcd.PointCloud.from_path(pcd_fname)
|
| 191 |
+
pc2 = pc.copy()
|
| 192 |
+
pc2.pc_data['x'] += 0.1
|
| 193 |
+
pc3 = pypcd.cat_point_clouds(pc, pc2)
|
| 194 |
+
for fld, fld3 in zip(pc.fields, pc3.fields):
|
| 195 |
+
assert(fld == fld3)
|
| 196 |
+
assert(pc3.width == pc.width+pc2.width)
|
| 197 |
+
|
| 198 |
+
def test_ascii_bin1(ascii_pcd_fname, bin_pcd_fname):
|
| 199 |
+
from pypcd import pypcd
|
| 200 |
+
apc1 = pypcd.point_cloud_from_path(ascii_pcd_fname)
|
| 201 |
+
bpc1 = pypcd.point_cloud_from_path(bin_pcd_fname)
|
| 202 |
+
am = cloud_centroid(apc1)
|
| 203 |
+
bm = cloud_centroid(bpc1)
|
| 204 |
+
assert( np.allclose(am, bm) )
|
| 205 |
+
|
| 206 |
+
|
mcd_cluster_ntu_day01_sgpr/keypoints_cloud_2923.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9ef8a7923324d07617bb8c27c738da5b6cc18d8bd5d6b060036b015e8ae46ca8
|
| 3 |
+
size 336
|
mcd_cluster_ntu_day01_sgpr/keypoints_cloud_3487.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cc56b1c381f723b780eb8e1776968a26e5d454d54e62452bbf60f4b59ce9fc52
|
| 3 |
+
size 384
|
mcd_cluster_ntu_day01_sgpr/keypoints_cloud_4224.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9504e8201ba6e6713b6aafbd9b1a8cdcc0df395ba25ec293e78a3207567ab410
|
| 3 |
+
size 384
|
mcd_cluster_ntu_day01_sgpr/keypoints_cloud_5884.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2f1e4608b2fe2cd32106fad2f02e3311a3517ea44e35134ceb216470979d57a5
|
| 3 |
+
size 304
|
mcd_cluster_ntu_day01_sgpr/keypoints_cloud_5918.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b4959d500f7137106b9f0aeb6c3d784344ea5e229ef3b9f27caeb9f0bfa536b6
|
| 3 |
+
size 272
|
tgfz7_ablation_runs/exp1_no_dynamic_ms072/ntu_day_01/keypoints_cloud_0766.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4fd3f9c25a0cc146bab91f392190143708b87ac1a621e93642262ed34e4c09a8
|
| 3 |
+
size 832
|
tgfz7_ablation_runs/exp1_no_dynamic_ms072/ntu_day_01/keypoints_cloud_2801.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:71fff7d3544075ebfed3fac6220c9f99fe69156381ee64ba0d3eb71b2706623e
|
| 3 |
+
size 560
|
tgfz7_ablation_runs/exp1_no_dynamic_ms072/ntu_day_01/keypoints_cloud_3867.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:61dd2cffb237834263e29fb17caa53f291515c5ce33529dfae4a243b25c907da
|
| 3 |
+
size 576
|
tgfz7_ablation_runs/exp1_no_dynamic_ms072/ntu_day_01/keypoints_cloud_4572.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4995719e0d1f44a1626a3b74c04351c467a69183567540a05f1d1a814048a432
|
| 3 |
+
size 1072
|
tgfz7_ablation_runs/exp1_no_dynamic_ms072/ntu_day_01/keypoints_cloud_5467.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7bcacd893daf113a98ab0fa8463d038ae6e2480109b952da301f262d1158c88c
|
| 3 |
+
size 624
|