In order to set exposure times, you have to know the f number of the pinhole camera. This is calculated simply by dividing the focal length by the diameter of the hole. However, it is important to bear in mind that, during longer exposures, the time must be extended due to reciprocity failure (see Determining exposure times for pinhole cameras).

A piece of metal cut from a drinks can, approximately 4 x 4 cm, is sufficient. First, using coarse sandpaper, remove the paint from the area where the hole should be, and try to make the metal as thin as possible. Then finish the surface by using fine sandpaper. Place the plate on a flat wooden block and, using a sharp needle, make the smallest hole possible. Be careful not to injure your hand and use a hard block to press down on the needle. Remove the embossed material from the reverse side of the plate using fine sandpaper. Place the needle into the hole again and, by gently pressing and turning the needle between your fingers, make the hole round. Smooth the hole again using sandpaper. It is necessary to repeat the process until the required diameter is achieved. A regular round hole in a very thin plate can be made with a bit of patience.

We replace the pinhole by a lens thus increasing the size of the aperture through which light rays can pass. A lens allows larger number of rays to pass through the hole and because of its optical properties it can also focus them on the screen. This makes the image brighter.

To generate clear and sharp images the diameter of the aperture (hole) of a pinhole camera should be as small as possible. If we increase the size of the aperture, we know that rays from multiple points of the object would be incident on the same part of the screen creating a blurred image.

Distortion in imagesfree

It is important to note that sometimes in case of high radial distortions, using the getOptimalNewCameraMatrix() with alpha=0 generates a blank image. This usually happens because the method gets poor estimates for the distortion at the edges. In such cases you need to recalibrate the camera and ensure that more images are taken with different views close to image borders. This way more samples near image border would be available for estimating the distortion, thus improving the estimation.

LensdistortionExamples

Most probably, the first person to try to find a formula for calculating the optimum hole diameter was the famous mathematician and physicist Josef Petzval in the mid-19th century. It was later improved by the British Nobel Prize-Winner Lord Rayleigh. The equation, on which he worked for ten years and which is valid to this day, was published in his book Nature in 1891. Several more formulas have appeared since that time, often derived from the same base.

The distCoeffs matrix returned by the calibrateCamera method give us the values of K_1, to K_6, which represent the radial distortion and P_1 , P_2, which represent the tangential distortion. As we know that the above mathematical model representing the lens distortion, includes all the types of distortions, radial distortion, decentering distortion and thin prism distortion, thus the coefficients K_1 to K_6 represent the net radial distortion and P_1 and P_2 represent the net tangential distortion.

Imagedistortion inradiography

Great ! So in this series of posts on camera calibration we started with geometry of image formation , then we performed camera calibration and discussed the basic theory involved we also discussed the mathematical model of a pin hole camera and finally we discussed lens distortion in this post. With this understanding you can now create your own virtual camera and simulate some interesting effects using OpenCV and Numpy. You can refer to this repository where a a virtual camera is implemented using only Numpy computations. With all the parameters, intrinsic as well as extrinsic, in your hand you can get a better feeling of the effect each parameter of the camera has on the final image you see.

Pincushiondistortion

So what do we do after the calibration step ? We got the camera matrix and distortion coefficients in the previous post on camera calibration but how do we use the values ?

Empowering innovation through education, LearnOpenCV provides in-depth tutorials, code, and guides in AI, Computer Vision, and Deep Learning. Led by Dr. Satya Mallick, we're dedicated to nurturing a community keen on technology breakthroughs.

In a previous post, we went over the geometry of image formation and learned how a point in 3D gets projected on to the image plane of a camera.

Several companies sell precise holes of various diameters, normally made in high-grade materials using lasers (see links). However, anyone can make a good hole by themselves.

The primary influence on the technical quality of a photograph taken using a pinhole camera is obviously the hole. In order to achieve the sharpest photograph, the hole must be of the optimum size, perfectly round and should be made from the thinnest material. However, the truth is that the quality and size of the hole are not such critical parameters as one might think at first glance. Interesting pictures can be taken using almost any hole. Also, sharpness alone does not always have to be the most important requirement. Photographs from a pinhole camera are always a little less sharp and sometimes a certain amount of blur can, in itself, be an attractive means of expression.

