Skip to content

Commit c40b75c

Browse files
committed
Template cuboid and script done
1 parent f145411 commit c40b75c

File tree

3 files changed

+21485
-0
lines changed

3 files changed

+21485
-0
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ For Assignment 3, we are using the `cuboid_detection` package.
2525
roslaunch cuboid_detection ground_plane_segmentation.launch
2626
```
2727

28+
3. To generate template cuboid point cloud files (.pcd), run the following script (run with --help for more details).
29+
30+
```
31+
cd ws/src/perception/cuboid_detection/templates/
32+
python make_cuboid.py
33+
```
34+
2835
## Notes
2936

3037
### Camera Info Topics (Intel RealSense D435)
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import argparse
2+
import numpy as np
3+
4+
parser = argparse.ArgumentParser()
5+
parser.add_argument('-L', '--length', default=200, type=int, help='cuboid length (mm)')
6+
parser.add_argument('-W', '--width', default=100, type=int, help='cuboid width (mm)')
7+
parser.add_argument('-H', '--height', default=75, type=int, help='cuboid height (mm)')
8+
parser.add_argument('-d', '--density', default=2, type=float, help='number of points per unit (mm)')
9+
parser.add_argument('-f', '--filename', default='', type=str, help='output filename')
10+
args = parser.parse_args()
11+
12+
# Specify dimensions in mm
13+
L = args.length
14+
W = args.width
15+
H = args.height
16+
17+
# Handle filename
18+
if not args.filename:
19+
args.filename = 'template_cuboid_L%d_W%d_H%d.pcd' % (L, W, H)
20+
elif not args.filename.endswith('.pcd'):
21+
args.filename += '.pcd'
22+
23+
# PCL header
24+
header = '''# .PCD v0.7 - Point Cloud Data file format
25+
VERSION 0.7
26+
FIELDS x y z
27+
SIZE 4 4 4
28+
TYPE F F F
29+
COUNT 1 1 1
30+
WIDTH %d
31+
HEIGHT 1
32+
VIEWPOINT 0 0 0 1 0 0 0
33+
POINTS %d
34+
DATA ascii
35+
'''
36+
37+
# Interpolate points
38+
X = np.arange(0, L, args.density)
39+
Y = np.arange(0, W, args.density)
40+
Z = np.arange(0, H, args.density)
41+
N = [Y.shape[0] * Z.shape[0], X.shape[0] * Z.shape[0], X.shape[0] * Y.shape[0]]
42+
43+
# Function to make (N, 1) face points
44+
def face(xin, yin):
45+
xout, yout = np.meshgrid(xin, yin)
46+
return np.matrix([xout.flatten(), yout.flatten()]).T
47+
48+
# Single column filled with same value
49+
column = lambda x: np.full((x[1], 1), x[0])
50+
51+
# Make all 6 faces
52+
faces = [None] * 6
53+
faces[0] = np.hstack((face(X, Y), column([0, N[2]])))
54+
faces[1] = np.hstack((face(X, Z)[:, 0], column([0, N[1]]), face(X, Z)[:, 1]))
55+
faces[2] = np.hstack((column([0, N[0]]), face(Y, Z)[:, 0], face(Y, Z)[:, 1]))
56+
faces[3] = np.hstack((face(X, Y), column([H, N[2]])))
57+
faces[4] = np.hstack((face(X, Z)[:, 0], column([W, N[1]]), face(X, Z)[:, 1]))
58+
faces[5] = np.hstack((column([L, N[0]]), face(Y, Z)[:, 0], face(Y, Z)[:, 1]))
59+
faces = np.vstack(faces)
60+
61+
# Save PCD file
62+
with open(args.filename, 'w') as pcd:
63+
pcd.write(header % (len(faces), len(faces)))
64+
for row in faces:
65+
pcd.write('%f %f %f\n' % (row[0, 0], row[0, 1], row[0, 2]))
66+
67+
print('Saved "%s" with %d points' % (args.filename, len(faces)))

0 commit comments

Comments
 (0)