Help with camera distortion correction.

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Help with camera distortion correction.

Post by fmw42 »

I would not use the floor, since there is perspective distortion, since the floor is not perpendicular to the camera look direction. I would recommend that you paste a printed grid on the wall and photograph that face-on filling the frame for best calibration. Or buy a pegboard and use the holes for the grid. Put the pegboard directly on the wall and photograph that straight-on (no tilt) filling the frame.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Help with camera distortion correction.

Post by snibgo »

Photographing an interior wall, flat-on to that wall, in a rectangular room, is easy:

1. Put camera on a tripod, pointing towards the wall.
2. Measure the height of the centre-line of the lens above the floor.
3. Measure the horizontal distance from the centre-line of the lens to the wall on the left (or right).
4. Walk to the other end of the room, where the camera is pointing.
5. Put a mark on the wall at the same height, and same distance from the wall on the left (or right).
6. Adjust the camera angles to put the mark in the centre of the viewfinder.
DanielB wrote:For the correction I used A, B and C in Hugin, but not D. Do you think that using D could improve the correction?
Is your corrected image from Hugin or IM? If IM, what was the command?
snibgo's IM pages: im.snibgo.com
DanielB
Posts: 12
Joined: 2016-05-18T05:50:38-07:00
Authentication code: 1151

Re: Help with camera distortion correction.

Post by DanielB »

Hi, snibgo.
snibgo wrote:Photographing an interior wall, flat-on to that wall, in a rectangular room, is easy:

1. Put camera on a tripod, pointing towards the wall.
2. Measure the height of the centre-line of the lens above the floor.
3. Measure the horizontal distance from the centre-line of the lens to the wall on the left (or right).
4. Walk to the other end of the room, where the camera is pointing.
5. Put a mark on the wall at the same height, and same distance from the wall on the left (or right).
6. Adjust the camera angles to put the mark in the centre of the viewfinder.
Thank you for diagramming of these steps. Sorry, but I'm not sure I understand what you mentioned in paragraphs 3 and 5. When you say "measure the horizontal distance from the centre-line of the lens to the wall on the left (or right)", do you mean to measuring the horizontal distance between the vertical axis passing through the lens and the wall on the left (or right) of the camera, then carry that distance at the same height of the horizontal axis of the camera on the wall to which the camera is pointed, and then to position the camera so that "cross" stays in the center of the viewfilder? If I understood correctly, then I would have to make sure that distance is measured with an instrument which ensure horizontality and perpendicularity with respect to the side wall.
snibgo wrote:
DanielB wrote:For the correction I used A, B and C in Hugin, but not D. Do you think that using D could improve the correction?
Is your corrected image from Hugin or IM? If IM, what was the command?
I calculated the values of "a", "b" and "c" using Hugin. The values obtained were: a = -0.026, b = 0.02, and c = 0.001 Then I used the following syntax with ImageMagic:

Code: Select all

$ convert 20160523_131515-rotated -distort barrel.jpg "-0.026 0.02 0.001" 20160523_131515-rotated-processed.jpg
This is the procedure I have been always using.

A side question: when loading the image in Hugin, it asks for focal length but I'm not sure what value should be used here or if this value influences the result of the transformation. I have examined the EXIF metadata of the photo (taken using uvccapture 0.5-3+b1 on Debian GNU/Linux), but I did not find anything there regarding the focal length.

Thanks for your reply and your time.

Kind regards,
Daniel
DanielB
Posts: 12
Joined: 2016-05-18T05:50:38-07:00
Authentication code: 1151

Re: Help with camera distortion correction.

Post by DanielB »

Hi, Fred.
fmw42 wrote:I would not use the floor, since there is perspective distortion, since the floor is not perpendicular to the camera look direction.
As the lines appear curved on the floor, I thought it might also be a distortion of the camera.
fmw42 wrote: I would recommend that you paste a printed grid on the wall and photograph that face-on filling the frame for best calibration. Or buy a pegboard and use the holes for the grid. Put the pegboard directly on the wall and photograph that straight-on (no tilt) filling the frame.
I'll see if I can do something like that. Thank you for the recommendations.

Thanks for your reply.

Kind regards,
Daniel
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Help with camera distortion correction.

Post by snibgo »

DanielB wrote:... do you mean ...
Yes. No fancy tools are needed, just a tape measure or even just a piece of string.
DanielB wrote:...an instrument which ensure horizontality and perpendicularity with respect to the side wall.
That would give the most accurate results. If you have such an instrument, you can also check that the walls really are vertical, the floor and ceiling are horizontal, the edges between them are straight, and so on.

This also assumes that the central axis of the lens passes through the centre of the imaging sensor. These are the X,Y coordinates in "-distort barrel".
From memory, if you don't tell Hugin the focal length (or what it would be if your camera was 35mm), it will be calculated. See the Hugin docs.
snibgo's IM pages: im.snibgo.com
Post Reply