forked from meteorshowers/X-StereoLab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SecenFlowLoader.py
executable file
·121 lines (102 loc) · 3.26 KB
/
SecenFlowLoader.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import torch.utils.data as data
import random
from PIL import Image
from . import preprocess
# import preprocess
import numpy as np
import sys, os
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
IMG_EXTENSIONS = [
'.jpg',
'.JPG',
'.jpeg',
'.JPEG',
'.png',
'.PNG',
'.ppm',
'.PPM',
'.bmp',
'.BMP',
]
def is_image_file(filename):
return any(filename.endswith(extension) for extension in IMG_EXTENSIONS)
def default_loader(path):
return Image.open(path).convert('RGB')
# def disparity_loader(path):
# path_prefix = path.split('.')[0]
# # print(path_prefix)
# path1 = path_prefix + '_exception_assign_minus_1.npy'
# path2 = path_prefix + '.npy'
# path3 = path_prefix + '.pfm'
# import os.path as ospath
# if ospath.exists(path1):
# return np.load(path1)
# else:
# if ospath.exists(path2):
# data = np.load(path2)
# else:
# # from readpfm import readPFMreadPFM
# from readpfm import readPFM
# data, _ = readPFM(path3)
# np.save(path2, data)
# for i in range(data.shape[0]):
# for j in range(data.shape[1]):
# if j - data[i][j] < 0:
# data[i][j] = -1
# np.save(path1, data)
# return data
def disparity_loader(path):
path_prefix = path.split('.')[0]
# print(path_prefix)
path1 = path_prefix + '_exception_assign_minus_1.npy'
path2 = path_prefix + '.npy'
path3 = path_prefix + '.pfm'
import os.path as ospath
if ospath.exists(path1):
return np.load(path1)
else:
# from readpfm import readPFMreadPFM
from readpfm import readPFM
data, _ = readPFM(path3)
np.save(path2, data)
for i in range(data.shape[0]):
for j in range(data.shape[1]):
if j - data[i][j] < 0:
data[i][j] = -1
np.save(path1, data)
return data
class myImageFloder(data.Dataset):
def __init__(self,
left,
right,
left_disparity,
training,
normalize,
loader=default_loader,
dploader=disparity_loader):
self.left = left
self.right = right
self.disp_L = left_disparity
self.loader = loader
self.dploader = dploader
self.training = training
self.normalize = normalize
def __getitem__(self, index):
left = self.left[index]
right = self.right[index]
disp_L = self.disp_L[index]
left_img = self.loader(left)
right_img = self.loader(right)
dataL = self.dploader(disp_L)
dataL = np.ascontiguousarray(dataL, dtype=np.float32)
processed = preprocess.get_transform(
augment=False, normalize=self.normalize)
left_img = processed(left_img)
right_img = processed(right_img)
return left_img, right_img, dataL
def __len__(self):
return len(self.left)
if __name__ == '__main__':
path = '/media/lxy/sdd1/stereo_coderesource/dataset_nie/SceneFlowData/frames_cleanpass/flyingthings3d_disparity/TRAIN/A/0024/left/0011.pfm'
res = disparity_loader(path)
print(res.shape)