Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

fix lint test

edgarriba418c778e0a64
diff --git a/test/test_imgwarp.py b/test/test_imgwarp.py
index c11bb9502..25dcb17ab 100644
--- a/test/test_imgwarp.py
+++ b/test/test_imgwarp.py
@@ -149,7 +149,7 @@ class Tester(unittest.TestCase):
# compute transform from source to target
res = gradcheck(tgm.get_perspective_transform,
- (points_src, points_dst,), raise_exception=True)
+ (points_src, points_dst,), raise_exception=True)
self.assertTrue(res)
diff --git a/torchgeometry/imgwarp.py b/torchgeometry/imgwarp.py
index a4188558d..100067fd1 100644
--- a/torchgeometry/imgwarp.py
+++ b/torchgeometry/imgwarp.py
@@ -131,22 +131,27 @@ def get_perspective_transform(src, dst):
if not src.shape == dst.shape:
raise ValueError("Inputs must have the same shape. Got {}"
.format(dst.shape))
+ if not (src.shape[0] == dst.shape[0]):
+ raise ValueError("Inputs must have same batch size dimension. Got {}"
+ .format(src.shape, dst.shape))
+
def ax(p, q):
ones = torch.ones_like(p)[..., 0:1]
zeros = torch.zeros_like(p)[..., 0:1]
return torch.cat(
- [ p[:, 0:1], p[:, 1:2], ones, zeros, zeros, zeros,
- -p[:, 0:1] * q[:, 0:1], -p[:, 1:2] * q[:, 0:1] ], dim=1)
+ [p[:, 0:1], p[:, 1:2], ones, zeros, zeros, zeros,
+ -p[:, 0:1] * q[:, 0:1], -p[:, 1:2] * q[:, 0:1]
+ ], dim=1)
def ay(p, q):
ones = torch.ones_like(p)[..., 0:1]
zeros = torch.zeros_like(p)[..., 0:1]
return torch.cat(
- [ zeros, zeros, zeros, p[:, 0:1], p[:, 1:2], ones,
- -p[:, 0:1] * q[:, 1:2], -p[:, 1:2] * q[:, 1:2] ], dim=1)
+ [zeros, zeros, zeros, p[:, 0:1], p[:, 1:2], ones,
+ -p[:, 0:1] * q[:, 1:2], -p[:, 1:2] * q[:, 1:2]], dim=1)
# we build matrix A by using only 4 point correspondence. The linear
- # system is solved with the least square method, so here
- # we could even pass more correspondence
+ # system is solved with the least square method, so here
+ # we could even pass more correspondence
p = []
p.append(ax(src[:, 0], dst[:, 0]))
p.append(ay(src[:, 0], dst[:, 0]))