mapillary / mapillary/OpenSfM

[QUESTION] Project shots over flat plane.

Open
#760 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted question
Dominant language
Python
Stars
3.8k
Forks
899
PR merge metrics
No merged PRs in 30d

Description

Hello, and thank you for the project and your efforts on this project. 🙂

I would like to know if you could, please, throw some light to how to project all the images over a plane. More precisely I have some drone pictures taken at high altitude (no perspective affected) and I would like to put them all together like it can be seen in the viewer. I'm setting the use_altitude_tag to True in the config during the reconstruction.

image

My code so far is:

project_path = </path/to/project>
data = DataSet(project_path)

rec: Reconstruction = data.load_reconstruction()[0]
ref: TopocentricConverter = rec.reference

# Plane will be created at the mean altitude (z position) of 3D points
points = rec.get_points().values()
plane_altitude: LandmarkView = np.median([p.coordinates[2] for p in points])

for shot_id in rec.get_shots():
    
    shot: Shot = rec.shots[shot_id]
    cam: Camera = shot.camera
    pose: Pose = shot.pose

   # Scale

    x,y,z = pose.get_origin()
    z_scale = z - plane_altitude

   # Rotation

    # I think the main problem is here (?):
    # I ignore the Z axis because I suppose shot is "almost" facing down
    rot_matrix = pose.get_rotation_matrix()[:2,:2].T
    rot_matrix /= z_scale   # Set scale at floor level so images have correct size (is it correct?)

    # Translation

    x,y,z = ref.to_lla(x,y,z)  # Convert to GPS coordinates
    
    # Internal camera parameters

    K = cam.get_K()

    # Create affine to georeference image

    affine = np.eye(3)
    affine[:2,:2] = rot_matrix  # Insert rotation and scale
    affine[:2,2] = np.array((x,y))  # Insert translation
    
    K_inv = np.linalg.inv(K) 
    affine = affine.dot(K_inv)  # Add K to image

    ## Follows the code to insert Affine into TIF ##

Is this approximation correct? Once this is solved I would really like to help improving OpenSFM docs.
Thank you in advance.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the DataSet, Reconstruction, TopocentricConverter, Shot, Camera, and Pose APIs used in the example, focusing on how shot poses and camera parameters relate to projection onto a plane. Confirm the supported approach and document the required transformation steps, assumptions, and limitations so a user can reproduce the result from the reconstruction.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-vision
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.