-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdepth_visulization.py
147 lines (102 loc) · 4.37 KB
/
depth_visulization.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import numpy as np
import os
import sys
from matplotlib import pyplot as plt
from PIL import Image
from numpy.lib.npyio import load
import cv2
# import rospy
import glob
import pandas as pd
# from visualization_msgs.msg import Marker
path = "E://cloth_datasets//cloth_datasets"
filepath = "E://cloth_datasets//cloth_datasets//clean_datasets"
# img = cv2.imread('E:\\cloth_datasets\\cloth_datasets\\rgb_222_1638896540-155743599.png')
# print(type(cv2.imread(path)))
# img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# plt.subplot(1,2,1)
# plt.imshow(img)
# depth = np.load('E:\\cloth_datasets\\cloth_datasets\\depth_222_1638896540-155743599.npy')
# plt.subplot(1, 2, 2)
# plt.imshow(depth, cmap='gray')
# plt.show()
class Data_loader():
def __init__(self):
path = "E://cloth_datasets//cloth_datasets"
self.path = path
self.image_list = []
self.image_index_list = []
self.depth_list = []
self.depth_index_list = []
for filename in glob.glob('E:/cloth_datasets/cloth_datasets/rgb*'):
self.rgb_image = Image.open(filename)
self.image_list.append(self.rgb_image)
self.rgb_image_index = self._get_imidx(filename)
self.image_index_list.append(self.rgb_image_index)
for filename in glob.glob('E:/cloth_datasets/cloth_datasets/depth*'):
self.depth_image = np.load(filename)
self.depth_image = self._fill_hole(self.depth_image)
self.depth_image = Image.fromarray(self.depth_image)
self.depth_image = self._depth_normalize(self.depth_image)
self.depth_list.append(self.depth_image)
self.depth_image_index = self._getdep_imidx(filename)
self.depth_index_list.append(self.depth_image_index)
def _depth_normalize(self,depth_data):
MIN = np.min(depth_data)
MAX = np.max(depth_data)
depth_data = (depth_data-MIN) / (MAX-MIN)
return depth_data
def _fill_hole(self, im):
zeros = np.where(im == 0)
mask = np.zeros_like(im, np.uint8)
mask[zeros] = 1
im = cv2.inpaint(im, mask, 3, cv2.INPAINT_NS)
return im
def _get_imidx(self,index):
imidx = index.split("_")[4].replace(".png", "")
return imidx
def _getdep_imidx(self,index):
imidx = index.split("_")[4].replace(".npy", "")
return imidx
if __name__ == '__main__':
a = Data_loader()
rgb_image_list = a.image_list
rgb_header_list = a.image_index_list
# rgb_list = list(zip(rgb_header_list, rgb_image_list))
depth_image_list = a.depth_list
depth_header_list = a.depth_index_list
# depth_list = list(zip(depth_header_list, depth_image_list))
align_list = []
align_image = []
align_depth = []
for i in range(len(rgb_header_list)):
rgb_idx = rgb_header_list[i]
try:
dep_idx = depth_header_list.index(rgb_idx)
align_list.append(rgb_idx)
align_image.append(rgb_image_list[i])
align_depth.append(depth_image_list[dep_idx])
except:
pass
align_data = list(zip(align_list, align_image, align_depth))
# df = pd.DataFrame(align_image, index = align_list)
for i in range(len(align_data)):
print(i)
img_path = os.path.join(filepath, 'rgb_%d_%s-%s.png' % (i, align_data[i][0].split("-")[0], align_data[i][0].split("-")[1]))
print(align_data[i][1])
a = np.array(align_data[i][1])
a = a[:, :, ::-1].copy() # cover to RGB
cv2.imwrite(img_path, a)
img_path = os.path.join(filepath, 'depth_%d_%s-%s.npy' % (i, align_data[i][0].split("-")[0], align_data[i][0].split("-")[1]))
print(align_data[i][2])
a = np.array(align_data[i][2])
np.save(img_path, a)
plt.subplot(2, 2, 1)
plt.imshow(align_data[192][1])
plt.subplot(2, 2, 2)
plt.imshow(align_data[192][2], cmap='gray')
plt.subplot(2, 2, 3)
plt.imshow(align_data[152][1])
plt.subplot(2, 2, 4)
plt.imshow(align_data[152][2], cmap='gray')
plt.show()