Advertisement

3D Gaussian Splatting Windows安装

阅读量:

该文本详细描述了如何在 upstream-implicit-loss 环境中安装并配置一系列工具包以进行图像处理和点云生成。具体步骤包括:下载源码、安装 CUDA 和 COLMAP 等库、配置环境变量并运行相关命令完成数据预处理和训练任务。

请按照以下步骤安装C++ 编译器

https://aka.ms/vs/17/release/vs_buildtools.exe

1.下载源码

复制代码
    git clone https://github.com/graphdeco-inria/gaussian-splatting --recursive

2.安装cuda

NVIDIA GPU Computing Toolkit

CUDA Toolkit Archive | NVIDIA Developer

3.安装COLMAP

https://github.com/colmap/colmap/releases/tag/3.9.1

下载完成需要添加环境变量例如

然后就可以在终端打开

4.安装ffmpeg

Builds - CODEX FFMPEG @ gyan.dev

下载完成之后解压,同样加入环境变量

5.安装miniconda

Miniconda — Anaconda resource)

安装完成之后进入目录

C:\AI\gaussian-splatting

运行

复制代码
 # 安装环境&激活

    
 conda create -n gaussian_splatting python=3.8
    
 conda activate gaussian_splatting
    
  
    
 # 然后再安装两个子模块,以及其他包
    
 pip install submodules/diff-gaussian-rasterization
    
 pip install submodules/simple-knn
    
 pip install plyfile tqdm

安装pytorch

使用conda安装更稳定

复制代码
    conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia

二、开始训练

首先,在Gaussian Splatting源码目录中进行操作。随后,在该目录下新建一个data文件夹,并将准备好的input.MP4视频放置其中。在此处的视频文件名指定为input.MP4。

通过FFmpeg提取视频帧并生成图片文件至data目录下的input子目录中,请参考以下代码段以实现操作:

具体步骤如下:

  1. 打开命令行界面并执行FFmpeg提取视频帧的操作
  2. 指定输出文件路径位于data根目录下的input子目录
  3. 使用预设参数配置截取特定帧数
  4. 生成的图片将被系统自动保存到指定位置
  5. 可根据需求调整参数设置以优化输出效果
复制代码
    ffmpeg -i input.mp4 -vf "setpts=0.5*PTS" input/input_%4d.jpg

在源码目录中运行convert.py文件以生成点云数据;该操作实际上是利用colmap工具完成的;因此必须先安装colmap软件;运行完成后位于data文件夹中的目录结构如下所示:

复制代码
     python convert.py -s data

4.开始训练,接下来等待训练完即可:

复制代码
    python train.py -s data -m data/output

使用经验/注意事项:

1.运行ffmpeg之后目录如下

执行python convert.py -s数据命令后, 通过colmap工具将图像转换为点云后生成的文件目录如下

3.查看生成的点云

里面有两个文件夹可以依次查看

文件夹0的内容

文件夹1的内容

可以看到第一个建出来的点云不行

查看代码

复制代码
 # Copyright (C) 2023, Inria

    
 # GRAPHDECO research group, https://team.inria.fr/graphdeco
    
 # All rights reserved.
    
 #
    
 # This software is free for non-commercial, research and evaluation use
    
 # under the terms of the LICENSE.md file.
    
 #
    
 # For inquiries contact  george.drettakis@inria.fr
    
 #
    
  
    
 import os
    
 import logging
    
 from argparse import ArgumentParser
    
 import shutil
    
  
    
 # 创建一个命令行参数解析器
    
 parser = ArgumentParser("Colmap converter")
    
 parser.add_argument("--no_gpu", action='store_true')  # 不使用GPU
    
 parser.add_argument("--skip_matching", action='store_true')  # 跳过特征匹配步骤
    
 parser.add_argument("--source_path", "-s", required=True, type=str)  # 数据集的源路径
    
 parser.add_argument("--camera", default="OPENCV", type=str)  # 相机模型,默认为OPENCV
    
 parser.add_argument("--colmap_executable", default="", type=str)  # Colmap可执行文件的路径
    
 parser.add_argument("--resize", action="store_true")  # 是否进行图像缩放
    
 parser.add_argument("--magick_executable", default="", type=str)  # ImageMagick可执行文件的路径
    
 args = parser.parse_args()
    
  
    
 # 设置Colmap和ImageMagick命令
    
 colmap_command = '"{}"'.format(args.colmap_executable) if len(args.colmap_executable) > 0 else "colmap"
    
 magick_command = '"{}"'.format(args.magick_executable) if len(args.magick_executable) > 0 else "magick"
    
 use_gpu = 1 if not args.no_gpu else 0  # 根据参数决定是否使用GPU
    
  
    
 # 如果不跳过特征匹配步骤
    
 if not args.skip_matching:
    
     # 创建必要的目录
    
     os.makedirs(args.source_path + "/distorted/sparse", exist_ok=True)
    
  
    
     # 特征提取命令
    
     feat_extracton_cmd = colmap_command + " feature_extractor " \
    
                                       "--database_path " + args.source_path + "/distorted/database.db \
    
     --image_path " + args.source_path + "/input \
    
     --ImageReader.single_camera 1 \
    
     --ImageReader.camera_model " + args.camera + " \
    
     --SiftExtraction.use_gpu " + str(use_gpu)
    
  
    
     # 运行特征提取命令
    
     exit_code = os.system(feat_extracton_cmd)
    
     if exit_code != 0:
    
     logging.error(f"Feature extraction failed with code {exit_code}. Exiting.")
    
     exit(exit_code)
    
  
    
     # 特征匹配命令
    
     feat_matching_cmd = colmap_command + " exhaustive_matcher \
    
     --database_path " + args.source_path + "/distorted/database.db \
    
     --SiftMatching.use_gpu " + str(use_gpu)
    
  
    
     # 运行特征匹配命令
    
     exit_code = os.system(feat_matching_cmd)
    
     if exit_code != 0:
    
     logging.error(f"Feature matching failed with code {exit_code}. Exiting.")
    
     exit(exit_code)
    
  
    
     # 捆绑调整(Bundle adjustment)命令
    
     mapper_cmd = (colmap_command + " mapper \
    
     --database_path " + args.source_path + "/distorted/database.db \
    
     --image_path " + args.source_path + "/input \
    
     --output_path " + args.source_path + "/distorted/sparse \
    
     --Mapper.ba_global_function_tolerance=0.000001")
    
  
    
     # 运行捆绑调整命令
    
     exit_code = os.system(mapper_cmd)
    
     if exit_code != 0:
    
     logging.error(f"Mapper failed with code {exit_code}. Exiting.")
    
     exit(exit_code)
    
  
    
 # 图像去畸变命令
    
 img_undist_cmd = (colmap_command + " image_undistorter \
    
     --image_path " + args.source_path + "/input \
    
     --input_path " + args.source_path + "/distorted/sparse/1 \
    
     --output_path " + args.source_path + "\
    
     --output_type COLMAP")
    
  
    
 # 运行图像去畸变命令
    
 exit_code = os.system(img_undist_cmd)
    
 if exit_code != 0:
    
     logging.error(f"Mapper failed with code {exit_code}. Exiting.")
    
     exit(exit_code)
    
  
    
 # 获取稀疏点云文件列表并移动到目标目录
    
 files = os.listdir(args.source_path + "/sparse")
    
 os.makedirs(args.source_path + "/sparse/0", exist_ok=True)
    
 for file in files:
    
     if file == '0':
    
     continue
    
     source_file = os.path.join(args.source_path, "sparse", file)
    
     destination_file = os.path.join(args.source_path, "sparse", "0", file)
    
     print("args.source_path=",args.source_path)
    
     print("source_file=", source_file)
    
     print("destination_file=", destination_file)
    
     shutil.move(source_file, destination_file)
    
  
    
 # 如果指定了图像缩放参数
    
 if (args.resize):
    
     print("Copying and resizing...")
    
  
    
     # 创建缩放后图像的目录
    
     os.makedirs(args.source_path + "/images_2", exist_ok=True)
    
     os.makedirs(args.source_path + "/images_4", exist_ok=True)
    
     os.makedirs(args.source_path + "/images_8", exist_ok=True)
    
  
    
     # 获取源图像文件列表
    
     files = os.listdir(args.source_path + "/images")
    
  
    
     # 复制和缩放图像文件
    
     for file in files:
    
     source_file = os.path.join(args.source_path, "images", file)
    
  
    
     destination_file = os.path.join(args.source_path, "images_2", file)
    
     shutil.copy2(source_file, destination_file)
    
     exit_code = os.system(magick_command + " mogrify -resize 50% " + destination_file)
    
     if exit_code != 0:
    
         logging.error(f"50% resize failed with code {exit_code}. Exiting.")
    
         exit(exit_code)
    
  
    
     destination_file = os.path.join(args.source_path, "images_4", file)
    
     shutil.copy2(source_file, destination_file)
    
     exit_code = os.system(magick_command + " mogrify -resize 25% " + destination_file)
    
     if exit_code != 0:
    
         logging.error(f"25% resize failed with code {exit_code}. Exiting.")
    
         exit(exit_code)
    
  
    
     destination_file = os.path.join(args.source_path, "images_8", file)
    
     shutil.copy2(source_file, destination_file)
    
     exit_code = os.system(magick_command + " mogrify -resize 12.5% " + destination_file)
    
     if exit_code != 0:
    
         logging.error(f"12.5% resize failed with code {exit_code}. Exiting.")
    
         exit(exit_code)
    
  
    
 print("Done.")

全部评论 (0)

还没有任何评论哟~