File size: 3,248 Bytes
b5ba7a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import unittest
import numpy as np

import importlib
utils = importlib.import_module('extensions.sd-webui-controlnet.tests.utils', 'utils')
utils.setup_test_env()

from annotator.openpose.util import faceDetect, handDetect
from annotator.openpose.body import Keypoint, BodyResult

class TestFaceDetect(unittest.TestCase):
    def test_no_faces(self):
        oriImg = np.zeros((100, 100, 3), dtype=np.uint8)
        body = BodyResult([None] * 18, total_score=3, total_parts=0)
        expected_result = None
        result = faceDetect(body, oriImg)

        self.assertEqual(result, expected_result)

    def test_single_face(self):
        body = BodyResult([
            Keypoint(50, 50),
            *([None] * 13),
            Keypoint(30, 40),
            Keypoint(70, 40),
            Keypoint(20, 50),
            Keypoint(80, 50),
        ], total_score=2, total_parts=5)

        oriImg = np.zeros((100, 100, 3), dtype=np.uint8)

        expected_result = (0, 0, 120)
        result = faceDetect(body, oriImg)

        self.assertEqual(result, expected_result)

class TestHandDetect(unittest.TestCase):
    def test_no_hands(self):
        oriImg = np.zeros((100, 100, 3), dtype=np.uint8)
        body = BodyResult([None] * 18, total_score=3, total_parts=0)
        expected_result = []
        result = handDetect(body, oriImg)

        self.assertEqual(result, expected_result)

    def test_single_left_hand(self):
        oriImg = np.zeros((100, 100, 3), dtype=np.uint8)

        body = BodyResult([
            None, None, None, None, None,
            Keypoint(20, 20),
            Keypoint(40, 30),
            Keypoint(60, 40),
            *([None] * 8),
            Keypoint(20, 60),
            Keypoint(40, 70),
            Keypoint(60, 80)
        ], total_score=3, total_parts=0.5)

        expected_result = [(49, 26, 33, True)]
        result = handDetect(body, oriImg)

        self.assertEqual(result, expected_result)

    def test_single_right_hand(self):
        oriImg = np.zeros((100, 100, 3), dtype=np.uint8)

        body = BodyResult([
            None, None,
            Keypoint(20, 20),
            Keypoint(40, 30),
            Keypoint(60, 40),
            *([None] * 11),
            Keypoint(20, 60),
            Keypoint(40, 70),
            Keypoint(60, 80)
        ], total_score=3, total_parts=0.5)

        expected_result = [(49, 26, 33, False)]
        result = handDetect(body, oriImg)

        self.assertEqual(result, expected_result)

    def test_multiple_hands(self):
        body = BodyResult([
            Keypoint(20, 20),
            Keypoint(40, 30),
            Keypoint(60, 40),
            Keypoint(20, 60),
            Keypoint(40, 70),
            Keypoint(60, 80),
            Keypoint(10, 10),
            Keypoint(30, 20),
            Keypoint(50, 30),
            Keypoint(10, 50),
            Keypoint(30, 60),
            Keypoint(50, 70),
            *([None] * 6),
        ], total_score=3, total_parts=0.5)

        oriImg = np.zeros((100, 100, 3), dtype=np.uint8)

        expected_result = [(0, 0, 100, True), (16, 43, 56, False)]
        result = handDetect(body, oriImg)
        self.assertEqual(result, expected_result)


if __name__ == '__main__':
    unittest.main()