forked from mdbloice/Augmentor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_rotate.py
55 lines (36 loc) · 1.2 KB
/
test_rotate.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import sys
sys.path.insert(0, os.path.abspath('.'))
import tempfile
import shutil
from PIL import Image
from Augmentor import Operations
def rotate_images(tmpdir, rot):
original_dimensions = (800, 800)
im_tmp = tmpdir.mkdir("subfolder").join('test.JPEG')
im = Image.new('RGB', original_dimensions)
im.save(str(im_tmp), 'JPEG')
r = Operations.Rotate(probability=1, rotation=rot)
im = [im]
im_r = r.perform_operation(im)
assert im_r is not None
assert im_r[0].size == original_dimensions
def test_rotate_images_90(tmpdir):
rotate_images(tmpdir, 90)
def test_rotate_images_180(tmpdir):
rotate_images(tmpdir, 180)
def test_rotate_images_270(tmpdir):
rotate_images(tmpdir, 270)
def test_rotate_images_custom_temp_files():
original_dimensions = (800, 800)
tmpdir = tempfile.mkdtemp()
tmp = tempfile.NamedTemporaryFile(dir=tmpdir, suffix='.JPEG')
im = Image.new('RGB', original_dimensions)
im.save(tmp.name, 'JPEG')
r = Operations.Rotate(probability=1, rotation=90)
im = [im]
im_r = r.perform_operation(im)
assert im_r is not None
assert im_r[0].size == original_dimensions
tmp.close()
shutil.rmtree(tmpdir)