MCPcopy Create free account
hub / github.com/XiaoBaiiiiii/colmap-pcd / write_array

Function write_array

scripts/python/read_write_dense.py:58–87  ·  view source on GitHub ↗

see: src/mvs/mat.h void Mat ::Write(const std::string& path)

(array, path)

Source from the content-addressed store, hash-verified

56
57
58def write_array(array, path):
59 """
60 see: src/mvs/mat.h
61 void Mat<T>::Write(const std::string& path)
62 """
63 assert array.dtype == np.float32
64 if len(array.shape) == 2:
65 height, width = array.shape
66 channels = 1
67 elif len(array.shape) == 3:
68 height, width, channels = array.shape
69 else:
70 assert False
71
72 with open(path, "w") as fid:
73 fid.write(str(width) + "&" + str(height) + "&" + str(channels) + "&")
74
75 with open(path, "ab") as fid:
76 if len(array.shape) == 2:
77 array_trans = np.transpose(array, (1, 0))
78 elif len(array.shape) == 3:
79 array_trans = np.transpose(array, (1, 0, 2))
80 else:
81 assert False
82 data_1d = array_trans.reshape(-1, order="F")
83 data_list = data_1d.tolist()
84 endian_character = "<"
85 format_char_sequence = "".join(["f"] * len(data_list))
86 byte_data = struct.pack(endian_character + format_char_sequence, *data_list)
87 fid.write(byte_data)
88
89
90def parse_args():

Callers 1

mainFunction · 0.90

Calls 2

writeMethod · 0.45
transposeMethod · 0.45

Tested by 1

mainFunction · 0.72