-
Notifications
You must be signed in to change notification settings - Fork 4
/
generate_smaller_depth.py
executable file
·69 lines (49 loc) · 1.7 KB
/
generate_smaller_depth.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
import itertools as it
import pickle
from random import sample, randint, random
from time import time
import cv2
import numpy as np
import xml.etree.ElementTree as ET
import operator
import math
import glob
from PIL import Image as PILImage
import sys
import Image
import os
from random import shuffle
import copy
#import scipy.misc
load_dir = '/media/shehroze/sheep/deathmatch_slam_new/'
save_dir = '/media/shehroze/sheep/deathmatch_slam_new/'
total_images = 991
def convertToGrayScale(img, height=84,width=84):
img = img.astype(np.float32)
img = cv2.resize(img, (height, width))
return img
def convert(img):
rgb = np.zeros((480, 640, 3), dtype=np.uint8)
rgb[..., 0] = img[:,:,2]
rgb[..., 1] = img[:,:,1]
rgb[..., 2] = img[:,:,0]
return rgb
count = 0
with open(load_dir + 'depth.txt') as f:
frameCount = -1
for line in f:
line_components = line.split(" ")
filename = line_components[1].replace("depth/", "")
filename = filename.replace("\n","")
print('Converting file ' + filename)
depth_file_name = 'depth/' + filename
rgb_file_name = 'rgb/' + filename
depth_file = cv2.imread(load_dir + depth_file_name, cv2.CV_LOAD_IMAGE_UNCHANGED)
rgb_file = cv2.imread(load_dir + rgb_file_name)
print(depth_file.shape)
print(rgb_file.shape)
new_depth_file = cv2.resize(depth_file,(160,120))
new_rgb_file = np.zeros((120,160,3))
new_rgb_file[:,:,0], new_rgb_file[:,:,1], new_rgb_file[:,:,2] = cv2.resize(rgb_file[:,:,0], (160,120)), cv2.resize(rgb_file[:,:,1], (160,120)), cv2.resize(rgb_file[:,:,2], (160,120))
cv2.imwrite(save_dir + 'depth_small_size/' + filename , new_depth_file)
cv2.imwrite(save_dir + 'rgb_small_size/' + filename, new_rgb_file)