-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package colmap | ||
|
||
import ( | ||
"encoding/binary" | ||
"image/color" | ||
"os" | ||
|
||
"github.com/EliCDavis/bitlib" | ||
"github.com/EliCDavis/vector/vector3" | ||
) | ||
|
||
// Everything transcribed from | ||
// https://github.com/colmap/colmap/blob/main/scripts/python/read_write_model.py | ||
// https://docs.python.org/3/library/struct.html | ||
|
||
type Point3DTrack struct { | ||
ImageID int | ||
Point2DID int | ||
} | ||
|
||
type Point3D struct { | ||
ID uint64 | ||
Position vector3.Float64 | ||
Color color.RGBA | ||
Error float64 | ||
Tracks []Point3DTrack // as (IMAGE_ID, POINT2D_IDX) | ||
} | ||
|
||
func ReadPoints3DBinary(filename string) ([]Point3D, error) { | ||
f, err := os.Open(filename) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer f.Close() | ||
|
||
reader := bitlib.NewReader(f, binary.LittleEndian) | ||
|
||
numPoints := reader.UInt64() | ||
points := make([]Point3D, numPoints) | ||
|
||
for i := uint64(0); i < numPoints; i++ { | ||
p := Point3D{} | ||
|
||
p.ID = reader.UInt64() | ||
|
||
p.Position = vector3.New( | ||
reader.Float64(), | ||
reader.Float64(), | ||
reader.Float64(), | ||
) | ||
|
||
c := color.RGBA{A: 255} | ||
c.R = reader.Byte() | ||
c.G = reader.Byte() | ||
c.B = reader.Byte() | ||
p.Color = c | ||
|
||
p.Error = reader.Float64() | ||
|
||
numTracks := reader.UInt64() | ||
p.Tracks = make([]Point3DTrack, numTracks) | ||
for trackIndex := uint64(0); trackIndex < numTracks; trackIndex++ { | ||
track := Point3DTrack{} | ||
track.ImageID = int(reader.Int32()) | ||
track.Point2DID = int(reader.Int32()) | ||
p.Tracks[trackIndex] = track | ||
} | ||
|
||
points[i] = p | ||
} | ||
|
||
return points, reader.Error() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
module github.com/EliCDavis/sfm | ||
|
||
go 1.21.0 | ||
|
||
require ( | ||
github.com/EliCDavis/bitlib v1.0.0 | ||
github.com/EliCDavis/vector v1.5.0 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
github.com/EliCDavis/bitlib v1.0.0 h1:iMWUThiBzXnEQTAG3C5Mtjzfna8cpFhrmQylhWSJINM= | ||
github.com/EliCDavis/bitlib v1.0.0/go.mod h1:B/mBEBsbOKSL85ELpHDmN1ncf1gO14Nrum184HWHcPQ= | ||
github.com/EliCDavis/vector v1.5.0 h1:IE7Xco/V9S0inlIoIPu5J87Nnup9RJUEK/PiDLsueY8= | ||
github.com/EliCDavis/vector v1.5.0/go.mod h1:A+Zf8tDKfocwQa9md33HsE53KclL7uayR/cKjKHUFSA= |