-
Notifications
You must be signed in to change notification settings - Fork 1
/
viewer.py
executable file
·97 lines (76 loc) · 2.45 KB
/
viewer.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
#!/usr/bin/env python3
# import sys
import os
import glob
import argparse
# import vlc
# import multiprocessing
# import threading
# from enum import Enum
import python.logfile
from python.logfile import *
def my_glob(path):
expanded = []
for r,d,f in os.walk(path):
for file in f:
expanded.append(f"{r}/{file}")
return expanded
def main():
# os.system('cls' if os.name == 'nt' else 'clear')
parser = argparse.ArgumentParser(
description='View results of query')
# Positional arguments
parser.add_argument(
'logfile',
type=str,
help='path to result logfile')
parser.add_argument(
'querypath',
type=str,
help='path to query video')
parser.add_argument(
'-v','--visualize',
action='store_true',
help='visualize video matches'
)
parser.add_argument(
'-shortestmatch',
metavar = '',
type=int,
help='minimum length of matching video clip (in seconds)',
default=0)
args = parser.parse_args()
if not os.path.isfile(args.logfile):
print("Logfile does not exist at this path")
return
logfile = read_logfile(args.logfile, args.shortestmatch)
print_log(logfile)
if not args.visualize or len(logfile) < 1:
return
from python.previewer import Previewer
db_video_path = input("Please enter directory of videos in database to view alignments: ")
while not os.path.isdir(db_video_path):
print("Not a valid directory, please try again.")
db_video_path = input("Please enter directory of videos in database to view alignments: ")
vids = my_glob(db_video_path)
# dict of vidname to path
db_vids = {os.path.basename(vid) :vid for vid in vids}
selection=""
while (1):
selection = input("Enter a number to view match, q to quit: ")
if selection in ["q","Q","quit","Quit"]:
break
else:
try:
selection = int(selection)
selected_row = logfile[selection]
except:
print("Invalid choice, try again")
continue
if selected_row[VIDNAME] in db_vids:
previewer = Previewer(args.querypath, db_vids[selected_row[VIDNAME]], selected_row)
previewer.view()
else:
print(f"{selected_row[VIDNAME]} is not in the database video directory")
if __name__ == '__main__':
main()