-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
executable file
·85 lines (58 loc) · 2.62 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
import os
from typing import Callable
from gcposm import utils
from gcposm import model
from gcposm.gcp_url_parser import GCPURLParser, GeoLocationResolver, GeoLocationDecoder
from gcposm.gcp_list_writer import write_gcp_list_file
import argument_parser
import qr_code_extractor
def load_your_gcp_list(file):
gcp_list = []
if os.path.exists(file):
with open(file, 'r') as infile:
for line in infile:
gcp_list.append(line.split("*")[0].split(";"))
return gcp_list
def init_gcp_url_parser(lookup: Callable[[str], model.GeoLocation]):
geo_location_resolver = GeoLocationResolver(lookup)
geo_location_decoder = GeoLocationDecoder()
return GCPURLParser(geo_location_resolver, geo_location_decoder)
def main(filename):
gcp_lookup_table = load_your_gcp_list("my_gcp_list.txt")
def lookup_geo_location_in_lookup_table(id: str):
for entry in gcp_lookup_table:
[entry_id, latitude, longitude, altitude_in_meters] = entry
if id != entry_id:
continue
return model.GeoLocation(float(latitude), float(longitude), float(altitude_in_meters))
raise Exception("Id not found in lookup table: " + id)
gcp_url_parser = init_gcp_url_parser(lookup_geo_location_in_lookup_table)
print("Hello, starting GCP-OSM...")
print("")
# now working time
if os.path.isdir(args.file):
print("loading in all files in folder:", filename)
processing_files = utils.get_all_files(filename)
elif os.path.isfile(args.file):
print("loading in this file:", filename)
processing_files = utils.get_one_file(filename)
else:
print("neither file nor folder. ending programm.")
return
gcp_tuples_to_write = []
for file in processing_files:
found_qr_codes = qr_code_extractor.get_qr_data(file, debug_show_image=args.is_debug)
print(str(found_qr_codes) + " -> ", end='')
[gcp_url, upper_left_position_marker_pixel_coordinates] = found_qr_codes
if gcp_url != '' and upper_left_position_marker_pixel_coordinates is not None:
ground_control_point = gcp_url_parser.parse(gcp_url)
print(ground_control_point)
gcp_tuples_to_write.append( (file, ground_control_point.center_geo_location, *upper_left_position_marker_pixel_coordinates) )
print("writing gcp list to " + args.output_file);
write_gcp_list_file(args.output_file, gcp_tuples_to_write)
print("")
print("GCP-OSM is finished, Good Bye!")
if __name__ == '__main__':
args = argument_parser.parse_arguments()
main(args.file)