Created
July 6, 2021 07:27
-
-
Save CGCooke/2f82a585c33b1de1427e3875bcbb9b5b to your computer and use it in GitHub Desktop.
How to access the COLMAP database.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
import sqlite3 | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from PIL import Image | |
con = sqlite3.connect('Nuketown.db') | |
plt.rcParams['figure.figsize'] = [20, 20] | |
cur = con.cursor() | |
for row in cur.execute('SELECT * FROM cameras'): | |
print(row[0:3]) | |
print(np.frombuffer(row[4], dtype=np.float64)) | |
print(cur.description) | |
for row in cur.execute('SELECT * FROM images'): | |
print(row) | |
print(cur.description) | |
count = 0 | |
for row in cur.execute('SELECT * FROM keypoints'): | |
image_id, rows, cols, data = row | |
array = np.frombuffer(data, dtype=np.float32) | |
array = array.reshape((rows, cols)) | |
break | |
img = Image.open('01285.jpg') | |
plt.rcParams['figure.figsize'] = [15, 15] | |
plt.scatter(array[:, 0], array[:, 1], alpha=0.5) | |
plt.imshow(img) | |
plt.show() | |
print(cur.description) | |
count = 0 | |
for row in cur.execute('SELECT * FROM descriptors'): | |
image_id, rows, cols, data = row | |
array = np.frombuffer(data, dtype=np.uint8) | |
array = array.reshape((rows, cols)) | |
print(array.shape) | |
break | |
print(cur.description) | |
def image_ids_to_pair_id(image_id1, image_id2): | |
if image_id1 > image_id2: | |
return 2147483647 * image_id2 + image_id1 | |
else: | |
return 2147483647 * image_id1 + image_id2 | |
def pair_id_to_image_ids(pair_id): | |
image_id2 = pair_id % 2147483647 | |
image_id1 = int((pair_id - image_id2) / 2147483647) | |
return image_id1, image_id2 | |
count = 0 | |
for row in cur.execute('SELECT * FROM matches'): | |
pair_id, rows, cols, data = row | |
array = np.frombuffer(data, dtype=np.uint32) | |
array = array.reshape((rows, cols)) | |
print(array) | |
print(pair_id_to_image_ids(pair_id)) | |
print(array.shape) | |
break | |
print(cur.description) | |
count = 0 | |
for row in cur.execute('SELECT * FROM two_view_geometries'): | |
pair_id, rows, cols, data, config, F, E, H = row | |
array = np.frombuffer(data, dtype=np.uint32) | |
array = array.reshape((rows, cols)) | |
break | |
print(cur.description) | |
for row in cur.execute('SELECT * FROM keypoints WHERE image_id IS 1'): | |
image_id, rows, cols, data = row | |
array1 = np.frombuffer(data, dtype=np.float32) | |
array1 = array1.reshape((rows, cols)) | |
for row in cur.execute('SELECT * FROM keypoints WHERE image_id IS 2'): | |
image_id, rows, cols, data = row | |
array2 = np.frombuffer(data, dtype=np.float32) | |
array2 = array2.reshape((rows, cols)) | |
img1 = Image.open('01285.jpg') | |
img2 = Image.open('01286.jpg') | |
for i in range(0, array.shape[0], 100): | |
idx1, idx2 = array[i][0], array[i][1] | |
x1, y1 = array1[idx1][0], array1[idx1][1] | |
x2, y2 = array2[idx2][0], array2[idx2][1] | |
plt.plot([x1, x2 + 2560], [y1, y2], alpha=0.2) | |
plt.imshow(np.hstack([img1, img2])) | |
plt.show() | |
print(cur.description) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment