Skip to content

Instantly share code, notes, and snippets.

@ymd-stella
Last active September 2, 2024 13:42
Show Gist options
  • Save ymd-stella/0992ef8de1051529fcbff72c06f96867 to your computer and use it in GitHub Desktop.
Save ymd-stella/0992ef8de1051529fcbff72c06f96867 to your computer and use it in GitHub Desktop.
Reads keyframe poses from map data in sqlite3 format.
#!/usr/bin/env python3
import argparse
import sqlite3
import struct
import numpy as np
def main():
parser = argparse.ArgumentParser()
parser.add_argument("filepath", type=str)
args = parser.parse_args()
conn = sqlite3.connect(args.filepath)
cur = conn.cursor()
cur.execute('SELECT * FROM keyframes ORDER BY id')
for keyfrm in cur:
# See https://github.com/stella-cv/stella_vslam/blob/04f87d943ffcc5edf3e09c1a9d2a806ef4b762b4/src/stella_vslam/data/map_database.cc#L749-L759.
pose_cw_bytes = keyfrm[5]
pose_cw_vec = struct.unpack("<16d", pose_cw_bytes)
pose_cw = np.matrix(np.array(pose_cw_vec).reshape((4, 4)).T)
map_to_camera_affine_cv = np.linalg.inv(pose_cw)
with np.printoptions(suppress=True):
print(map_to_camera_affine_cv)
cur.close()
conn.close()
if __name__ == "__main__":
main()
@Inshu32
Copy link

Inshu32 commented Sep 2, 2024

Hi,

Thanks for the code here. I would like to ask, how to get poses from running stella vslam to sqlite3 format.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment