kopia lustrzana https://github.com/OpenDroneMap/ODM
Fixed srt parser
rodzic
2e362c2238
commit
a74337f8fe
|
@ -1,4 +1,4 @@
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
import re
|
import re
|
||||||
class SrtFileParser:
|
class SrtFileParser:
|
||||||
def __init__(self, filename, utc_offset):
|
def __init__(self, filename, utc_offset):
|
||||||
|
@ -10,11 +10,15 @@ class SrtFileParser:
|
||||||
if not self.data:
|
if not self.data:
|
||||||
self.parse()
|
self.parse()
|
||||||
|
|
||||||
|
# check min and max
|
||||||
|
if timestamp < self.min or timestamp > self.max:
|
||||||
|
return None
|
||||||
|
|
||||||
for entry in self.data:
|
for entry in self.data:
|
||||||
if entry["timestamp"] <= timestamp:
|
if entry["timestamp"] <= timestamp:
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
return None
|
return self.data[len(self.data) - 1]
|
||||||
|
|
||||||
def parse(self):
|
def parse(self):
|
||||||
|
|
||||||
|
@ -26,6 +30,9 @@ class SrtFileParser:
|
||||||
# 2023-01-06 18:56:48,380,821
|
# 2023-01-06 18:56:48,380,821
|
||||||
# [iso : 3200] [shutter : 1/60.0] [fnum : 280] [ev : 0] [ct : 3925] [color_md : default] [focal_len : 240] [latitude: 0.000000] [longitude: 0.000000] [altitude: 0.000000] </font>
|
# [iso : 3200] [shutter : 1/60.0] [fnum : 280] [ev : 0] [ct : 3925] [color_md : default] [focal_len : 240] [latitude: 0.000000] [longitude: 0.000000] [altitude: 0.000000] </font>
|
||||||
|
|
||||||
|
self.min = datetime.max
|
||||||
|
self.max = datetime.min
|
||||||
|
|
||||||
with open(self.filename, 'r') as f:
|
with open(self.filename, 'r') as f:
|
||||||
|
|
||||||
for line in f:
|
for line in f:
|
||||||
|
@ -48,6 +55,10 @@ class SrtFileParser:
|
||||||
"longitude": longitude,
|
"longitude": longitude,
|
||||||
"altitude": altitude
|
"altitude": altitude
|
||||||
})
|
})
|
||||||
|
self.min = min(self.min, timestamp)
|
||||||
|
# account for the difftime milliseconds to get the actual max
|
||||||
|
self.max = max(self.max, timestamp + timedelta(milliseconds=difftime))
|
||||||
|
|
||||||
srtcnt = None
|
srtcnt = None
|
||||||
difftime = None
|
difftime = None
|
||||||
timestamp = None
|
timestamp = None
|
||||||
|
@ -112,13 +123,20 @@ class SrtFileParser:
|
||||||
match = re.search("latitude: (\d+.\d+)", line)
|
match = re.search("latitude: (\d+.\d+)", line)
|
||||||
if match:
|
if match:
|
||||||
latitude = float(match.group(1))
|
latitude = float(match.group(1))
|
||||||
|
latitude = latitude if latitude != 0 else None
|
||||||
|
|
||||||
match = re.search("longitude: (\d+.\d+)", line)
|
match = re.search("longitude: (\d+.\d+)", line)
|
||||||
if match:
|
if match:
|
||||||
longitude = float(match.group(1))
|
longitude = float(match.group(1))
|
||||||
|
longitude = longitude if longitude != 0 else None
|
||||||
|
|
||||||
match = re.search("altitude: (\d+.\d+)", line)
|
match = re.search("altitude: (\d+.\d+)", line)
|
||||||
if match:
|
if match:
|
||||||
altitude = float(match.group(1))
|
altitude = float(match.group(1))
|
||||||
|
altitude = altitude if altitude != 0 else None
|
||||||
|
|
||||||
|
self.data.reverse()
|
||||||
|
|
||||||
|
self.max = self.max.replace(microsecond=0)
|
||||||
|
self.min = self.min.replace(microsecond=0)
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue