예제 #1
0
def main():
    for i in range(10):
        pred_disp = readPFM('output/TL' + str(i) + '.pfm')
        gt = readPFM('data/Synthetic/TLD' + str(i) + '.pfm')
        left_img = cv2.imread('data/Synthetic/TL' + str(i) + '.png')
        loss = cal_avgerr(gt, pred_disp)
        print(loss)
        new_disp = weightedMedianMatlab(left_img, pred_disp, 19, 0.1, 9)
        loss = cal_avgerr(gt, new_disp)
        print(loss)
        disp_normalized = (new_disp * 255.0).astype(np.uint8)
        disp_normalized = cv2.applyColorMap(disp_normalized, cv2.COLORMAP_JET)
        cv2.imshow("visualized disparity", disp_normalized)
        cv2.waitKey(10000)
        cv2.destroyAllWindows()
def create():
    rgb_img = cv.imread(args.rgb)
    height, width, _ = rgb_img.shape
    if args.depth.endswith('pfm'):
        depth = readPFM(args.depth)
    elif args.depth.endswith('npy'):
        depth = np.load(args.depth)

    ## create model
    model = {}
    vertices = []
    colors = []
    for w in range(width):
        for h in range(height):
            x, y, z = -w, -h, (depth[h, w] * (-1))
            r, g, b = rgb_img[h, w]
            vertices.extend([x, y, z])
            colors.extend([r, g, b])

    vertices = [float(i) for i in vertices]
    vertices = normalize_vertices(vertices, width, height)
    colors = [int(i) for i in colors]
    colors = normalize_colors(colors)

    model['vertexPositions'] = vertices
    model['vertexFrontcolors'] = colors
    model['vertexBackcolors'] = colors

    ## dump to file
    file = open(args.save, 'w')
    content = json.dumps(model)
    file.write(content)
    file.close()
    print('Saved to file:', args.save)
예제 #3
0
def read_sample(filename_queue):
    filenames = filename_queue.dequeue()
    left_fn, right_fn, disp_fn = filenames[0], filenames[1], filenames[2]
    left_img = tf.image.decode_image(tf.read_file(left_fn))
    right_img = tf.image.decode_image(tf.read_file(right_fn))
    target = tf.py_func(lambda x: readPFM(x)[0], [disp_fn], tf.float32)
    return left_img, right_img, target
def main():
    print('Compute error')
    N = 10
    imgae_dir = './data/Synthetic'
    output_dir = './output/Synthetic'
    err_list = []
    for i in range(N):
        print("loading image %d/10" % i)
        gt = readPFM(os.path.join(
            imgae_dir,
            "TLD%d.pfm" % (i)))  #os.path.join(imgae_dir, "%04d_0.png" % (i) )
        disp = readPFM(os.path.join(output_dir, "SD%d.pfm" % (i)))

        err = cal_avgerr(gt, disp)  #GT,disp
        print('avgerr: %f ' % err)
        err_list.append(err)

    print('Average error on synthetic data: %.2f' %
          (sum(err_list) / len(err_list)))
예제 #5
0
 def __init__(self, rgb_image_path=None, depth_image_path=None):
     self.rgb_image = cv.imread(rgb_image_path)
     self.shape = self.rgb_image.shape
     if depth_image_path.endswith('pfm'):
         self.depth = readPFM(depth_image_path)
     elif depth_image_path.endswith('npy'):
         self.depth = np.load(depth_image_path)
     self.vertices = []
     self.colors = []
     self.process_data()
예제 #6
0
def computeDisp(Il, Ir):
    h, w, ch = Il.shape
    disp = np.zeros((h, w), dtype=np.int32)

    # TODO: Some magic
    if if_syn:
        print('Synthesis')

        cmd = 'python submission.py --maxdisp 192 --model stackhourglass --KITTI cv --left_datapath ' + args.input_left + ' --right_datapath ' + args.input_right + ' --output ' + "ori_" + args.output + ' --loadmodel synthesis_tune_best_for_end.tar'
        print(cmd)
        retcode = subprocess.call(cmd, shell=True)
        print(retcode)

        cmd = 'python submission.py --maxdisp 192 --model stackhourglass --KITTI cv --left_datapath ' + args.input_left + ' --right_datapath ' + args.input_right + ' --output ' + "resolu_" + args.output + ' --loadmodel aug_resolutionfinetune_146.tar'
        print(cmd)
        retcode = subprocess.call(cmd, shell=True)
        print(retcode)

        cmd = 'python submission.py --maxdisp 192 --model stackhourglass --KITTI cv --left_datapath ' + args.input_left + ' --right_datapath ' + args.input_right + ' --output ' + "color_" + args.output + ' --loadmodel aug_colorfinetune_169.tar'
        print(cmd)
        retcode = subprocess.call(cmd, shell=True)
        print(retcode)

        p1 = readPFM("ori_" + args.output)
        p2 = readPFM("resolu_" + args.output)
        p3 = readPFM("color_" + args.output)
        final_pfm = (p1 + p2 + p3) / 3
        writePFM(args.output, final_pfm)

    else:
        print('Real')
        scale_factor = getlrdisp(Il, Ir)
        print(scale_factor)
        #if scale_factor in [14,56,75]:
        #    cmd = 'python cencus_quick.py '+ args.input_left +' '+args.input_right+' '+ args.output + ' ' +
        cmd = 'python cencus_transform.py ' + args.input_left + ' ' + args.input_right + ' ' + args.output
        print(cmd)
        retcode = subprocess.call(cmd, shell=True)
        print(retcode)

    return disp
