verticalphotoplacer / VerticalPhotoPlacer

A free open source plugin for QGIS that performs quick placement of vertical drone photos on map.
GNU General Public License v3.0
28 stars 16 forks source link

A possible mathematical mistake in the method `createSingleWorldfile` in uav_georeference.py #10

Closed ufukcbicici closed 1 year ago

ufukcbicici commented 1 year ago

Hello,

While trying to understand how the world files are generated from the camera metadata directly, I came to inspect the algorithm in the method createSingleWorldfile. Basically, it consists of converting the sensor dimensions into longitude, latitude values, projecting them into the ground plane by using the sensor focal length and the estimated ground altitude and then applying rotation such that the image is oriented towards the heading value. What I am not sure about is in the upper left coordinate calculation for the world file:

    # Computes upper left coordinates as required in Worldfile specification.
    hypotenuse_hlength_degrees = math.sqrt(img_hwidth_degrees * img_hwidth_degrees +
                                           img_hlength_degrees * img_hlength_degrees)
    invar_angle = math.degrees(math.atan(iw / ih))
    lat_angle = heading - invar_angle
    y_length = hypotenuse_hlength_degrees * math.cos(math.radians(lat_angle))
    x_length = hypotenuse_hlength_degrees * math.sin(math.radians(lat_angle))
    upper_left_lon = lon + x_length
    upper_left_lat = lat + y_length

My concern is in the line invar_angle = math.degrees(math.atan(iw / ih)). This angle, arctangent of the image width divided by the image height, is directly used for calculating the upper left coordinate, in longitude and latitude space. However we are using the image width and height in pixels for calculating the angle, which are in the original image space. I think we should use the arctangent between the image width and height in degrees like:

    invar_angle = math.degrees(math.atan(img_hwidth_degrees / img_hlength_degrees))

Am I missing something here or is there really a small glitch in the code?

devtrick03 commented 1 year ago

First off, phantastic plugin - exactly what I was searching for.

I also wondered why the image centres were not exactly aligned with the GPS coordinates. With the code changes above, the images definitely fit better. However, this does not seem to apply if the photos are strongly rotated (nearly 90 degree). But generally an absolute improvement.

chuc92man commented 1 year ago

that's correct! I updated the program and will update to the plugin hub.