mapillary / OpenSfM

Open source Structure-from-Motion pipeline
https://www.opensfm.org/
BSD 2-Clause "Simplified" License
3.37k stars 856 forks source link

Meaning of reference frame. #841

Open QuickLearner171998 opened 2 years ago

QuickLearner171998 commented 2 years ago

Hi,

I was going through the reconstruction code and had some doubts regarding the reference coordinate frame.

Here https://github.com/mapillary/OpenSfM/blob/d087aa64159d18e919ac4c5bd25ab0d27b497fad/opensfm/reconstruction.py#L597 we set the reference in some world coordinate frame. And during bootsraping https://github.com/mapillary/OpenSfM/blob/d087aa64159d18e919ac4c5bd25ab0d27b497fad/opensfm/reconstruction.py#L640 we set the pose of the first frame as Identity and compute the pose of 2nd frame with respect to the first frame (if my understanding is correct). So this means the reference for each partial reconstruction should be the first frame and hence the pose of the first frame should not change. But during alignment and bundle adjustment the pose of the first frame also changes.

So I have two questions -

  1. Am I correct in assuming that the first frame of each partial reconstruction is a reference frame with respect to which all the poses in that reconstruction are calculated. If not can you please once explain meaning of reference frame?
  2. If I have some initial poses (in world coordinate frame) then how can I pass them in openSfm codebase maintaining the correct reference.

Thank You

YanNoun commented 2 years ago

Hi @QuickLearner171998 ,

1 - Periodically during reconstruction, we align the partial reconstruction that is being grown, to the world coordinate frame using align (see https://github.com/mapillary/OpenSfM/blob/main/opensfm/reconstruction.py#L1316). If you have GPS metadata, it will realign the partial reconstruction on them. 2 - The reference frame is a topocentric coordinate frame computed as the mean of all GPS metadata's lat/lon/alt, and oriented as East, North, Up (ENU). All OpenSfM world coordinates are wrt. this coordinate frame. 3 - If you have some poses in the world and have the corresponding lat/lon/alt, then you can overwrite them as EXIF gps using exif_overrides.json

In case, you're working in some arbitrary coordinate frame, then : 1 - align will do nothing and the reconstruction is in arbitrary coordinate system, with the first two reconstructed camera having a relative translation of scale 1 more-or-less. 2 - If you have some poses in some arbitrary coordinate frame, you can write them directly as a reconstruction object, dump it as JSON, and then use the extend reconstruction command(https://github.com/mapillary/OpenSfM/blob/7b455d9c424c82d96fc60d57a9c1dbf024aa8b3b/opensfm/commands/extend_reconstruction.py) if you want to add more images while keeping your poses fixed.

Let me know if that helps,

Yann