-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelping_functs.py
63 lines (54 loc) · 1.96 KB
/
helping_functs.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
import cv2
import os
import numpy as np
import time
#import matplotlib.pyplot as plt
def im_convert(fil, path, flag):
if flag=='Depth':
img=cv2.imread(path+'/'+fil)
img=(256*256*img[:, :, 0]+256*img[:, :, 1]+img[:, :, 2])/float(256*256*256)
elif flag=='Color':
initimg=cv2.imread(path+'/'+fil)
img=np.zeros([424, 512, 3])
for c in range(3):
img[:, :, c]=cv2.resize(initimg[:, :, c], (512, 424))/float(256)
return(img)
def im_load(path, flag):
contents=os.listdir(path) # returns list
ctime= map(lambda fil:os.stat(path+'/'+fil)[8], contents)
contents=[x for (y, x) in sorted(zip(ctime, contents))]
if flag=='Depth':
imdata=np.transpose(np.concatenate([map(lambda fil:im_convert(fil, path, flag), contents)]), (1, 2, 0))
elif flag=='Color':
imdata=np.transpose(np.concatenate([map(lambda fil:im_convert(fil, path, flag), contents)]), (1, 2, 3, 0))
return(imdata)
'''
def hist(image):
hbins=30
plt.hist(image.ravel()*256, 256, [1, 256])
plt.show()
'''
def diff(a, b):
if sum(list(b.shape))/2>1:
return [np.sqrt((i[0]-j[0])**2+(i[1]-j[1])**2) for i, j in zip(np.array(a), np.array(b))]
else:
if sum(list(b.shape))==2:
return [np.sqrt((i[0]-b[0])**2+(i[1]-b[1])**2) for i in a]
else:
return [np.sqrt((i-b)**2) for i in a]
def interpolate(points, winsize):
interpolated_data=[]
for count, i in enumerate(range(0, points.shape[0], (winsize-1)/2)):
interpolated_data.append(np.mean(points[max(0, i-(winsize-1)/2):(min(i+(winsize-1)/2, points.shape[0]-1)+1)], axis=0))
return np.array(interpolated_data)
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def compute_angles(points):
return np.array([np.arctan2(n[1], n[0]) for n in points[1:]-points[:-1]])