@@ -520,9 +520,9 @@ def write_pcd(self, file_object, undistorted, registered=None):
520
520
rgb (:py:class:`Frame`): if not-None, the RGB data corresponding to
521
521
the depth frame.
522
522
"""
523
- undistorted_array = undistorted .to_array ()
524
- rows , cols = np .nonzero (undistorted_array )
523
+ cols , rows = np .meshgrid (np .arange (undistorted .width ), np .arange (undistorted .height ))
525
524
xs , ys , zs = self .get_points_xyz (undistorted , rows , cols )
525
+ n_points = int (np .product (xs .shape ))
526
526
527
527
print ('VERSION .7' , file = file_object )
528
528
@@ -531,23 +531,23 @@ def write_pcd(self, file_object, undistorted, registered=None):
531
531
print ('SIZE 4 4 4' , file = file_object )
532
532
print ('TYPE F F F' , file = file_object )
533
533
print ('COUNT 1 1 1' , file = file_object )
534
- data = np .vstack ((- xs , - ys , - zs )).T
534
+ data = np .vstack ((- xs . flatten () , - ys . flatten () , - zs . flatten () )).T
535
535
else :
536
536
print ('FIELDS x y z rgb' , file = file_object )
537
537
print ('SIZE 4 4 4 4' , file = file_object )
538
538
print ('TYPE F F F I' , file = file_object )
539
539
print ('COUNT 1 1 1 1' , file = file_object )
540
- bgrx = ( registered .to_array ()[ rows , cols , ...] ).astype (np .uint32 )
541
- rgbs = bgrx [: , 0 ] + (bgrx [: , 1 ] << 8 ) + (bgrx [: , 2 ] << 16 )
542
- data = np .vstack ((- xs , - ys , - zs , rgbs )).T
540
+ bgrx = registered .to_array ().astype (np .uint32 )
541
+ rgbs = bgrx [... , 0 ] + (bgrx [... , 1 ] << 8 ) + (bgrx [... , 2 ] << 16 )
542
+ data = np .vstack ((- xs . flatten () , - ys . flatten () , - zs . flatten () , rgbs . flatten () )).T
543
543
544
- print ('WIDTH {}' .format (xs . shape [ 0 ] ), file = file_object )
545
- print ('HEIGHT 1' , file = file_object )
544
+ print ('WIDTH {}' .format (undistorted . width ), file = file_object )
545
+ print ('HEIGHT {}' . format ( undistorted . height ) , file = file_object )
546
546
print ('VIEWPOINT 0 0 0 1 0 0 0' , file = file_object )
547
- print ('POINTS {}' .format (xs . shape [ 0 ] ), file = file_object )
547
+ print ('POINTS {}' .format (n_points ), file = file_object )
548
548
print ('DATA ascii' , file = file_object )
549
549
550
- assert data .shape [0 ] == xs . shape [ 0 ]
550
+ assert data .shape [0 ] == n_points
551
551
552
552
for row in data :
553
553
print (' ' .join ([str (f ) for f in row ]), file = file_object )
0 commit comments