-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui_checker.py
106 lines (78 loc) · 4.41 KB
/
gui_checker.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
import os
import pandas as pd
import numpy as np
import PySimpleGUI as sg
def get_data_for_encounter(encounter_db_line):
# Get middle timestamp
center = np.mean([encounter_db_line.begin, encounter_db_line.end])
# Scrape directory
camera_folder = os.path.join('H:', 'bagfiles_unpack', encounter_db_line.bag_file, 'camera_0')
frame_list = os.listdir(camera_folder)
frame_list_float = [float(frame[:-4]) for frame in frame_list]
closest_index = np.argmin(abs(frame_list_float - center))
frame_to_use = frame_list[closest_index]
second_frame_to_use = frame_list[closest_index + 1]
return os.path.join(camera_folder, frame_to_use), os.path.join(camera_folder, second_frame_to_use), encounter_db_line.description, encounter_db_line.is_encounter, encounter_db_line.direction, encounter_db_line.distance
# Open feather file
encounter_db = pd.read_feather('H:/bagfiles_unpack/encounter_db_v2_backup_after_manual.feather')
encounter_db = encounter_db.drop_duplicates(subset=['begin', 'end', 'description']).reset_index().drop('index', axis=1)
# Start index of unchecked data
first_unchecked = min(encounter_db[encounter_db.manual_override == False].index)
# Get first entry
image_path_0, image_path_1, description, is_encounter, direction, distance = get_data_for_encounter(encounter_db.iloc[first_unchecked])
# Counter to go through all encounters
counter = first_unchecked + 1
sg.theme('DarkAmber') # Add a touch of color
# All the stuff inside your window.
layout = [ [sg.Image(image_path_0, key="-IMAGE-")],
[sg.Text(f"Direction: {direction}, Description: {description}, Distance: {distance}", key="-TEXT-")],
[ sg.Button('Oppose'), sg.Button('None'), sg.Button('Overtake'), sg.VerticalSeparator(), sg.Button('Prev'), sg.Button('Next'), sg.VerticalSeparator(), sg.Button('GO BACK')] ]
# Create the Window
window = sg.Window('GUI Checker', layout)
# Event Loop to process "events" and get the "values" of the inputs
while True:
event, values = window.read()
# If user closes window
if event == sg.WIN_CLOSED or counter == len(encounter_db):
break
if event == 'No':
print(0, -1, int(is_encounter), direction)
encounter_db.at[counter - 1, 'is_encounter'] = False
encounter_db.at[counter - 1, 'direction'] = -1
encounter_db.at[counter - 1, 'manual_override'] = True
# Get next encounter
image_path_0, image_path_1, description, is_encounter, direction, distance = get_data_for_encounter(encounter_db.iloc[counter])
counter += 1
window["-IMAGE-"].update(image_path_0)
window["-TEXT-"].update(f"Direction: {direction}, Description: {description}, Distance: {distance}")
elif event == 'Overtake':
print(1, 1, int(is_encounter), direction)
encounter_db.at[counter - 1, 'is_encounter'] = True
encounter_db.at[counter - 1, 'direction'] = 1
encounter_db.at[counter - 1, 'manual_override'] = True
# Get next encounter
image_path_0, image_path_1, description, is_encounter, direction, distance = get_data_for_encounter(encounter_db.iloc[counter])
counter += 1
window["-IMAGE-"].update(image_path_0)
window["-TEXT-"].update(f"Direction: {direction}, Description: {description}, Distance: {distance}")
elif event == 'Oppose':
print(1, 0, int(is_encounter), direction)
encounter_db.at[counter - 1, 'is_encounter'] = True
encounter_db.at[counter - 1, 'direction'] = 0
encounter_db.at[counter - 1, 'manual_override'] = True
# Get next encounter
image_path_0, image_path_1, description, is_encounter, direction, distance = get_data_for_encounter(encounter_db.iloc[counter])
counter += 1
window["-IMAGE-"].update(image_path_0)
window["-TEXT-"].update(f"Direction: {direction}, Description: {description}, Distance: {distance}")
elif event == 'Next':
window["-IMAGE-"].update(image_path_1)
elif event == 'Prev':
window["-IMAGE-"].update(image_path_0)
elif event == 'GO BACK':
counter -= 1
image_path_0, image_path_1, description, is_encounter, direction, distance = get_data_for_encounter(encounter_db.iloc[counter - 1])
window["-IMAGE-"].update(image_path_0)
window["-TEXT-"].update(f"Direction: {direction}, Description{description}, Distance: {distance}")
window.close()
#encounter_db.to_feather('H:/bagfiles_unpack/encounter_db_v2.feather')