forked from flyhamsw/livedronemap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrone_watchcat_exif.py
118 lines (107 loc) · 4.66 KB
/
drone_watchcat_exif.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import time, os
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
from config.config_watchdog import BaseConfig as Config
from clients.ldm_client import Livedronemap
from server.image_processing.exif_parser import extract_eo
image_list = []
eo_list = []
ldm = Livedronemap(Config.LDM_ADDRESS)
project_id = ldm.create_project(Config.LDM_PROJECT_NAME)
ldm.set_current_project(project_id)
print('Current project ID: %s' % project_id)
def upload_data(image_fname, eo_fname):
result = ldm.ldm_upload(image_fname, eo_fname)
print('response from LDM server:')
print(result)
def diff(current, previous):
previous = set(previous)
return [item for item in current if item not in previous]
previous = os.listdir(Config.DIRECTORY_TO_WATCH)
for i in range(0, 10000):
time.sleep(10)
current = os.listdir(Config.DIRECTORY_TO_WATCH)
new = diff(current, previous)
for fname in new:
file_name = Config.DIRECTORY_TO_WATCH + '/' + fname[:-4]
extension_name = Config.DIRECTORY_TO_WATCH + '/' + fname.split('.')[-1]
print('A new file detected: %s' % file_name)
if Config.IMAGE_FILE_EXT in extension_name:
image_list.append(file_name)
eo_dict = extract_eo(file_name + '.' + Config.IMAGE_FILE_EXT, Config.CAMERA_MANUFACTURER)
with open(file_name + '.' + Config.EO_FILE_EXT, 'w') as f:
eo_file_data = 'EO' + '\t' + \
str(eo_dict['longitude']) + '\t' + \
str(eo_dict['latitude']) + '\t' + \
str(eo_dict['altitude']) + '\t' + \
str(eo_dict['yaw']) + '\t' + \
str(eo_dict['pitch']) + '\t' + \
str(eo_dict['roll']) + '\t'
print('EO data:')
print(eo_file_data)
f.write(eo_file_data)
eo_list.append(file_name + Config.EO_FILE_EXT)
print('uploading data...')
upload_data(
file_name + '.' + Config.IMAGE_FILE_EXT,
file_name + '.' + Config.EO_FILE_EXT
)
else:
print('But it is not an image file.')
print('===========================================================')
previous = os.listdir(Config.DIRECTORY_TO_WATCH)
# class Watcher:
# def __init__(self, directory_to_watch):
# self.observer = Observer()
# self.directory_to_watch = directory_to_watch
#
# def run(self):
# event_handler = Handler()
# self.observer.schedule(event_handler, self.directory_to_watch, recursive=True)
# self.observer.start()
# try:
# while True:
# time.sleep(1)
# except:
# self.observer.stop()
# self.observer.join()
#
#
# class Handler(FileSystemEventHandler):
# @staticmethod
# def on_any_event(event):
# if event.is_directory:
# return None
# elif event.event_type == 'created':
# file_name = event.src_path.split('\\')[-1][:-4]
# extension_name = event.src_path.split('\\')[-1].split('.')[-1]
# print('A new file detected: %s' % file_name)
# if Config.IMAGE_FILE_EXT in extension_name:
# image_list.append(file_name)
# time.sleep(5)
# eo_dict = extract_eo(file_name + '.' + Config.IMAGE_FILE_EXT, Config.CAMERA_MANUFACTURER)
# with open(file_name + '.' + Config.EO_FILE_EXT, 'w') as f:
# eo_file_data = 'EO' + '\t' + \
# str(eo_dict['longitude']) + '\t' + \
# str(eo_dict['latitude']) + '\t' + \
# str(eo_dict['altitude']) + '\t' + \
# str(eo_dict['yaw']) + '\t' + \
# str(eo_dict['pitch']) + '\t' + \
# str(eo_dict['roll']) + '\t'
# print('EO data:')
# print(eo_file_data)
# f.write(eo_file_data)
# eo_list.append(file_name + Config.EO_FILE_EXT)
# print('uploading data...')
# upload_data(
# file_name + '.' + Config.IMAGE_FILE_EXT,
# file_name + '.' + Config.EO_FILE_EXT
# )
# else:
# print('But it is not an image file.')
# print('===========================================================')
#
#
# if __name__ == '__main__':
# w = Watcher(directory_to_watch=Config.DIRECTORY_TO_WATCH)
# w.run()