Skip to content

Commit

Permalink
Fixed inversed order in HPatches homography preprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
rpautrat committed Nov 6, 2019
1 parent 13c678d commit 163d030
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
11 changes: 2 additions & 9 deletions notebooks/visualize_hpatches.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {
"scrolled": false
},
Expand All @@ -68,7 +68,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {
"scrolled": false
},
Expand Down Expand Up @@ -285,13 +285,6 @@
" superimposed = cv2.addWeighted(img1, 0.5, warped_img0, 0.5, 0.)\n",
" plot_imgs([img0, img1, warped_img0, superimposed], titles=['image0', 'image1', 'warped image0', 'superimposed'], dpi=200, cmap='gray')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
14 changes: 7 additions & 7 deletions superpoint/datasets/patches_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,27 @@ def _adapt_homography_to_preprocessing(zip_data):

# Compute the scaling ratio due to the resizing for both images
s = tf.reduce_max(tf.divide(target_size, source_size))
up_scale = tf.diag(tf.stack([s, s, tf.constant(1.)]))
up_scale = tf.diag(tf.stack([1. / s, 1. / s, tf.constant(1.)]))
warped_s = tf.reduce_max(tf.divide(target_size, source_warped_size))
down_scale = tf.diag(tf.stack([1 / warped_s, 1 / warped_s, tf.constant(1.)]))
down_scale = tf.diag(tf.stack([warped_s, warped_s, tf.constant(1.)]))

# Compute the translation due to the crop for both images
pad_y = tf.to_int32(((source_size[0] * s - target_size[0]) / tf.constant(2.0)))
pad_x = tf.to_int32(((source_size[1] * s - target_size[1]) / tf.constant(2.0)))
translation = tf.stack([tf.constant(1), tf.constant(0), -pad_x,
tf.constant(0), tf.constant(1), -pad_y,
translation = tf.stack([tf.constant(1), tf.constant(0), pad_x,
tf.constant(0), tf.constant(1), pad_y,
tf.constant(0),tf.constant(0), tf.constant(1)])
translation = tf.to_float(tf.reshape(translation, [3,3]))
pad_y = tf.to_int32(((source_warped_size[0] * warped_s - target_size[0])
/ tf.constant(2.0)))
pad_x = tf.to_int32(((source_warped_size[1] * warped_s - target_size[1])
/ tf.constant(2.0)))
warped_translation = tf.stack([tf.constant(1), tf.constant(0), pad_x,
tf.constant(0), tf.constant(1), pad_y,
warped_translation = tf.stack([tf.constant(1), tf.constant(0), -pad_x,
tf.constant(0), tf.constant(1), -pad_y,
tf.constant(0),tf.constant(0), tf.constant(1)])
warped_translation = tf.to_float(tf.reshape(warped_translation, [3,3]))

H = translation @ up_scale @ H @ down_scale @ warped_translation
H = warped_translation @ down_scale @ H @ up_scale @ translation
return H

def _get_shape(image):
Expand Down

0 comments on commit 163d030

Please sign in to comment.