-
Notifications
You must be signed in to change notification settings - Fork 56
/
outputPly.m
42 lines (25 loc) · 1000 Bytes
/
outputPly.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function outputPly(PLYfilename, cameraRtC2W, data)
fprintf('Writing ply point cloud file: ');
tic
frameInterval = 10;
pointCount = round(min(640*480*0.5,1000000/(length(data.image)/frameInterval)));
dataChunk = uint8([]);
for frameID=1:frameInterval:length(data.image)
image = imread(data.image{frameID});
XYZcam = depth2XYZcamera(data.K, depthRead(data.depth{frameID}));
XYZcam = reshape(XYZcam,640*480,4)';
isValid = find(XYZcam(4,:));
XYZcam = transformRT(XYZcam(1:3,:),cameraRtC2W(:,:,frameID));
try
selID = randsample(length(isValid),pointCount);
catch
selID = randsample(length(isValid),pointCount,true);
end
isValid = isValid(selID);
RGB = reshape(image, 640*480, 3)';
dataChunk = [dataChunk [reshape(typecast(reshape(single(XYZcam(:,isValid)),1,[]),'uint8'),3*4,[]); RGB(:,isValid)]];
end
file = writePLYhead(PLYfilename, size(dataChunk,2));
fwrite(file, dataChunk,'uint8');
fclose(file);
toc;