"vscode:/vscode.git/clone" did not exist on "e1267a9acf2a361dbdb9ff3eb5e37079736b4935"
test_structures.py 882 Bytes
Newer Older
limm's avatar
limm committed
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
# Copyright (c) Facebook, Inc. and its affiliates.

import unittest

from densepose.structures import normalized_coords_transform


class TestStructures(unittest.TestCase):
    def test_normalized_coords_transform(self):
        bbox = (32, 24, 288, 216)
        x0, y0, w, h = bbox
        xmin, ymin, xmax, ymax = x0, y0, x0 + w, y0 + h
        f = normalized_coords_transform(*bbox)
        # Top-left
        expected_p, actual_p = (-1, -1), f((xmin, ymin))
        self.assertEqual(expected_p, actual_p)
        # Top-right
        expected_p, actual_p = (1, -1), f((xmax, ymin))
        self.assertEqual(expected_p, actual_p)
        # Bottom-left
        expected_p, actual_p = (-1, 1), f((xmin, ymax))
        self.assertEqual(expected_p, actual_p)
        # Bottom-right
        expected_p, actual_p = (1, 1), f((xmax, ymax))
        self.assertEqual(expected_p, actual_p)