-
Notifications
You must be signed in to change notification settings - Fork 47
/
IO_funcs.py
71 lines (54 loc) · 1.6 KB
/
IO_funcs.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
import os
import Config
import numpy as np
import random
from PIL import Image
import cv2
import math
import matplotlib.pyplot as plt
def get_table(filename):
'''
Input : File
Output : Array containing the table in the file in float format.
'''
f = open(filename, 'r')
lines = f.readlines()
l=[]
for line in enumerate(lines):
#print line
line_split = line[1].split(' ')
l.append(float(line_split[1]))
return np.asarray(l)
def get_HW(filename):
'''
Output : Shape of the image.
'''
f = open(filename, 'r')
lines = f.readlines()
for i,line in enumerate(lines):
if line.find('ROOM') > -1:
return np.int(line.split(' ')[1]),np.int(line.split(' ')[2])
return -1,-1
def extract_BB_coordinates(filename,camera):
'''
In : pom file name, camera id
Out : List of all bounding boxes coordinates on this view, as defined by the pom file.
'''
f = open(filename, 'r')
lines = f.readlines()
bounding_boxes =[]
current_object =1
for i,line in enumerate(lines):
if line.find('RECTANGLE %d'%camera) > -1:
bounding_boxes.append(parse_BB_from_line(line))
return bounding_boxes
def parse_BB_from_line(line):
'''
In : line string
Out : coordinates of the box in the parsed line, where we set random 0-size coordinates.
'''
line_split = line.split(' ')
if line_split[3] == 'notvisible\n':
return [0,0,0,0]
else:
return [np.int(line_split[3]),np.int(line_split[4]),np.int(line_split[5]),np.int(line_split[6])]