beverley-gorry/colmap-vslamlab
0
1# Copyright (c), ETH Zurich and UNC Chapel Hill.2# All rights reserved.3#4# Redistribution and use in source and binary forms, with or without5# modification, are permitted provided that the following conditions are met:6#7# * Redistributions of source code must retain the above copyright8# notice, this list of conditions and the following disclaimer.9#10# * Redistributions in binary form must reproduce the above copyright11# notice, this list of conditions and the following disclaimer in the12# documentation and/or other materials provided with the distribution.13#14# * Neither the name of ETH Zurich and UNC Chapel Hill nor the names of15# its contributors may be used to endorse or promote products derived16# from this software without specific prior written permission.17#18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"19# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE22# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR23# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF24# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS25# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN26# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)27# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE28# POSSIBILITY OF SUCH DAMAGE.29 30 31# This script exports inlier image pairs from a COLMAP database to a text file.32 33import argparse34import sqlite335 36 37def parse_args():38 parser = argparse.ArgumentParser()39 parser.add_argument("--database_path", required=True)40 parser.add_argument("--match_list_path", required=True)41 parser.add_argument("--min_num_matches", type=int, default=15)42 args = parser.parse_args()43 return args44 45 46def pair_id_to_image_ids(pair_id):47 image_id2 = pair_id % 214748364748 image_id1 = (pair_id - image_id2) / 214748364749 return image_id1, image_id250 51 52def main():53 args = parse_args()54 55 connection = sqlite3.connect(args.database_path)56 cursor = connection.cursor()57 58 # Get a mapping between image ids and image names59 image_id_to_name = dict()60 cursor.execute("SELECT image_id, name FROM images;")61 for row in cursor:62 image_id = row[0]63 name = row[1]64 image_id_to_name[image_id] = name65 66 # Iterate over entries in the two_view_geometries table67 output = open(args.match_list_path, "w")68 cursor.execute("SELECT pair_id, rows FROM two_view_geometries;")69 for row in cursor:70 pair_id = row[0]71 rows = row[1]72 73 if rows < args.min_num_matches:74 continue75 76 image_id1, image_id2 = pair_id_to_image_ids(pair_id)77 image_name1 = image_id_to_name[image_id1]78 image_name2 = image_id_to_name[image_id2]79 80 output.write("%s %s\n" % (image_name1, image_name2))81 82 output.close()83 cursor.close()84 connection.close()85 86 87if __name__ == "__main__":88 main()89 