forked from HumanSignal/labelImg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_io.py
32 lines (26 loc) · 1.11 KB
/
test_io.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
from unittest import TestCase
import sys
import os
class TestPascalVocRW(TestCase):
def test_upper(self):
dir_name = os.path.abspath(os.path.dirname(__file__))
libs_path = os.path.join(dir_name, '..', 'libs')
sys.path.insert(0, libs_path)
from pascal_voc_io import PascalVocWriter
from pascal_voc_io import PascalVocReader
# Test Write/Read
writer = PascalVocWriter('tests', 'test', (512, 512, 1), localImgPath='tests/test.bmp')
difficult = 1
writer.addBndBox(60, 40, 430, 504, 'person', difficult)
writer.addBndBox(113, 40, 450, 403, 'face', difficult)
writer.save('tests/test.xml')
reader = PascalVocReader('tests/test.xml')
shapes = reader.getShapes()
personBndBox = shapes[0]
face = shapes[1]
self.assertEqual(personBndBox[0], 'person')
self.assertEqual(personBndBox[1], [(60, 40), (430, 40), (430, 504), (60, 504)])
self.assertEqual(face[0], 'face')
self.assertEqual(face[1], [(113, 40), (450, 40), (450, 403), (113, 403)])
if __name__ == '__main__':
unittest.main()