-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.py
34 lines (25 loc) · 1018 Bytes
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import cv2
import numpy as np
from daug.transforms import build_transformation_matrix
# TODO: test shear, flip, and translate
def run_rotation_scale_tests(n=10):
heights = np.random.randint(16, 512, size=n)
widths = np.random.randint(16, 512, size=n)
thetas = (2 * np.pi) * np.random.random(n)
scales = np.random.random(n)
for i in range(n):
theta, scale = thetas[i], scales[i]
height, width = heights[i], widths[i]
# getRotMat2D only supports isotropic scaling
L = cv2.getRotationMatrix2D(
(height / 2, width / 2), 180. / np.pi * theta, scale)
M = build_transformation_matrix(
(height, width), theta=theta, stretch=(scale, scale))
assert np.allclose(L, M[:2, :]), (
'OpenCV transformation matrix:\n'
'%r,\nbut Daug transformation matrix:\n%r' % (L, M[:2, :]))
print('All rotation/scale tests passed.')
def main():
run_rotation_scale_tests(n=10)
if __name__ == '__main__':
main()