Hi, snibgo.
snibgo wrote:If you tilt the camera up, in the photo the corners of the walls will remain straight but will tilt inwards. If you take a photo of a tall building from outside, tilting the camera up, the edges will tilt inwards. If you stand on a bridge over a railway and photograph it, the tracks will tilt together in the photo, converging at the horizon. These are all due to perspective. You can correct for this if you want with IM's "-distort perspective".
Very interesting observation! Thanks for sharing! I took again a photo of the same scene, but this time I tried to support the USB camera on a tripod trying to be as level as possible. This tripod has a horizontal level and a level relative to the angular inclination of the camera (forward or backward). The tripod also allows a radial tilt of the camera in the longitudinal direction, so I used it to place it vertically. To ensure the verticality, I used a set square.
Rotated image (-90 from photo took with tripod):
Rotated image processed:
As you can see, here the corner of the wooden wall to the left is much more aligned with the edge of the picture, suggesting that the camera would not be inclined upwards but leveled. Although I keep noticing that the floor appears to be inclined downward, toward the right (I'm not sure if it is bent). What do you think could be causing this?
Moreover, although the roof edge look more straight, it seems inclined upward. Do you think these two effects could be due to a problem of parallax of the camera?
On the other hand, it's interesting what you mention about using "-distort perspective". I was watching ImageMagick documentation, although I'm not sure what is the most efficient way to get the values to use for this.
snibgo wrote:
If real-life straight lines become curved, this is probably caused by barrel/pincushion distortion, which can be corrected with "-distort barrel". The Hugin toolset can give you the ABCD parameters.
Hugin allows to obtain the parameters A, B, C, D and E. Thank you for confirming in the other post that the values of D and E corresponds to the center of the distortion. Following the
reference mentioned in the original message, I only selected in Hugin the A, B and C parameters for calculation. Do you think I should also mark D and E?
In this case, reviewing the
documentation of ImageMagick, I see that it expects the following syntax for "-distortion barrel":
The optional X,Y arguments provide an optional 'center' for the radial distortion, otherwise it defaults to the exact center of the image given (regardless of its virtual offset). So in the case of using X and Y, should I use the following syntax with the values obtained from Hugin?
Code: Select all
$ convert input.jpg -distort barrel "A B C 0.0 D E" output.jpg
Because somehow I have to tell to
convert that I'm not providing the D parameter.
snibgo wrote:
For best results, you need to photograph something that has both vertical and horizontal straight lines. There should be at least 5 lines in each direction: one near each edge, one near the centre, and one each between the center and edge. More lines is better. You only need three points per line, but 5 or more is better.
Thanks for the recommendation! I'll see if I can find something like a brick wall or something similar that gives me a grid of reference.
snibgo wrote:
If the camera lens doesn't focus or zoom, this barrel/pincushion calibration only needs to be done once.
I think this USB camera does not allow zoom. Anyway the idea is to use it without zoom. However it has a mechanism of manual focus, when rotating the front in a circular manner. This here you say is interesting, since the intention is to have several of these USB cameras connected to Raspberries Pi. So I would have to ensure the focus is the same for all cameras to ensure the correction of the distortion is equally good in all of them. But the rotating drum does not have any reference mark enabling replicate the focus graduation. Any suggestions?
snibgo wrote:
When processing photos, you should correct barrel/pincushion distortion first, then perspective distortion.
Thank you for the advice! I'll keep that in mind. Although before I would see how to get the values for the perspective distortion correction.
Thank you very much for your time and reply. It gave me several things to think about.
Kind regards,
Daniel