import os
import cv2
import time
import numpy as np
from google.colab import drive
drive.mount('/content/gdrive')
def normalize_mat(depth_src):
depth_min = depth_src.min()
depth_max = depth_src.max()
depth = (depth_src - depth_min) / (depth_max - depth_min)
return depth
def generate_stereo(depth_dir, depth_prefix, filename):
print("=== Start processing:", filename, "===")
depth_src = cv2.imread(os.path.join(depth_dir, depth_prefix + filename + ".jpg"))
if len(depth_src.shape) == 3:
depth_src = cv2.cvtColor(depth_src, cv2.COLOR_BGR2GRAY)
else:
depth_src = depth_src
depth = normalize_mat(depth_src)
depth = np.round(depth*255).astype(int)
cv2.imwrite(os.path.join(depth_dir, "normaized_depth_" + filename + ".jpg"), depth)
def file_processing_im(depth_dir, depth_prefix):
for f in os.listdir(depth_dir):
filename = f.split(".")[0]
generate_stereo(depth_dir, depth_prefix, filename)
def main():
start_time = time.time()
depth_dir = 'gdrive/MyDrive/depth/'
depth_prefix = 'Depth_'
file_processing_im(depth_dir, depth_prefix)
print(time.time() - start_time, "seconds for base generation")
if name == "main":
main()