mapillary / mapillary/OpenSfM

Fix: Arbitrary focal plane and length conversion to 35 mm film focal length

Open
#599 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

sfm-reconstruction
Dominant language
Python
Stars
3.8k
Forks
899
PR merge metrics
No merged PRs in 30d

Description

https://github.com/mapillary/OpenSfM/blob/2005aae849ae5c43e781c2ae8ced1d550e36675e/opensfm/exif.py#L63-L64

Apparently, OpenSfM assumes or works with 35 mm film focal length internally (I was not aware of that), which is not great but okay. Anyhow, the current conversion from an arbitrary focal plane and length to full-frame/35 mm film focal length is incomplete, to say the least. So, you get things like this.

To fix this we have to compute the true equivalent focal length in 35 mm film:

focalLengthIn35mmFilm = focalLength /
    sqrt(focalPlaneWidth^2 + focalPlaneHeight^2) *
    sqrt(36.0^2 + 24.0^2)

We have to convert to 35 mm film via the focal plane’s hypotenuse because we have to take into account all the different aspect ratios which are out there.

Besides, I would also prefer evaluating FocalLength, FocalPlaneXResolution, FocalPlaneYResolution first before evaluating FocalLengthIn35mmFilm because FocalLengthIn35mmFilm is just a lazy imprecise equivalent of the true focal length; it is an integer value of type Short in the Exif metadata header. Exactly for that reason the fully precise FocalLength, FocalPlaneXResolution, FocalPlaneYResolution (and FocalPlaneResolutionUnit) Exif tags have been introduced after FocalLengthIn35mmFilm has been found or deemed unfit for many purposes. The amount of deviation caused by FocalLengthIn35mmFilm’s imprecision does not seem like much on a per image basis but it accumulates rapidly over many images (like OpenSfM is used). Note, that it is still okay for OpenSfM to use the 35 mm film focal length internally because we can compute fractions of millimeters in the metadata extraction step.

@paulinus Do you want me to create a PR or would you like to add a quick fix?

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

Read opensfm/exif.py at the referenced lines and trace how FocalLength, focal-plane dimensions, resolution units, and FocalLengthIn35mmFilm are evaluated. The work is done when the metadata extraction uses the precise focal-plane values for the 35 mm conversion, including aspect ratio, and no longer relies on the imprecise integer tag first.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-vision
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.