gtsam/python/gtsam/examples/SFMdata.py

44 lines
1.2 KiB
Python
Raw Normal View History

2018-09-28 10:46:24 +08:00
"""
A structure-from-motion example with landmarks
- The landmarks form a 10 meter cube
- The robot rotates around the landmarks, always facing towards the cube
"""
# pylint: disable=invalid-name, E1101
2018-09-28 10:46:24 +08:00
2021-08-22 11:08:37 +08:00
from typing import List
2018-09-28 10:46:24 +08:00
import numpy as np
import gtsam
2021-08-22 11:08:37 +08:00
from gtsam import Cal3_S2, Point3, Pose3
2018-09-28 10:46:24 +08:00
2021-08-22 11:08:37 +08:00
def createPoints() -> List[Point3]:
2018-09-28 10:46:24 +08:00
# Create the set of ground-truth landmarks
2021-08-22 11:08:37 +08:00
points = [
Point3(10.0, 10.0, 10.0),
Point3(-10.0, 10.0, 10.0),
Point3(-10.0, -10.0, 10.0),
Point3(10.0, -10.0, 10.0),
Point3(10.0, 10.0, -10.0),
Point3(-10.0, 10.0, -10.0),
Point3(-10.0, -10.0, -10.0),
Point3(10.0, -10.0, -10.0),
]
2018-09-28 10:46:24 +08:00
return points
2021-08-22 11:08:37 +08:00
def createPoses(K: Cal3_S2) -> List[Pose3]:
"""Generate a set of ground-truth camera poses arranged in a circle about the origin."""
radius = 40.0
height = 10.0
2021-08-22 11:08:37 +08:00
angles = np.linspace(0, 2 * np.pi, 8, endpoint=False)
2018-09-28 10:46:24 +08:00
up = gtsam.Point3(0, 0, 1)
target = gtsam.Point3(0, 0, 0)
poses = []
for theta in angles:
2021-08-22 11:08:37 +08:00
position = gtsam.Point3(radius * np.cos(theta), radius * np.sin(theta), height)
2018-09-28 10:46:24 +08:00
camera = gtsam.PinholeCameraCal3_S2.Lookat(position, target, up, K)
poses.append(camera.pose())
return poses