-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutilities.py
39 lines (32 loc) · 1.19 KB
/
utilities.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
from operator import itemgetter
import os
import xml.etree.ElementTree as ET
# find all videos whith a certain directory
def find_videos(path, extension):
if not extension:
extension="MOV"
videos_names = []
files_path = []
for file in os.listdir(path):
if file.endswith(f".{extension}"):
videos_names.append(file)
files_path.append(os.path.join(path,file))
return(files_path, videos_names)
# check if folder exists, and create one if it doesn't
def create_folder_for_video (video_path, extention):
if not os.path.exists(video_path+extention):
os.mkdir(video_path+extention)
# extract parameters from the xml camera calibration file
def get_parameters (video_path):
parameters_dict = {}
if os.path.exists(f"{video_path[:-4]}_camera_calibration.xml"):
xmlTree = ET.parse(f"{video_path[:-4]}_camera_calibration.xml")
for elem in xmlTree.iter():
parameters_dict[elem.tag] = elem.text
else:
parameters_dict['k1'] = 0
parameters_dict['k2'] = 0
parameters_dict['p1'] = 0
parameters_dict['p2'] = 0
parameters_dict['f'] = 0
return parameters_dict