Created
February 8, 2018 03:53
-
-
Save MatsumotoJ/74e873ec4110274d6d0d84cc9167943f to your computer and use it in GitHub Desktop.
functions to read pre-processed point cloud data made by 3DTracker (www.3dtracker.org; beta version)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import struct | |
| def get_fname(fname_metadata, str_ext): | |
| n = fname_metadata.find('.metadata.xml') | |
| base = fname_metadata[0:n] | |
| return base+str_ext | |
| # call this function to read the file (fname_metadata = path of *.metadata.xml; i_frame = frame no. to read) | |
| def load_mrgpc(fname_metadata, i_frame): | |
| fname_mrgpc = get_fname(fname_metadata, '.mrgpc.frame.bin') | |
| fname_ts = get_fname(fname_metadata, '.mrgpc.ts.txt') | |
| ts_data = np.loadtxt(fname_ts) | |
| file_pc = open(fname_mrgpc, 'rb') | |
| file_pc.seek(int(ts_data[i_frame, 1])) | |
| buf = file_pc.read(8); | |
| n_points = struct.unpack('Q', buf)[0] # n_point: number of point in the point cloud of the frame | |
| pc = np.zeros((n_points,10)) # pc: point cloud data in the frame (matrix of n_point x 10) | |
| for i in range(n_points): | |
| buf = file_pc.read(2*3); | |
| xyz = struct.unpack('hhh', buf) | |
| buf = file_pc.read(1*3); | |
| rgb = struct.unpack('BBB', buf) | |
| buf = file_pc.read(1*3); | |
| normal = struct.unpack('bbb', buf) | |
| # xyz of the point (in mm), rgb (0-255), xyz of the surface normal vector (0-1) | |
| pc[i,:] = [float(xyz[0])/2000.0, float(xyz[1])/2000.0, float(xyz[2])/2000.0, \ | |
| float(rgb[0])/255.0, float(rgb[1])/255.0, float(rgb[2])/255.0, 1.0, \ | |
| float(normal[0])/100.0, float(normal[1])/100.0, float(normal[2])/100.0 ] | |
| file_pc.close(); | |
| return pc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment