오늘은 gaussian-splatting에 사용할 3D point cloud, Camera parameter(Intrinsic & Extrinsic)를 Colmap으로 생성하는 방법에 대해 알아보고자 한다.
일단 gaussian splatting에 3D point cloud와 Camera parameter가 필요한 이유는 초기 3D Gaussian(= 3D point cloud에 입체감과 깊이감을 추가한 형태)을 설정하기 위한 초기값에 해당하기 때문이다. 이후에 이러한 초기 3D gaussian을 점점 최적화해가면서 2D img상의 object를 3D의 object로 얻을 수 있게 된다.
따라서, Colmap에서 input에 해당하는 2D image의 3D point cloud, Camera parameter(Intrinsic & Extrinsic)를 더 잘 추정할수록 gaussian-splatting의 3D reconstruction 성능이 좋아질 수 밖에 없다.
Colmap을 사용하는 이유를 간단하게 알아봤으니, Colmap으로 어떻게 2D image를 이용해 3D point cloud와 Camera parameter를 구할 수 있는지 살펴보도록하자. 아래는 Colmap 응용 프로그램을 바로 다운받을 수 있는 사이트이다. 글쓴이는 가장 최신 윈도우 버전을 이용했다.( COLMAP-3.9.1-windows-cuda.zip )
https://github.com/colmap/colmap/releases
Releases · colmap/colmap
COLMAP - Structure-from-Motion and Multi-View Stereo - colmap/colmap
github.com
그리고 아래는 Colmap gui를 이용한 실습 영상이다. 글쓴이는 Command-line을 이용해서 실습을 진행했다.
https://www.youtube.com/watch?v=SC0V5aOEq14
Colmap gui를 이용해 camera parameter와 3D point cloud를 구하는게 매우 편하긴 하지만, Camera model 설정이나 추가적인 기능 설정을 해주기에 Command-line이 훨씬 직관적이라는 장점이 있다. 아래는 Command-line 사용법을 잘 정리해둔 문서이다.
https://colmap.github.io/cli.html
Command-line Interface — COLMAP 3.9-dev documentation
exhaustive_matcher, vocab_tree_matcher, sequential_matcher, spatial_matcher, transitive_matcher, matches_importer: Perform feature matching after performing feature extraction.
colmap.github.io
Command-line
그럼 이제부터 Command-line을 이용해 camera parameter와 3D point cloud를 얻어보자. 먼저 cmd를 이용해 Colmap이 존재하는 경로로 이동한다.
그리고 지금부터 2D img로부터 3D reconstruction하기 위해 총 아래 3단계를 거치고자 한다.
1. feature_extractor
위 명령어는 주어진 각 이미지의 특징점(Feature Points)을 추출할 때 사용한다.
--database_path: 추출된 특징점과 이미지간의 매칭 정보 등을 저장할 데이터베이스 파일의 경로이다. 초기 특성 추출 단계에서 생성된 정보부터 최종적인 3D 모델링 과정까지, 다양한 정보가 이 파일에 저장되고 참조된다.
--image_path: 특징점을 추출할 이미지가 포함된 폴더의 경로를 지정하는 명령어다.
--ImageReader.camera_model: 이미지를 해석할 때 사용해야 하는 카메라 모델의 유형을 알려주는 명령어다. (글쓴이는 blender에서 rendering한 이미지를 이용했기 때문에 camera model을 PINHOLE을 사용했다.)
colmap feature_extractor \
--database_path \Users\user\Desktop\colmap_data\output\database.db \
--image_path \Users\user\Desktop\colmap_data\images \
--ImageReader.camera_model PINHOLE
2. exhaustive_matcher
위 명령어는 내가 입력한 모든 이미지 쌍 사이에서 특징점 매칭을 수행할 때 사용한다.
exhaustive_matcher는 추출된 특징점 사이의 매칭을 찾아내서 각 이미지 쌍이 어떻게 서로 연관되어 있는지를 식별하며, 3D reconstruction에 필요한 정보를 제공한다.
--database_path: 데이터베이스 파일의 경로로, 특징점과 이미지간의 특징점 매칭 정보가 저장된 위치이다.
colmap exhaustive_matcher \
--database_path \Users\user\Desktop\colmap_data\output\database.db
3. mapper
위 명령어는 이미지 간의 매칭 정보를 사용해 3D point cloud를 생성하고, 최종 camera parameter(카메라 위치와 방향, intrinsic parameter)을 추정할 때 사용한다.
이 과정은 Sparse 3D reconstruction이라고 부르며, 결과는 상대적으로 적은 수의 3D point로 구성된다.
--database_path: 데이터베이스 파일의 경로로, 3D point cloud와 Camera parameter를 저장한다.
--image_path: input 이미지가 저장된 폴더의 경로이다.
--output_path: sparse 3D point cloud와 camera parameter를 저장할 폴더의 경로이다.
mkdir \Users\user\Desktop\colmap_data\output\sparse
colmap mapper \
--database_path \Users\user\Desktop\colmap_data\output\database.db \
--image_path \Users\user\Desktop\colmap_data\images \
--output_path \Users\user\Desktop\colmap_data\output\sparse
여기까지가 gaussian-splatting의 convert.py까지 끝낸 단계라고 볼 수 있다. 실제로 gaussian-splatting에서 train.py까지 했을 때 아래와 같은 결과가 나온다. 왜곡이 없는 PINHOLE model을 이용해서 그런지 point cloud도 잘 생성된 것 같고, 결과도 좋은 것 같다.
추가사항
gaussian-splatting은 사용자 computer에 이미 깔린 colmap을 이용하기 때문에 아래의 colmap help을 이용해서 최적의 camera parameter와 3D point cloud를 얻기 위한 함수들을 추가할 수 있다.
$ colmap help
Usage:
colmap [command] [options]
Documentation:
https://colmap.github.io/
Example usage:
colmap help [ -h, --help ]
colmap gui
colmap gui -h [ --help ]
colmap automatic_reconstructor -h [ --help ]
colmap automatic_reconstructor --image_path IMAGES --workspace_path WORKSPACE
colmap feature_extractor --image_path IMAGES --database_path DATABASE
colmap exhaustive_matcher --database_path DATABASE
colmap mapper --image_path IMAGES --database_path DATABASE --output_path MODEL
...
Available commands:
help
gui
automatic_reconstructor
bundle_adjuster
color_extractor
database_creator
delaunay_mesher
exhaustive_matcher
feature_extractor
feature_importer
image_deleter
image_rectifier
image_registrator
image_undistorter
mapper
matches_importer
model_aligner
model_analyzer
model_converter
model_merger
model_orientation_aligner
patch_match_stereo
point_triangulator
poisson_mesher
rig_bundle_adjuster
sequential_matcher
spatial_matcher
stereo_fusion
transitive_matcher
vocab_tree_builder
vocab_tree_matcher
vocab_tree_retriever
'실습 & 활동 > Computer vision' 카테고리의 다른 글
[WSL-Ubuntu] Pytorch & Pytorch3d & CUDA 버전 설치 (0) | 2024.04.23 |
---|---|
[Gaussian Splatting] Colmap vs. Correct camera parameter (0) | 2024.04.12 |
[Blender] Data file 한 번에 Import → Render (0) | 2024.03.26 |
[Objaverse] 데이터셋 다운로드 (0) | 2024.03.25 |
[PTAM] 실습 (0) | 2024.03.20 |