|
36 | 36 | from PIL import Image |
37 | 37 | from PIL import ExifTags |
38 | 38 |
|
39 | | -# XML |
40 | | -# read-only |
41 | | -import xml.sax as sax |
42 | 39 | # write and mangle |
43 | | -# tutorialspoint.com/xml-parsing-in-python |
44 | | -import xml.etree.ElementTree as ET |
| 40 | +# eli.thegreenplace.net/2012/03/15/processing-xml-in-python-with-elementtree |
| 41 | +# try: |
| 42 | +# import xml.etree.cElementTree as ET # C implementation, much faster |
| 43 | +# except ImportError: |
| 44 | +# import xml.etree.ElementTree as ET |
| 45 | + |
45 | 46 |
|
46 | 47 |
|
47 | 48 | # unused :( |
@@ -116,7 +117,7 @@ def parseImage(): |
116 | 117 |
|
117 | 118 | sensData = None, None, None, None, None |
118 | 119 | target = None |
119 | | - try: |
| 120 | + if True: |
120 | 121 | #from stackoverflow.com/a/14637315 |
121 | 122 | # if XMP in image is spread in multiple pieces, this |
122 | 123 | # approach will fail to extract data in all |
@@ -156,32 +157,26 @@ def parseImage(): |
156 | 157 | print(f'skipping {thisImage}', file=sys.stderr) |
157 | 158 | continue |
158 | 159 | elif make == "SKYDIO": |
159 | | - print(f'ERROR with {thisImage}, Mfr. \'{make}\' not compatible with this program', file=sys.stderr) |
160 | | - print(f'skipping {thisImage}', file=sys.stderr) |
161 | | - # sensData = handleSKYDIO(xmp_str) |
162 | | - # if sensData is not None: |
163 | | - # y, x, z, azimuth, theta = sensData |
164 | | - # target = resolveTarget(y, x, z, azimuth, theta, elevationData, xParams, yParams) |
165 | | - # else: |
166 | | - # print(f'ERROR with {thisImage}, couldn\'t find sensor data', file=sys.stderr) |
167 | | - # print(f'skipping {thisImage}', file=sys.stderr) |
168 | | - # continue |
| 160 | + sensData = handleSKYDIO(xmp_str) |
| 161 | + if sensData is not None: |
| 162 | + y, x, z, azimuth, theta = sensData |
| 163 | + target = resolveTarget(y, x, z, azimuth, theta, elevationData, xParams, yParams) |
| 164 | + else: |
| 165 | + print(f'ERROR with {thisImage}, couldn\'t find sensor data', file=sys.stderr) |
| 166 | + print(f'skipping {thisImage}', file=sys.stderr) |
| 167 | + continue |
169 | 168 | elif False: # your drone make here |
170 | 169 | # <----YOUR HANDLER FUNCTION HERE----> |
171 | 170 | pass |
172 | 171 | elif False: # your drone make here |
173 | 172 | # <----YOUR HANDLER FUNCTION HERE----> |
174 | 173 | pass |
175 | 174 | else: |
176 | | - print(f'ERROR with {thisImage}, Mfr. \'{make}\' not compatible with this program', file=sys.stderr) |
| 175 | + print(f'ERROR with {thisImage}, xmp data not found!', file=sys.stderr) |
177 | 176 | print(f'skipping {thisImage}', file=sys.stderr) |
178 | 177 | continue |
179 | | - else: |
180 | | - print(f'ERROR with {thisImage}, xmp data not found!', file=sys.stderr) |
181 | | - print(f'skipping {thisImage}', file=sys.stderr) |
182 | | - continue |
183 | 178 |
|
184 | | - except: |
| 179 | + else: |
185 | 180 | print(f'ERROR with filename {thisImage}, skipping...', file=sys.stderr) |
186 | 181 | continue |
187 | 182 | # |
@@ -293,28 +288,29 @@ def handleDJI( xmp_str ): |
293 | 288 | def handleSKYDIO( xmp_str ): |
294 | 289 | # Skydio has multiple frame of reference tags with same children |
295 | 290 | # (i.e. "Yaw", "Pitch", etc.) |
296 | | - # will need to parse as XML :( |
297 | | - elements = ["drone-skydio:AbsoluteAltitude=", |
298 | | - "drone-skydio:Latitude=", |
299 | | - "drone-skydio:Longitude=" |
300 | | - "drone-skydio:Yaw=" # name collision :( |
| 291 | + # will need to parse differently :( |
301 | 292 |
|
302 | | - ] |
303 | 293 |
|
| 294 | + element = "drone-skydio:CameraOrientationNED" |
| 295 | + values = xmp_str[xmp_str.find(element) + len(element) : xmp_str.find(element) + len(element) + 100] |
| 296 | + theta = float(values.split('\"')[3]) |
| 297 | + azimuth = float(values.split('\"')[5]) |
304 | 298 |
|
305 | | - dict = xmp_parse( xmp_str, elements) |
306 | | - if dict is None: |
307 | | - return None |
| 299 | + theta = abs(theta) |
308 | 300 |
|
309 | | - # print(xmp_str) |
| 301 | + elements = ["drone-skydio:Latitude=", |
| 302 | + "drone-skydio:Longitude=", |
| 303 | + "drone-skydio:AbsoluteAltitude="] |
| 304 | + gpsDict = xmp_parse( xmp_str, elements) |
310 | 305 |
|
311 | | - y = dict["drone-skydio:Latitude="] |
312 | | - x = dict["drone-skydio:Longitude="] |
313 | | - z = dict["drone-dji:AbsoluteAltitude="] |
| 306 | + y = gpsDict["drone-skydio:Latitude="] |
| 307 | + x = gpsDict["drone-skydio:Longitude="] |
| 308 | + z = gpsDict["drone-skydio:AbsoluteAltitude="] |
314 | 309 |
|
315 | | - # azimuth = dict[ |
316 | | - # theta = abs( |
317 | | - return None |
| 310 | + if y is None or x is None or z is None or azimuth is None or theta is None: |
| 311 | + return None |
| 312 | + else: |
| 313 | + return (y, x, z, azimuth, theta) |
318 | 314 |
|
319 | 315 | """takes a xmp metadata string and a list of keys |
320 | 316 | return a dictionary of key, value pairs |
|
0 commit comments