mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-13 11:24:00 +08:00
fix: coerce numpy scalars in colmap write_next_bytes for NumPy 2.x
NumPy 2.x no longer implicitly converts a size-1 ndarray or a NumPy scalar to a Python scalar inside struct.pack, so writing COLMAP binary models (e.g. Point3D.error passed as np.array([0])) raised 'struct.error: required argument is not a float'. Coerce ndarray/generic to a Python scalar via .item() before packing. Fixes the failing tests/process_data/test_process_images.py cases.
This commit is contained in:
1 parent
50e0e3c70c
commit
7c93989cc8
1 file changed
+5
@@ -96,6 +96,11 @@ def write_next_bytes(fid, data, format_char_sequence, endian_character="<"):
|
||||
if isinstance(data, (list, tuple)):
|
||||
bytes = struct.pack(endian_character + format_char_sequence, *data)
|
||||
else:
|
||||
# NumPy 2.x no longer implicitly converts a size-1 ndarray (or a NumPy
|
||||
# scalar) to a Python scalar inside struct.pack, which raises
|
||||
# "required argument is not a float/integer". Coerce explicitly.
|
||||
if isinstance(data, (np.ndarray, np.generic)):
|
||||
data = data.item()
|
||||
bytes = struct.pack(endian_character + format_char_sequence, data)
|
||||
fid.write(bytes)
|
||||
|
||||
|
||||
Reference in new issue
Block a user