2 * @file Pose3SLAMExample_initializePose3.cpp 3 * @brief A 3D Pose SLAM example that reads input from g2o, and initializes the 4 * Pose3 using InitializePose3 6 * @author Vikrant Shah based on CPP example by Luca Carlone 10 from __future__
import print_function
13 import matplotlib.pyplot
as plt
14 from mpl_toolkits.mplot3d
import Axes3D
21 """Create 6d double numpy array.""" 22 return np.array([x, y, z, a, b, c], dtype=float)
25 parser = argparse.ArgumentParser(
26 description=
"A 3D Pose SLAM example that reads input from g2o, and " 28 parser.add_argument(
'-i',
'--input', help=
'input file g2o format')
29 parser.add_argument(
'-o',
'--output',
30 help=
"the path to the output file with optimized graph")
31 parser.add_argument(
"-p",
"--plot", action=
"store_true",
32 help=
"Flag to plot results")
33 args = parser.parse_args()
45 print(
"Adding prior to g2o file ")
46 firstKey = initial.keys()[0]
47 graph.add(gtsam.PriorFactorPose3(firstKey,
gtsam.Pose3(), priorModel))
50 params.setVerbosity(
"Termination")
52 result = optimizer.optimize()
53 print(
"Optimization complete")
55 print(
"initial error = ", graph.error(initial))
56 print(
"final error = ", graph.error(result))
58 if args.output
is None:
59 print(
"Final Result:\n{}".format(result))
61 outputFile = args.output
62 print(
"Writing results to file: ", outputFile)
69 for i
in range(resultPoses.size()):
70 plot.plot_pose3(1, resultPoses.atPose3(i))
void print(const Matrix &A, const string &s, ostream &stream)
Values allPose3s(const Values &values)
Extract all Pose3 values.
def vector6(x, y, z, a, b, c)
GTSAM_EXPORT GraphAndValues readG2o(const std::string &g2oFile, const bool is3D=false, KernelFunctionType kernelFunctionType=KernelFunctionTypeNONE)
This function parses a g2o file and stores the measurements into a NonlinearFactorGraph and the initi...
GTSAM_EXPORT void writeG2o(const NonlinearFactorGraph &graph, const Values &estimate, const std::string &filename)
This function writes a g2o file from NonlinearFactorGraph and a Values structure. ...
static shared_ptr Variances(const Vector &variances, bool smart=true)
GTSAM_EXPORT std::string findExampleDataFile(const std::string &name)