mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-05 07:18:57 +08:00
fix metashape_to_json() if there is no 'components' tag in .xml (#1906)
fix metashape_to_json() if no 'components' in .xml
This commit is contained in:
1 parent
b1ddb9e695
commit
79b06ee2bf
1 file changed
+28
-26
@@ -115,30 +115,31 @@ def metashape_to_json( # pylint: disable=too-many-statements
|
|||||||
sensor_dict[sensor.get("id")] = s
|
sensor_dict[sensor.get("id")] = s
|
||||||
|
|
||||||
components = chunk.find("components")
|
components = chunk.find("components")
|
||||||
component_dict = {}
|
if components is not None:
|
||||||
for component in components:
|
component_dict = {}
|
||||||
transform = component.find("transform")
|
for component in components:
|
||||||
if transform is not None:
|
transform = component.find("transform")
|
||||||
rotation = transform.find("rotation")
|
if transform is not None:
|
||||||
if rotation is None:
|
rotation = transform.find("rotation")
|
||||||
r = np.eye(3)
|
if rotation is None:
|
||||||
else:
|
r = np.eye(3)
|
||||||
r = np.array([float(x) for x in rotation.text.split()]).reshape((3, 3))
|
else:
|
||||||
translation = transform.find("translation")
|
r = np.array([float(x) for x in rotation.text.split()]).reshape((3, 3))
|
||||||
if translation is None:
|
translation = transform.find("translation")
|
||||||
t = np.zeros(3)
|
if translation is None:
|
||||||
else:
|
t = np.zeros(3)
|
||||||
t = np.array([float(x) for x in translation.text.split()])
|
else:
|
||||||
scale = transform.find("scale")
|
t = np.array([float(x) for x in translation.text.split()])
|
||||||
if scale is None:
|
scale = transform.find("scale")
|
||||||
s = 1.0
|
if scale is None:
|
||||||
else:
|
s = 1.0
|
||||||
s = float(scale.text)
|
else:
|
||||||
|
s = float(scale.text)
|
||||||
|
|
||||||
m = np.eye(4)
|
m = np.eye(4)
|
||||||
m[:3, :3] = r
|
m[:3, :3] = r
|
||||||
m[:3, 3] = t / s
|
m[:3, 3] = t / s
|
||||||
component_dict[component.get("id")] = m
|
component_dict[component.get("id")] = m
|
||||||
|
|
||||||
frames = []
|
frames = []
|
||||||
cameras = chunk.find("cameras")
|
cameras = chunk.find("cameras")
|
||||||
@@ -171,9 +172,10 @@ def metashape_to_json( # pylint: disable=too-many-statements
|
|||||||
num_skipped += 1
|
num_skipped += 1
|
||||||
continue
|
continue
|
||||||
transform = np.array([float(x) for x in camera.find("transform").text.split()]).reshape((4, 4))
|
transform = np.array([float(x) for x in camera.find("transform").text.split()]).reshape((4, 4))
|
||||||
component_id = camera.get("component_id")
|
if components is not None:
|
||||||
if component_id in component_dict:
|
component_id = camera.get("component_id")
|
||||||
transform = component_dict[component_id] @ transform
|
if component_id in component_dict:
|
||||||
|
transform = component_dict[component_id] @ transform
|
||||||
transform = transform[[2, 0, 1, 3], :]
|
transform = transform[[2, 0, 1, 3], :]
|
||||||
transform[:, 1:3] *= -1
|
transform[:, 1:3] *= -1
|
||||||
frame["transform_matrix"] = transform.tolist()
|
frame["transform_matrix"] = transform.tolist()
|
||||||
|
|||||||
Reference in new issue
Block a user