-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpeek-incomplete.py
74 lines (64 loc) · 1.58 KB
/
peek-incomplete.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
# peek.py
# This file is served as utilities to
# read homography matrix of a specified image
import scipy.io
import sys
import glob
import os
import pdb
FOLDER_PATH = '../processed_dataset/cmp/incomplete/'
path_len = len(FOLDER_PATH)
suffix = -5
# read mat
def readmat(img_path, i):
x = scipy.io.loadmat(img_path + 'rectification_mats.mat')
Hl = x['tl']
Hr = x['tr']
return Hl, Hr
def printmat(img_path, i):
Hl, Hr = readmat(img_path, i)
print(">>> [" + str(i) + "] Peek " + img_path + " >>>")
print("> Left Homography:\n" + str(Hl))
print("> Right Homography:\n" + str(Hr))
print()
def sortKeyFunc(s):
global path_len
# from pdb import set_trace as st
# st()
return int(s[path_len:suffix])
def getAllImgPaths(path):
global path_len
if path is None:
path = FOLDER_PATH
imgs = glob.glob(path + "*.jpg/")
path_len = len(path)
suffix = -5
imgs.sort(key=sortKeyFunc)
return imgs
def getAllImgs(type): # type = bad/good/borderline
global path_len
path_dir = "classified_vis/"
imgs = glob.glob(path_dir + type + "/*.png")
path_len = len(path_dir) + len(type) + 1
suffix = - len(".png")
imgs.sort(key=sortKeyFunc)
imgs = [imgs[i][path_len:suffix] for i in range(len(imgs))]
return imgs
def peek():
imgs = getAllImgPaths()
# parse arg
if len(sys.argv) != 2:
print(" Please follow the format: python3 peek.py <N or img(.jpg)>")
exit(0)
arg = sys.argv[1]
N = 0
img_path = ""
if arg.endswith(".jpg"):
img_path = FOLDER_PATH + arg + '/'
printmat(img_path)
else:
N = int(arg)
for i in range(min(N, len(imgs))):
printmat(imgs[i], i)
if __name__ == '__main__':
peek()