Simple Camera Models with NumPy and Matplotlib

Mario Larcher
Analytics Vidhya
Published in
12 min readMar 16, 2021

--

Photo by ShareGrid on Unsplash.

Introduction

The code presented in this article can be found here. I suggest you take a look at it and try to play around with it to fully assimilate the concepts that will be presented.

import matplotlib.pyplot as plt
import numpy as np

from camera_models import * # our package


DECIMALS = 2 # how many decimal places to use in print

Disclamer: The theory described in this article is almost entirely taken from the excellent book Multiple View Geometry in Computer Vision by Richard Hartley and Andrew Zisserman. This work is not intended to replace the explanations in the book, but only to present the minimum amount of theory needed so that it can be applied immediately thereafter.

The Pinhole Camera Model

Image by Bob Mellish, distributed under a CC BY-SA 3.0 license.

A pinhole camera is a camera with a pinhole aperture and no lens, it is considered the most specialised and simplest camera model. As can be seen from the image above, the image plane, also called the focal plane, is behind the projection centre called the camera centre (𝐂) or optical centre. In what follows, for the sake of simplicity, it is considered to be in front…

--

--

Mario Larcher
Analytics Vidhya

I like spaghetti code with 🍅. Currently Staff Applied Scientist in the Canva Image Generation team, formerly Head of Computer Vision at Enel Group.