1

I just started using Pix4D mapper and straight away ran into the problem that the flight data is in WGS 84 and the GCPs are in Gauss Krüger 3. The pix4d support suggested to

Transform the image geotags to the output coordinate system before importing them

(see this)

So I wrote a python script to do the job. But after converting WGS84 to GK3 I am unable to write the values into the exif of a new image.

import os, piexif, pyproj
from PIL import Image

img = Image.open(os.path.join(dirPath,fn))
exif_dict = piexif.load(img.info['exif'])

breite = exif_dict['GPS'][piexif.GPSIFD.GPSLatitude]
lange = exif_dict['GPS'][piexif.GPSIFD.GPSLongitude]

breite = breite[0][0] / breite[0][1] + breite[1][0] / (breite[1][1] * 60) + breite[2][0] / (breite[2][1] * 3600)
lange = lange[0][0] / lange[0][1] + lange[1][0] / (lange[1][1] * 60) + lange[2][0] / (lange[2][1] * 3600)
print(breite) #48.81368778730952
print(lange) #9.954511162420633
x, y = pyproj.transform(wgs84, gk3, lange, breite)
print(x) #3570178.732528623
print(y) #5408908.20172699
exif_dict['GPS'][piexif.GPSIFD.GPSLatitude] = (round(y,6) * 1000000, 1000000)
#exif_dict['GPS'][piexif.GPSIFD.GPSLongitude] = (round(x,6) * 1000000, 1000000)

exif_bytes = piexif.dump(exif_dict) #error here
img.save(os.path.join(outPath,fn), "jpeg", exif=exif_bytes)

I get UnboundLocalError: local variable 'new_value' referenced before assignment in the dump method.

The GPSInfo tag looks like {0: b'\x02\x03\x00\x00', 1: 'N', 2: ((48, 1), (48, 1), (3449322402, 70000000)), 3: 'E', 4: ((9, 1), (57, 1), (1136812930, 70000000)), 5: b'\x00', 6: (3659, 10)}

I am guessing I have to change the format but how or to what, I do not know.

  • Tried this way, exif_dict['GPS'][piexif.GPSIFD.GPSLatitude] = [ ( (int)(round(y,6) * 1000000), 1000000 ), (0, 1), (0, 1) ] but to no avail. Getting struct.error: argument out of range in dump. – Avishek Dutta Jan 11 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.