Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit 6f6f08c

Browse files
committed
parseImage.py fix metadata Autel parse
1 parent 35b86f5 commit 6f6f08c

File tree

1 file changed

+55
-15
lines changed

1 file changed

+55
-15
lines changed

src/parseImage.py

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,8 @@ def handleAUTEL(xmp_str, exifData):
492492
# print("\n")
493493
# print(exifData)
494494

495-
elements = ["rdf:about="]
496-
metadataAbout = xmp_parse(xmp_str, elements)
497-
metadataAbout = metadataAbout["rdf:about="]
495+
metadataAbout = xmp_str.find("rdf:about=") + len("rdf:about=")
496+
metadataAbout = xmp_str[metadataAbout : metadataAbout + 15]
498497
metadataAbout = metadataAbout.split(' ')[0]
499498
metadataAbout = metadataAbout.upper()
500499

@@ -521,7 +520,7 @@ def handleAUTEL(xmp_str, exifData):
521520
# Older firmware versions use proprietary Autel Robotics XMP tags
522521
# If the metadata rdf:about is not "Autel Robotics Meta Data"
523522
# then this software can't parse metadata, so throw an error
524-
if metadataAbout != "AUTEL":
523+
if not "AUTEL" in metadataAbout:
525524
errstr = f"ERROR: unexpected metadata format while parsing Autel image: '{metadataAbout}'"
526525
print(errstr, file=sys.stderr)
527526
return None
@@ -535,18 +534,59 @@ def handleAUTEL(xmp_str, exifData):
535534
"Camera:Yaw=",
536535
"Camera:Roll="]
537536

538-
dirDict = xmp_parse(xmp_str, elements)
539-
# I've noticed this can be inaccurate sometimes
540-
# poor calibration of magnetometer for compass heading?
541-
azimuth = float(dirDict["Camera:Yaw="])
537+
canary = xmp_str.find("Camera:Pitch=")
538+
# print(f'canary: {canary}')
542539

543-
theta = float(dirDict["Camera:Pitch="])
544-
# AUTEL (old firmware) Camera pitch 0 is down, 90 is forward towards horizon
545-
# so, we use its complement instead
546-
theta = 90.0 - theta
540+
if canary != -1:
541+
dirDict = xmp_parse(xmp_str, elements)
542+
# I've noticed this can be inaccurate sometimes
543+
# poor calibration of magnetometer for compass heading?
544+
azimuth = dirDict["Camera:Yaw="]
547545

548-
if theta < 0:
549-
return None
546+
theta = dirDict["Camera:Pitch="]
547+
try:
548+
theta = float(theta)
549+
# AUTEL (old firmware) Camera pitch 0 is down, 90 is forward towards horizon
550+
# so, we use its complement instead
551+
theta = 90.0 - theta
552+
azimuth = float(azimuth)
553+
except ValueError:
554+
errstr = f"ERROR: parsing Autel image "
555+
errstr += f"with values theta: {theta} azimuth: {azimuth}"
556+
print(errstr, file=sys.stderr)
557+
return None
558+
559+
if theta < 0:
560+
return None
561+
else:
562+
# replace "<" open tag character with ">" close tag character
563+
# this way we can use the same character for splitting up the string
564+
searchspace = xmp_str.replace('<','>')
565+
566+
theta = searchspace.find("Camera:Pitch")
567+
if theta == -1:
568+
return None
569+
substr = searchspace[theta :]
570+
theta = substr.split('>', 3)[1]
571+
572+
azimuth = searchspace.find("Camera:Yaw")
573+
if azimuth == -1:
574+
return None
575+
substr = searchspace[azimuth :]
576+
azimuth = substr.split('>', 3)[1]
577+
try:
578+
theta = abs(float(theta))
579+
# AUTEL (old firmware) Camera pitch 0 is down, 90 is forward towards horizon
580+
# so, we use its complement instead
581+
theta = 90 - theta
582+
azimuth = float(azimuth)
583+
except ValueError:
584+
errstr = f"ERROR: parsing Autel image "
585+
errstr += f"with values theta: {theta} azimuth: {azimuth}"
586+
print(errstr, file=sys.stderr)
587+
return None
588+
if theta < 0:
589+
return None
550590

551591
if y is None or x is None or z is None or azimuth is None or theta is None:
552592
return None
@@ -604,7 +644,7 @@ def handlePARROT(xmp_str, exifData):
604644
theta = float(theta)
605645
azimuth = float(azimuth)
606646
except ValueError:
607-
errstr = f"ERROR: parsing Parrot image"
647+
errstr = f"ERROR: parsing Parrot image "
608648
errstr += f"with values theta: {theta} azimuth: {azimuth}"
609649
print(errstr, file=sys.stderr)
610650
return None

0 commit comments

Comments
 (0)