예제 #7
0
def read_sample(filename_queue, pfm_target=True):
    filenames = filename_queue.dequeue()
    left_fn, right_fn, disp_fn, conf_fn = filenames[0], filenames[
        1], filenames[2], filenames[3]
    left_img = tf.image.decode_image(tf.read_file(left_fn))
    right_img = tf.image.decode_image(tf.read_file(right_fn))
    if pfm_target:
        target = tf.py_func(lambda x: readPFM(x)[0], [disp_fn], tf.float32)
    else:
        target = tf.image.decode_image(tf.read_file(disp_fn))
    conf = tf.image.decode_image(tf.read_file(conf_fn))
    return left_img, right_img, target, conf
예제 #8
0
 def fetch_data(self):
     self.left_images, self.right_images, self.ground_truths = [] , [] , []
     for n in range(self.data_size):
         left_image = cv2.imread(self.Ils_path[n],cv2.IMREAD_GRAYSCALE).astype(np.float32) / 255
         right_image = cv2.imread(self.Irs_path[n],cv2.IMREAD_GRAYSCALE).astype(np.float32) / 255
         self.ground_truths.append(readPFM(self.Gts_path[n]))
         
         #normalization
         left_image = (left_image - np.mean(left_image)) / np.std(left_image)
         right_image = (right_image - np.mean(right_image)) / np.std(right_image)            
         
         self.left_images.append(left_image)
         self.right_images.append(right_image)
         
     print("fetchdata done...")
예제 #9
0
def read_sample(filename_queue,
                pfm_target=True,
                scaled_gt=False,
                scaledConf=False):
    filenames = filename_queue.dequeue()
    left_fn, right_fn, disp_fn, conf_fn = filenames[0], filenames[
        1], filenames[2], filenames[3]
    left_img = tf.image.decode_image(tf.read_file(left_fn))
    right_img = tf.image.decode_image(tf.read_file(right_fn))
    if pfm_target:
        target = tf.py_func(lambda x: readPFM(x)[0], [disp_fn], tf.float32)
    else:
        read_type = tf.uint16 if scaled_gt else tf.uint8
        target = tf.image.decode_png(tf.read_file(disp_fn), dtype=read_type)
        if scaled_gt:
            target = tf.cast(target, tf.float32)
            target = target / 256.0

    read_type = tf.uint16 if scaledConf else tf.uint8
    conf = tf.image.decode_png(tf.read_file(conf_fn), dtype=read_type)
    if scaledConf:
        conf = tf.image.convert_image_dtype(conf, tf.float32)
    return left_img, right_img, target, conf
예제 #10
0
import sys
from util import readPFM, writePFM
from scipy.misc import imread
import numpy as np
import cv2

# read disparity pfm file (float32)
# the ground truth disparity maps may contain inf pixels as invalid pixels
disp = readPFM(str(sys.argv[1]))

# normalize disparity to 0.0~1.0 for visualization
max_disp = np.nanmax(disp[disp != np.inf])
min_disp = np.nanmin(disp[disp != np.inf])
disp_normalized = (disp - min_disp) / (max_disp - min_disp)

# Jet color mapping
disp_normalized = (disp_normalized * 255.0).astype(np.uint8)
disp_normalized = cv2.applyColorMap(disp_normalized, cv2.COLORMAP_JET)
# cv2.imwrite("visualized_disparity.png", disp_normalized)
cv2.imwrite("./synthe/syn7_bil2_tol.png", disp_normalized)
예제 #11
0
import sys
from util import readPFM, writePFM, cal_avgerr
import numpy as np
import cv2

# read disparity pfm file (float32)
# the ground truth disparity maps may contain inf pixels as invalid pixels
for i in range(10):

    disp = readPFM('output/TL' + str(i) + '.pfm')

    # normalize disparity to 0.0~1.0 for visualization
    max_disp = np.nanmax(disp[disp != np.inf])
    min_disp = np.nanmin(disp[disp != np.inf])
    disp_normalized = (disp - min_disp) / (max_disp - min_disp)

    # Jet color mapping
    disp_normalized = (disp_normalized * 255.0).astype(np.uint8)
    disp_normalized = cv2.applyColorMap(disp_normalized, cv2.COLORMAP_JET)

    cv2.imwrite('disp_vis/TL' + str(i) + '.png', disp_normalized)

    disp = readPFM('data/Synthetic/TLD' + str(i) + '.pfm')

    max_disp = np.nanmax(disp[disp != np.inf])
    min_disp = np.nanmin(disp[disp != np.inf])
    disp_normalized = (disp - min_disp) / (max_disp - min_disp)

    # Jet color mapping
    disp_normalized = (disp_normalized * 255.0).astype(np.uint8)
    disp_normalized = cv2.applyColorMap(disp_normalized, cv2.COLORMAP_JET)
