Module: Gsplat::IO::Colmap
- Defined in:
- lib/gsplat/io/colmap.rb
Overview
COLMAP sparse reconstruction reader and camera conversion utilities.
Defined Under Namespace
Classes: Camera, Dataset, ImageRecord, Point3D
Constant Summary collapse
- MODELS =
Supported COLMAP numeric camera model IDs.
{ 0 => "SIMPLE_PINHOLE", 1 => "PINHOLE", 2 => "SIMPLE_RADIAL", 4 => "OPENCV" }.freeze
Class Method Summary collapse
-
.qvec_to_rotmat(qvec) ⇒ Object
Converts a COLMAP wxyz quaternion to a 3x3 world-to-camera rotation.
-
.read(path, data_factor: 1) ⇒ Object
Reads cameras, registered images, and points from a sparse model directory.
-
.read_cameras(path, data_factor: 1) ⇒ Hash{Integer=>Camera}
Reads and scales camera calibration records from a bin/txt file.
-
.read_images(path) ⇒ Hash{Integer=>ImageRecord}
Reads registered image poses from a bin/txt file.
-
.read_points3d(path) ⇒ Hash{Integer=>Point3D}
Reads sparse points from a bin/txt file.
Class Method Details
.qvec_to_rotmat(qvec) ⇒ Object
Converts a COLMAP wxyz quaternion to a 3x3 world-to-camera rotation.
78 79 80 81 |
# File 'lib/gsplat/io/colmap.rb', line 78 def qvec_to_rotmat(qvec) quaternion = Numo::DFloat.cast(qvec).reshape(1, 4) Math::Quaternion.to_rotmat(quaternion)[0, true, true].dup end |
.read(path, data_factor: 1) ⇒ Object
Reads cameras, registered images, and points from a sparse model directory.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/gsplat/io/colmap.rb', line 32 def read(path, data_factor: 1) directory = model_directory(path) extension = model_extension(directory) Dataset.new( cameras: read_cameras(File.join(directory, "cameras.#{extension}"), data_factor: data_factor), images: read_images(File.join(directory, "images.#{extension}")), points3d: read_points3d(File.join(directory, "points3D.#{extension}")), path: directory ) end |
.read_cameras(path, data_factor: 1) ⇒ Hash{Integer=>Camera}
Reads and scales camera calibration records from a bin/txt file.
48 49 50 51 |
# File 'lib/gsplat/io/colmap.rb', line 48 def read_cameras(path, data_factor: 1) validate_factor!(data_factor) raw_records(path, :cameras).transform_values { |record| camera_record(record, data_factor) } end |
.read_images(path) ⇒ Hash{Integer=>ImageRecord}
Reads registered image poses from a bin/txt file.
57 58 59 |
# File 'lib/gsplat/io/colmap.rb', line 57 def read_images(path) raw_records(path, :images).transform_values { |record| image_record(record) } end |
.read_points3d(path) ⇒ Hash{Integer=>Point3D}
Reads sparse points from a bin/txt file.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/gsplat/io/colmap.rb', line 65 def read_points3d(path) raw_records(path, :points3d).transform_values do |record| Point3D.new( id: record.fetch(:id), xyz: Numo::DFloat.cast(record.fetch(:xyz)), rgb: Numo::UInt8.cast(record.fetch(:rgb)), error: record.fetch(:error), track: record.fetch(:track).freeze ) end end |