Skip to content

Commit

Permalink
depth map projects added
Browse files Browse the repository at this point in the history
  • Loading branch information
Shee-Ra committed Nov 8, 2020
1 parent 6a557ea commit c920757
Show file tree
Hide file tree
Showing 4 changed files with 505 additions and 0 deletions.
60 changes: 60 additions & 0 deletions 6_Project/1_get_depth_maps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import cv2
from PIL import Image
import numpy as np
import os
from matplotlib import pyplot as plt
from src.utils import *
from tqdm import tqdm

processed_frame_path = os.path.join(os.getcwd(), '6_Project/data/processed/')
allfiles = sorted(os.listdir(processed_frame_path))
results_path = os.path.join(os.getcwd(), '6_Project/data/results/')

file_pairs = []
for jpg in allfiles[1:]:
name = jpg.split('_')[0] + '_' + jpg.split('_')[1]
if jpg.split('_')[2] == 'left.jpg':
file_pairs.append((processed_frame_path + jpg, processed_frame_path + name + '_right.jpg'))

for k, p in enumerate(tqdm(file_pairs)):
left, right = load_image_pairs(p)
filename = p[0].split('/')[-1][0:-9] + '.jpg'
full_path = os.path.join(results_path, filename)

results_so_far = os.listdir(results_path)
if filename in results_so_far:
continue
else:
while_loop_go = True
try_overlap = 0.95
while while_loop_go:
try:
# if True:
lags_mapped_to_2D = GetDepthMap(left,
right,
windowsize=20,
overlap=try_overlap,
padding=0,
windowsearch=True,
use_my_lag_function=True)

# save file
cmap = plt.cm.jet
image = cmap(lags_mapped_to_2D)
plt.imshow(lags_mapped_to_2D)
plt.savefig(full_path)
plt.clf()
print(f'{filename} saved')

while_loop_go = False

except:
f = open(os.path.join(results_path, "fails.txt"),"a+")
f.write(f'{filename} fails for overlap {try_overlap}\n')
f.close()

try_overlap = try_overlap - 0.05
if try_overlap < 0.5:
while_loop_go= False
print(f'hyperparameter causes error (likely overlap is too large)')
continue
68 changes: 68 additions & 0 deletions 6_Project/2_make_videos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import cv2
import os

# paths etc.
path_left_images = os.path.join(os.getcwd(),'6_Project/data/processed/')
path_depth_maps = os.path.join(os.getcwd(),'6_Project/data/results/')
path_save_videos = os.path.join(os.getcwd(),'6_Project/data/results/')

left_images = sorted(os.listdir(path_left_images))
depth_maps = sorted(os.listdir(path_depth_maps))

video_left_images = 'video_left_images.avi'
video_depth_maps = 'video_depth_maps.avi'

left = [path_left_images, left_images, video_left_images, path_save_videos]
depth_maps = [path_depth_maps, depth_maps, video_left_images, path_save_videos]

# create videos
for im_sets in [left, depth_maps]:
images = [img for img in im_sets[1] if img.endswith(".jpg")]
frame = cv2.imread(os.path.join(im_sets[0], images[0]))
height, width, layers = frame.shape

video = cv2.VideoWriter(im_sets[2], 0, 7.0, (width,height))

for image in images:
video.write(cv2.imread(os.path.join(im_sets[3], image)))

cv2.destroyAllWindows()
video.release()


# ----------



# image_folder = os.path.join(os.getcwd(),'6_Project/data/processed/2018-08-01-11-13-14_left/')
# allfiles = sorted(os.listdir(image_folder))
# video_name = 'video_left.avi'

# images = [img for img in allfiles if img.endswith(".jpg")]
# frame = cv2.imread(os.path.join(image_folder, images[0]))
# height, width, layers = frame.shape

# video = cv2.VideoWriter(video_name, 0, 7.0, (width,height))

# for image in images:
# video.write(cv2.imread(os.path.join(image_folder, image)))

# cv2.destroyAllWindows()
# video.release()

# # depth maps
# image_folder = os.path.join(os.getcwd(),'6_Project/data/results/')
# images_sorted = sorted(os.listdir(image_folder))
# video_name = 'my_depth_map.avi'

# images = [img for img in images_sorted if img.endswith(".jpg")]
# frame = cv2.imread(os.path.join(image_folder, images[0]))
# height, width, layers = frame.shape

# video = cv2.VideoWriter(video_name, 0, 7.0, (width,height))

# for image in images:
# video.write(cv2.imread(os.path.join(image_folder, image)))

# cv2.destroyAllWindows()
# video.release()
Binary file added 6_Project/src/__pycache__/utils.cpython-36.pyc
Binary file not shown.
Loading

0 comments on commit c920757

Please sign in to comment.