예제 #12
0
def main():

    data_dir = sys.argv[1]
    output_dir = 'train-data'
    os.makedirs(output_dir, exist_ok=True)

    with open(os.path.join(output_dir, 'train.csv'), 'w') as f:
        print('lb,rb,label', file=f)
        total = 0
        # Il = cv2.imread(os.path.join(data_dir, 'im0.png'))
        # Ir = cv2.imread(os.path.join(data_dir, 'im1.png'))
        for i in range(10):
            print(i)
            Il = cv2.imread(os.path.join(data_dir, f'TL{i}.png'))
            Ir = cv2.imread(os.path.join(data_dir, f'TR{i}.png'))

            # l_d_map = readPFM(os.path.join(data_dir, 'disp0.pfm'))
            # r_d_map = readPFM(os.path.join(data_dir, 'disp1.pfm'))

            l_d_map = readPFM(os.path.join(data_dir, f'TLD{i}.pfm'))

            H, W, C = Il.shape

            r = 10
            N = 1000
            count = 0
            d_ops_list = [-1, 0, 1]
            d_neg_list = []
            d_neg_list.extend(np.arange(-21, -10))
            d_neg_list.extend(np.arange(11, 22))
            while True:

                h = np.random.randint(r, H - r)
                w = np.random.randint(r, W - r)

                if l_d_map[h, w] == np.inf:
                    continue

                d = int(l_d_map[h, w])
                w_r = w - d

                # if r_d_map[h, w_r] == np.inf:
                # 	continue

                # if abs(r_d_map[h, w_r] - d) > 2:
                # 	continue

                ops_w_r = w_r + d_ops_list[np.random.randint(len(d_ops_list))]
                neg_w_r = w_r + d_neg_list[np.random.randint(len(d_neg_list))]

                if ops_w_r < r or ops_w_r > W - r - 1 or neg_w_r < r or neg_w_r > W - r - 1:
                    continue

                l_patch = Il[h - r:h + r + 1, w - r:w + r + 1]
                ops_r_patch = Ir[h - r:h + r + 1, ops_w_r - r:ops_w_r + r + 1]
                neg_r_patch = Ir[h - r:h + r + 1, neg_w_r - r:neg_w_r + r + 1]

                l_name = f'{total}_l.png'
                ops_r_name = f'{total}_ops_r.png'
                neg_r_name = f'{total}_neg_r.png'
                cv2.imwrite(os.path.join(output_dir, l_name), l_patch)
                cv2.imwrite(os.path.join(output_dir, ops_r_name), ops_r_patch)
                cv2.imwrite(os.path.join(output_dir, neg_r_name), neg_r_patch)

                print(f'{l_name},{ops_r_name},1', file=f)
                print(f'{l_name},{neg_r_name},0', file=f)

                count += 1
                total += 1
                if count >= N:
                    break
예제 #13
0
from util import cal_avgerr, readPFM

files = ['./synthe/TL{}_output_noad.pfm'.format(i) for i in range(10)]
gts = ['./data/Synthetic/TLD{}.pfm'.format(i) for i in range(10)]

total = 0
for idx, (f, g) in enumerate(zip(files, gts)):
    gt = readPFM(g)
    result = readPFM(f)

    err = cal_avgerr(gt, result)
    total += err
    print("{}:".format(idx), err)

print("Ave:", total / 10)
예제 #14
0
from util import cal_avgerr, readPFM
import sys
import argparse

if __name__ == '__main__':

    parser = argparse.ArgumentParser()
    parser.add_argument('--GT',
                        default='./data/Synthetic/TLD0.pfm',
                        type=str,
                        help='Ground Truth')
    parser.add_argument('--input',
                        default='./TL0.pfm',
                        type=str,
                        help='input disparity map')
    args = parser.parse_args()

    GT = readPFM(args.GT)
    disp = readPFM(args.input)

    print(cal_avgerr(GT, disp))
import os
import sys
import numpy as np
from util import cal_avgerr, readPFM

result_dir, gt_dir = sys.argv[1], sys.argv[2]
nums = [str(i) for i in range(10)]
with open('result.txt', 'w') as f:
    for num in nums:
        result = os.path.join(result_dir, 'TLD{}.pfm'.format(num))
        gt = os.path.join(gt_dir, 'TLD{}.pfm'.format(num))

        result = readPFM(result).reshape(196608)
        gt = readPFM(gt).reshape(196608)

        f.write(num + '\n')
        f.write(str(cal_avgerr(gt, result)) + '\n')
        #f.write('################################################################\n')
예제 #16
0
import cv2
from util import cal_avgerr, readPFM
import sys

# for finding the score, please try following
# python3 score.py data/Synthetic/TLD0.pfm result1/TL0.pfm

GT, disp = sys.argv[1], sys.argv[2]

GT = readPFM(str(GT))
disp = readPFM(str(disp))

print("average score:", cal_avgerr(GT, disp))