Skip to content
Snippets Groups Projects
Commit 43347063 authored by Manuel's avatar Manuel
Browse files

Remove unused files

parent 96247840
No related branches found
No related tags found
No related merge requests found
import configuration as config
from utility.cam_models import *
import cv2
import numpy as np
import json
import os
import sys
# Add project library to Python path
python_src_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print(f"Adding '{python_src_dir}' to sys.path")
sys.path.append(python_src_dir) # /code/python/src/
sys.path.append(os.path.dirname(python_src_dir)) # /code/python/
# sys.path.append(os.path.join(python_src_dir, "../..")) # CR: unused?
# Data directory /data/
# TODO: remove the trailing slash once all usages of TEST_DATA_DIR are updated
TEST_DATA_DIR = os.path.abspath("../../../../data/") + "/"
# Set the PyTorch hub folder as an environment variable
# TODO: use os.path.join instead of string
os.environ['TORCH_HOME'] = TEST_DATA_DIR + 'models/'
if __name__ == "__main__":
data_root = config.TEST_DATA_DIR
json_file = json.load(open(data_root + 'brown_00/calibration.json', 'r')) # Calibration file from Elliot
# There are 6 cameras. I dont know to which one belongs the image under test. I use all of them.
camera_params = json_file['cameras']
img = cv2.cvtColor(cv2.imread(data_root + "brown_00/video-frame-3840x2880.png"), cv2.COLOR_BGR2RGB)
img = np.moveaxis(img, 0, 1)[::-1, ...] # Rotate image 90º counter clockwise
for cam in camera_params:
# Uncomment to undistort the whole input image
# mapx, mapy = create_perspective_undistortion_LUT(img.shape[:-1], ind_camera, sf=-7)
# undistorted = cv2.remap(img, mapx.astype(np.float32), mapy.astype(np.float32), cv2.INTER_LINEAR,
# borderMode=cv2.BORDER_CONSTANT)
RGB_subimages, depth_subimages, camera_array_size = sample_img(img, cam, run_midas=False)
plot_img_array(camera_array_size, RGB_subimages)
plot_img_array(camera_array_size, depth_subimages)
import configuration as config
from utility import depthmap_utils
from utility import metrics
from utility import image_io
from utility import depthmap_utils
from utility.logger import Logger
from MiDaS import MiDaS_utils
import numpy as np
log = Logger(__name__)
log.logger.propagate = False
def test_delta_inlier_ratio_map(dispmap_predict_filepath, depthmap_gt_filepath, output_filepath):
""" Test the error and error map.
"""
# 0) load data
gt_depthmap = depthmap_utils.read_dpt(depthmap_gt_filepath)
gt_dispmap = depthmap_utils.depth2disparity(gt_depthmap)
dispmap_predict, _ = MiDaS_utils.read_pfm(dispmap_predict_filepath)
mask = np.ones_like(gt_dispmap)
# 1) compute the metric
for index in range(1, 4):
delta_data = metrics.delta_inlier_ratio(dispmap_predict, gt_dispmap, mask, index)
print("dalta_{} error is {}".format(index, delta_data))
delta_data_map = metrics.delta_inlier_ratio_map(dispmap_predict, gt_dispmap, mask, index)
depthmap_utils.depth_visual_save(delta_data_map, output_filepath + "error_delta_{}.jpg".format(index))
abs_rel_error = metrics.abs_rel_error(dispmap_predict, gt_dispmap, mask)
abs_rel_error_map = metrics.abs_rel_error_map(dispmap_predict, gt_dispmap, mask)
print("Absolute Relative Difference error is {}".format(abs_rel_error))
depthmap_utils.depth_visual_save(abs_rel_error_map, output_filepath + "error_abs_rel_error.jpg")
sq_rel_error = metrics.sq_rel_error(dispmap_predict, gt_dispmap, mask)
sq_rel_error_map = metrics.sq_rel_error_map(dispmap_predict, gt_dispmap, mask)
print("Square Relative Difference error is {}".format(sq_rel_error))
depthmap_utils.depth_visual_save(sq_rel_error_map, output_filepath + "error_sq_rel_error.jpg")
lin_rms_sq_error = metrics.lin_rms_sq_error(dispmap_predict, gt_dispmap, mask)
lin_rms_sq_error_map = metrics.lin_rms_sq_error_map(dispmap_predict, gt_dispmap, mask)
print("RMSE (linear) is {}".format(lin_rms_sq_error))
depthmap_utils.depth_visual_save(lin_rms_sq_error_map, output_filepath + "error_lin_rms_sq_error.jpg")
log_rms_sq_error = metrics.log_rms_sq_error(dispmap_predict, gt_dispmap, mask)
log_rms_sq_error_map = metrics.log_rms_sq_error_map(dispmap_predict, gt_dispmap, mask)
print("RMSE (log) is {}".format(log_rms_sq_error))
depthmap_utils.depth_visual_save(log_rms_sq_error_map, output_filepath + "error_log_rms_sq_error.jpg")
log_rms_scale_invariant = metrics.log_rms_scale_invariant(dispmap_predict, gt_dispmap, mask)
log_rms_scale_invariant_map = metrics.log_rms_scale_invariant_map(dispmap_predict, gt_dispmap, mask)
print("RMSE (log scale invariant) is {}".format(log_rms_scale_invariant))
depthmap_utils.depth_visual_save(log_rms_scale_invariant_map, output_filepath + "error_log_rms_scale_invariant_map.jpg")
if __name__ == "__main__":
data_root = config.TEST_DATA_DIR + "erp_00/"
depth_gt_filepath = data_root + "0001_depth.dpt"
dispmap_filepath = data_root + "0001_dispmap_aligned.pfm"
output_filepath = data_root + "debug/"
test_delta_inlier_ratio_map(dispmap_filepath, depth_gt_filepath, output_filepath)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment