Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 78aaae7

Browse files
author
YaoYao
committed
fix the 0.5 error between image coordinate and pixel coordinate when applying tf transform for homography
1 parent 0dfdab5 commit 78aaae7

File tree

3 files changed

+54
-21
lines changed

3 files changed

+54
-21
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
* Enter the ``MVSNet/mvsnet`` folder, in ``test.py``, set ``pretrained_model_ckpt_path`` to ``MODEL_FOLDER/model.ckpt``
4242

4343
* To run MVSNet (GTX1080Ti):
44-
``python test.py --dense_folder /data/dtu/github_data/scan9/ --regularization '3DCNNs' --max_w 1152 --max_h 864 --max_d 192 --interval_scale 1.06``
44+
``python test.py --dense_folder TEST_DATA_FOLDER --regularization '3DCNNs' --max_w 1152 --max_h 864 --max_d 192 --interval_scale 1.06``
4545
* To run R-MVSNet (GTX1080Ti):
46-
``python test.py --dense_folder /data/dtu/github_data/scan9/ --regularization 'GRU' --max_w 1600 --max_h 1200 --max_d 256 --interval_scale 0.8``
46+
``python test.py --dense_folder TEST_DATA_FOLDER --regularization 'GRU' --max_w 1600 --max_h 1200 --max_d 256 --interval_scale 0.8``
4747
* Inspect the .pfm format outputs in ``TEST_DATA_FOLDER/depths_mvsnet`` using ``python visualize.py .pfm``. For example the depth map and probability map for image `00000012` should look like:
4848

4949
<img src="doc/image.png" width="250"> | <img src="doc/depth_example.png" width="250"> | <img src="doc/probability_example.png" width="250">
@@ -59,7 +59,7 @@ To run the post-processing:
5959
* Check out the modified version fusibile ```git clone https://github.com/YoYo000/fusibile```
6060
* Install fusibile by ```cmake .``` and ```make```, which will generate the executable at ``FUSIBILE_EXE_PATH``
6161
* Run post-processing:
62-
``python depthfusion.py --dense_folder TEST_DATA_FOLDER --fusibile_exe_path FUSIBILE_EXE_PATH``
62+
``python depthfusion.py --dense_folder TEST_DATA_FOLDER --fusibile_exe_path FUSIBILE_EXE_PATH --prob_threshold 0.3``
6363
* The final point cloud is stored in `TEST_DATA_FOLDER/points_mvsnet/consistencyCheck-TIME/final3d_model.ply`.
6464

6565
We observe that the point cloud output of ``depthfusion.py`` is very similar to our own implementation. For detailed differences, please refer to [MVSNet paper](https://arxiv.org/abs/1804.02505) and [Galliani's paper](https://www.cv-foundation.org/openaccess/content_iccv_2015/papers/Galliani_Massively_Parallel_Multiview_ICCV_2015_paper.pdf). The point cloud for `scan9` should look like:

mvsnet/homography_warping.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,49 @@ def homography_warping(input_image, homography):
200200

201201
# return input_image
202202
return warped_image
203+
def tf_transform_homography(input_image, homography):
204+
205+
# tf.contrib.image.transform is for pixel coordinate but our
206+
# homograph parameters are for image coordinate (x_p = x_i + 0.5).
207+
# So need to change the corresponding homography parameters
208+
homography = tf.reshape(homography, [-1, 9])
209+
a0 = tf.slice(homography, [0, 0], [-1, 1])
210+
a1 = tf.slice(homography, [0, 1], [-1, 1])
211+
a2 = tf.slice(homography, [0, 2], [-1, 1])
212+
b0 = tf.slice(homography, [0, 3], [-1, 1])
213+
b1 = tf.slice(homography, [0, 4], [-1, 1])
214+
b2 = tf.slice(homography, [0, 5], [-1, 1])
215+
c0 = tf.slice(homography, [0, 6], [-1, 1])
216+
c1 = tf.slice(homography, [0, 7], [-1, 1])
217+
c2 = tf.slice(homography, [0, 8], [-1, 1])
218+
a_0 = a0 - c0 / 2
219+
a_1 = a1 - c1 / 2
220+
a_2 = (a0 + a1) / 2 + a2 - (c0 + c1) / 4 - c2 / 2
221+
b_0 = b0 - c0 / 2
222+
b_1 = b1 - c1 / 2
223+
b_2 = (b0 + b1) / 2 + b2 - (c0 + c1) / 4 - c2 / 2
224+
c_0 = c0
225+
c_1 = c1
226+
c_2 = c2 + (c0 + c1) / 2
227+
homo = []
228+
homo.append(a_0)
229+
homo.append(a_1)
230+
homo.append(a_2)
231+
homo.append(b_0)
232+
homo.append(b_1)
233+
homo.append(b_2)
234+
homo.append(c_0)
235+
homo.append(c_1)
236+
homo.append(c_2)
237+
homography = tf.stack(homo, axis=1)
238+
homography = tf.reshape(homography, [-1, 9])
239+
240+
homography_linear = tf.slice(homography, begin=[0, 0], size=[-1, 8])
241+
homography_linear_div = tf.tile(tf.slice(homography, begin=[0, 8], size=[-1, 1]), [1, 8])
242+
homography_linear = tf.div(homography_linear, homography_linear_div)
243+
warped_image = tf.contrib.image.transform(
244+
input_image, homography_linear, interpolation='BILINEAR')
245+
246+
# return input_image
247+
return warped_image
203248

mvsnet/model.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
sys.path.append("../")
1313
from cnn_wrapper.mvsnet import *
1414
from convgru import ConvGRUCell
15-
from homography_warping import get_homographies, get_homographies_inv_depth, homography_warping
15+
from homography_warping import *
1616

1717
FLAGS = tf.app.flags.FLAGS
1818

@@ -108,7 +108,8 @@ def inference(images, cams, depth_num, depth_start, depth_interval, is_master_gp
108108
for view in range(0, FLAGS.view_num - 1):
109109
homography = tf.slice(view_homographies[view], begin=[0, d, 0, 0], size=[-1, 1, 3, 3])
110110
homography = tf.squeeze(homography, axis=1)
111-
warped_view_feature = homography_warping(view_towers[view].get_output(), homography)
111+
# warped_view_feature = homography_warping(view_towers[view].get_output(), homography)
112+
warped_view_feature = tf_transform_homography(view_towers[view].get_output(), homography)
112113
ave_feature = ave_feature + warped_view_feature
113114
ave_feature2 = ave_feature2 + tf.square(warped_view_feature)
114115
ave_feature = ave_feature / FLAGS.view_num
@@ -201,16 +202,8 @@ def body(view, ave_feature, ave_feature2):
201202
"""Loop body."""
202203
homography = tf.slice(view_homographies[view], begin=[0, d, 0, 0], size=[-1, 1, 3, 3])
203204
homography = tf.squeeze(homography, axis=1)
204-
205205
# warped_view_feature = homography_warping(view_features[view], homography)
206-
########## tf.contrib.image.transform #############
207-
homography = tf.reshape(homography, [-1, 9])
208-
homography_linear = tf.slice(homography, begin=[0, 0], size=[-1, 8])
209-
homography_linear_div = tf.tile(tf.slice(homography, begin=[0, 8], size=[-1, 1]), [1, 8])
210-
homography_linear = tf.div(homography_linear, homography_linear_div)
211-
warped_view_feature = tf.contrib.image.transform(
212-
view_features[view], homography_linear, interpolation='BILINEAR')
213-
206+
warped_view_feature = tf_transform_homography(view_features[view], homography)
214207
ave_feature = tf.assign_add(ave_feature, warped_view_feature)
215208
ave_feature2 = tf.assign_add(ave_feature2, tf.square(warped_view_feature))
216209
view = tf.add(view, 1)
@@ -327,13 +320,8 @@ def body(depth_index, state1, state2, state3, depth_image, max_prob_image, exp_s
327320
homographies = view_homographies[view]
328321
homographies = tf.transpose(homographies, perm=[1, 0, 2, 3])
329322
homography = homographies[depth_index]
330-
homography = tf.reshape(homography, [-1, 9])
331-
homography_linear = tf.slice(homography, begin=[0, 0], size=[-1, 8])
332-
homography_linear_div = tf.tile(tf.slice(homography, begin=[0, 8], size=[-1, 1]), [1, 8])
333-
homography_linear = tf.div(homography_linear, homography_linear_div)
334-
warped_view_feature = tf.contrib.image.transform(
335-
view_towers[view].get_output(), homography_linear, interpolation='BILINEAR')
336-
323+
# warped_view_feature = homography_warping(view_towers[view].get_output(), homography)
324+
warped_view_feature = tf_transform_homography(view_towers[view].get_output(), homography)
337325
ave_feature = ave_feature + warped_view_feature
338326
ave_feature2 = ave_feature2 + tf.square(warped_view_feature)
339327
ave_feature = ave_feature / FLAGS.view_num

0 commit comments

Comments
 (0)