I have been trying to add color to my point cloud. I want to add red green and blue but for now, I am only adding red to simplify the problem. I want to be using chunks to read the file. Right now when I read the file back I get an array of zeros.
import numpy as np
import laspy
def calculate_normals(file: str, chunk_size: int):
# read file point cloud file
header = laspy.LasHeader(point_format=2, version="1.2")
with laspy.open(file, mode='r') as read_f:
n_points = int(read_f.header.point_count)
n_chunks = int(n_points / chunk_size) + 1
chunk_size = n_points // n_chunks + 1
# Write to new file
header.scales = read_f.header.scales
out_file = file[:-4] + '_normals' + file[-4:]
print('Opening', out_file)
with laspy.open(out_file, mode='w', header=header) as write_f:
for count, chunk in enumerate(read_f.chunk_iterator(chunk_size)):
rec_s = len(chunk)
header = laspy.LasHeader(point_format=2, version="1.2")
point_record = laspy.ScaleAwarePointRecord.zeros(rec_s, header=header)
points = np.array((chunk.x, chunk.y, chunk.z)).T
point_record.x, point_record.y, point_record.z = points.T
point_record.red = np.full(len(chunk), 155)
def read_test(file):
with laspy.open(file, mode='r') as read_f:
points = read_f.read_points(500)
print(points.red)
You are modifying the point_record, but you don't seem to actually be writing it.
You have to use
write_f.write_points