Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This is an unofficial Pytorch implementation of MVSNet
### Environment
* python 3.6 (Anaconda)
* pytorch 1.0.1
* `pip install -r requirements.txt`

### Training

Expand All @@ -23,6 +24,14 @@ This is an unofficial Pytorch implementation of MVSNet
* in ``test.sh``, set ``DTU_TESTING`` as your testing data path and ``CKPT_FILE`` as your checkpoint file. You can also download my [pretrained model](https://drive.google.com/file/d/1j2I_LNKb9JeCl6wdA7hh8z1WgVQZfLU9/view?usp=sharing).
* Test MVSNet: ``./test.sh``

### Depthmap Visualization

<img src="doc/rgb.jpg" width="250"> | <img src="doc/depthmap.png" width="250"> | <img src="doc/depthmap.jpg" width="250">
:---------------------------------------:|:---------------------------------------:|:---------------------------------------:
reference image |depth map (matplotlib) | depth map (opencv)

Visualize the estimated depth map using `python visualize.py xxx.pfm`

### Fusion

in ``eval.py``, I implemented a simple version of depth map fusion. Welcome contributions to improve the code.
Expand All @@ -36,3 +45,7 @@ in ``eval.py``, I implemented a simple version of depth map fusion. Welcome cont
| PyTorch-MVSNet(D=192) | 0.4492 | 0.3796 | 0.4144 |

Due to the memory limit, we only train the model with ``D=192``, the fusion code is also different from the original repo.

### TODO
1. add dataloader for [blendedmvs dataset](https://github.com/YoYo000/BlendedMVS)
2. using [fusibile of mvsnet version](https://github.com/XYZ-qiyh/fusibile-mvsnet)
Binary file added doc/depthmap.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/depthmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/rgb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
opencv-python
plyfile
matplotlib
tensorboardX
36 changes: 36 additions & 0 deletions tools/fusibile_to_dtu_eval.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Convert output of fusibile to DTU evaluation format.
# By: Jiayu Yang
# Date: 2020-03-30

import os
from os import listdir

fusibile_out_folder="../outputs-dtu/"
dtu_eval_folder="../outputs-dtu/"

if not os.path.isdir(dtu_eval_folder):
os.mkdir(dtu_eval_folder)

scans = ["scan1", "scan4", "scan9", "scan10", "scan11",
"scan12", "scan13", "scan15", "scan23", "scan24",
"scan29", "scan32", "scan33", "scan34", "scan48",
"scan49", "scan62", "scan75", "scan77", "scan110",
"scan114", "scan118"]

for scan in scans:
# Move ply to dtu eval folder and rename
scan_folder = os.path.join(fusibile_out_folder, scan, "points_mvsnet")
consis_folders = [f for f in listdir(scan_folder) if f.startswith('consistencyCheck-')]

consis_folders.sort()
consis_folder = consis_folders[-1]
source_ply = os.path.join(fusibile_out_folder, scan, "points_mvsnet", consis_folder, 'final3d_model.ply')
#print("source :{}".format(source_ply))
#source_ply = os.path.join(fusibile_out_folder,scan,'consistencyCheck/final3d_model.ply')
scan_idx = int(scan[4:])
target_ply = os.path.join(dtu_eval_folder,'mvsnet{:03d}_l3.ply'.format(scan_idx))

cmd = 'mv '+source_ply+' '+target_ply

print(cmd)
os.system(cmd)
39 changes: 39 additions & 0 deletions tools/gray2color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import numpy as np
import cv2
import argparse

import sys
sys.path.append("../datasets")
from data_io import read_pfm#, write_depth_img


def write_depth_img(filename, depth_image):
# Mask the array where equal to a given value
ma = np.ma.masked_equal(depth_image, 0.0, copy=False)
d_min = ma.min()
d_max = ma.max()
depth_n = 255.0 * (depth_image - d_min) / (d_max - d_min) # depth map normalize
depth_n = depth_n.astype(np.uint8)
out_depth_image = cv2.applyColorMap(depth_n, cv2.COLORMAP_JET) # applyColorMap
cv2.imwrite(filename, out_depth_image)


if __name__ == "__main__":
# parse argument
parser = argparse.ArgumentParser()
parser.add_argument("depth_path")
args = parser.parse_args()
depth_path = args.depth_path

# read_pfm
depth_map, _ = read_pfm(depth_path)
print('depth shape: {}'.format(depth_map.shape))

## photometric filter
#if False:
# pfm_prob_path = depth_path.replace("depth_est", "confidence")
# prob_map, _ = read_pfm(pfm_prob_path)
# depth_map[prob_map < 0.9] = 0

# gray2color
write_depth_img(depth_path.replace(".pfm", ".jpg"), depth_map)
33 changes: 33 additions & 0 deletions tools/visualize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import numpy as np
import cv2
import argparse
import matplotlib.pyplot as plt

import sys
sys.path.append("../datasets")
from data_io import read_pfm

if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('depth_path')
args = parser.parse_args()
depth_path = args.depth_path
if depth_path.endswith('npy'):
depth_image = np.load(depth_path)
depth_image = np.squeeze(depth_image)
print('value range: ', depth_image.min(), depth_image.max())
plt.imshow(depth_image, 'rainbow')
plt.show()
elif depth_path.endswith('pfm'):
depth_image, _ = read_pfm(depth_path)
print('depth shape: {}'.format(depth_image.shape))
ma = np.ma.masked_equal(depth_image, 0.0, copy=False)
print('value range: ', ma.min(), ma.max())
plt.imshow(depth_image, 'rainbow')
plt.show()
else:
depth_image = cv2.imread(depth_path)
ma = np.ma.masked_equal(depth_image, 0.0, copy=False)
print('value range: ', ma.min(), ma.max())
plt.imshow(depth_image)
plt.show()
36 changes: 36 additions & 0 deletions tools/visualize_save.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import numpy as np
import cv2
import argparse
import matplotlib.pyplot as plt

import sys
sys.path.append("../datasets")
from data_io import read_pfm

if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('depth_path')
args = parser.parse_args()
depth_path = args.depth_path
if depth_path.endswith('npy'):
depth_image = np.load(depth_path)
depth_image = np.squeeze(depth_image)
print('value range: ', depth_image.min(), depth_image.max())
plt.imshow(depth_image, 'rainbow')
plt.show()
elif depth_path.endswith('pfm'):
depth_image, _ = read_pfm(depth_path)
print('depth shape: {}'.format(depth_image.shape))
ma = np.ma.masked_equal(depth_image, 0.0, copy=False)
print('value range: ', ma.min(), ma.max())
plt.imshow(depth_image, 'rainbow')
# plt.show()
plt.axis('off')
out_filename = depth_path.replace(".pfm", ".png")
plt.savefig(out_filename, bbox_inches='tight', pad_inches=0, dpi=300)
else:
depth_image = cv2.imread(depth_path)
ma = np.ma.masked_equal(depth_image, 0.0, copy=False)
print('value range: ', ma.min(), ma.max())
plt.imshow(depth_image)
plt.show()