Distortion in imagesexamples

One application is to use the derived distortion coefficients to un-distort the image. Images shown below depict the effect of lens distortion and how it can be removed from the coefficients obtained from camera calibration.

Distortion inimage processing

On the other hand, with a larger aperture, the image sensor receives more photons ( and hence more signal ). This leads to a bright image with only a small amount of noise.

Have you ever wondered why we attach a lens to our cameras? Does it affect the transformation defining the projection of a 3D points to a corresponding pixel in an image? If yes, how do we model it mathematically?

We mathematically model the distortion effect based on the lens properties and combine it with the pinhole camera model that is explained in the previous post of this series. So along with intrinsic and extrinsic parameters discussed in the previous post, we also have distortion coefficients (which mathematically represent the lens distortion), as additional intrinsic parameters.

There are several other parameters which you can change using the GUI provided in the repository. It will help you to have a better intuition about effect of various camera parameters.

Distortion in imagesonline

Now we have a better idea of what types of distortion effects are introduced by a lens, but what does a distorted image look like ? Do we need to worry about the distortion introduced by the lens ? If yes why ? How do we deal with it ?

So, smaller the aperture of the pinhole camera, more focused is the image but, at the same time, darker and noisier it is.

Imagedistortionmeaning

The above figure is an example of distortion effect that a lens can introduce. You can relate figure 3 with figure 1 and say that it is a barrel distortion effect, a type of radial distortion effect. Now if you were asked to find the height of the right door, which two points would you consider ? Things become even more difficult when you are performing SLAM or making some augmented reality application with cameras having high distortion effect in the image.

The second step is performed using the getOptimalNewCameraMatrix() method. What does this refined matrix mean and why do we need it ? Refer to the following images, in the right image we see some black pixels near the edges. These occur due to undistortion of the image. Sometimes these black pixels are not desired in the final undistorted image. Thus getOptimalNewCameraMatrix() method returns a refined camera matrix and also the ROI(region of interest) which can be used to crop the image such that all the black pixels are excluded. The percentage of unwanted pixels to be eliminated is controlled by a parameter alpha which is passed as an argument to the getOptimalNewCameraMatrix() method.

There are several ways to measure a hole like this. The simplest is to use a magnifying glass and ruler. However, a more accurate method is to use an enlarger. Place the hole plate and a transparent ruler in the film holder and project the image onto white paper. The greater the enlargement, the greater the accuracy of the measurement. A simple calculation will give you the scale of enlargement and, from that, the size of the hole. The following example illustrates this method: The projected image length of 6 cm of the actual ruler is 60 cm. 60/6 = 10, therefore the image is 10 times greater. The size of the projected hole image is 3 mm, 3/10 = 0.3, hence the actual diameter of the hole is 0.3 millimetres.

Based on [1] there are 3 types of distortion depending on the source of distortion, radial distortion, decentering distortion and thin prism distortion. The decentering and thin prism distortion have both, radial and tangential distortion effect.

The principle of the pinhole camera ensures that the image of a point is, in fact, a small disc. The smaller the hole, the smaller the disc and hence the sharper the image. However, this is only true up to a point. If the hole is too small, then light is diffracted and the image becomes less sharp. Hence, an optimum hole diameter exists for each focal length (distance from the hole to the light-sensitive material) which will create the sharpest picture.

[1] J. Weng, P. Cohen, and M. Herniou. Camera calibration with distortion models and accuracy evaluation. IEEE Transactions on Pattern Analysis and Machine Intelligence, 14(10):965–980, Oct. 1992.

To make the calculation of the optimum hole diameter or the optimum focal length easier, you can use the PinholeDesigner program.

By using a lens we get better quality images but the lens introduces some distortion effects. There are two major types of distortion effects :

On the other hand, if we make the aperture size small, only a small number of photons hit the image sensor. As a result the image is dark and noisy.

The formula proposed by Lord Rayleigh, revised so that the result gives the diameter, not the radius, can be written as follows:

The model we used was based on the pinhole camera model. The only time you use a pinhole camera is probably during an eclipse.