目录
1.数据加载以及数据增强
以室内数据NYU为例,txt文件可以在BTS的GitHub上下载,老版本的是csv文件,需用用pandas读取,过程类似
image_file = []
depth_file = []
data_file = r"F:\Datasets\nyu_depth_v2\offical_splits\train.txt"
with open(data_file, 'r') as f:
listInTXT = [line.strip() for line in f]
print(len(listInTXT))
此时测试的数据读取是正确的,总共 image/depth/focal 一共24231条, line.strip()可以把当前str内的空格删除,这里的作用是为了划分一行一行的数据,否则直接用 f.read(data_file)得到的结果是1条集体数据中包含的字符数。
对于此时已经按照 image/depth/focal 划分好的数据路径,我们可以切片为image_file, depth_file。
import cv2
image_path = []
depth_path = []
for i in range(len(listInTXT)):
image_file.append(listInTXT[i].split(' ')[0])
depth_file.append(listInTXT[i].split(' ')[1])
image_path.append("F:/Datasets/nyu_depth_v2/offical_splits/train" + image_file[i])
depth_path.append("F:/Datasets/nyu_depth_v2/offical_splits/train" + depth_file[i])
上述路径根据绝对地址自行修改
测试图像是否正确读入
%matplotlib inline
import matplotlib.pyplot as plt
image = cv2.imread(image_path[0])
cv2.imshow("test",image)
cv2.waitKey()
也可以用PIL 读取