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 merges multiple homogeneous PLY files into a single PLY file.32 33import argparse34import os35 36import numpy as np37import plyfile38 39 40def parse_args():41 parser = argparse.ArgumentParser()42 parser.add_argument("--folder_path", required=True)43 parser.add_argument("--merged_path", required=True)44 args = parser.parse_args()45 return args46 47 48def main():49 args = parse_args()50 51 files = []52 for file_name in os.listdir(args.folder_path):53 if len(file_name) < 4 or file_name[-4:].lower() != ".ply":54 continue55 56 print("Reading file", file_name)57 file = plyfile.PlyData.read(os.path.join(args.folder_path, file_name))58 for element in file.elements:59 files.append(element.data)60 61 print("Merging files")62 merged_file = np.concatenate(files, -1)63 merged_el = plyfile.PlyElement.describe(merged_file, "vertex")64 65 print("Writing merged file")66 plyfile.PlyData([merged_el]).write(args.merged_path)67 68 69if __name__ == "__main__":70 main()71 