From 22eb5d19434dc89cb7eb2228a78ec9488028ff7d Mon Sep 17 00:00:00 2001 From: Bart Trzynadlowski Date: Thu, 4 Nov 2021 21:35:28 -0700 Subject: [PATCH] Use tuples rather than sets in order to preserve connection ordering --- .../python/solutions/face_mesh_connections.py | 85 +++++++++---------- 1 file changed, 42 insertions(+), 43 deletions(-) diff --git a/mediapipe/python/solutions/face_mesh_connections.py b/mediapipe/python/solutions/face_mesh_connections.py index 1ebd541df..26874bf14 100644 --- a/mediapipe/python/solutions/face_mesh_connections.py +++ b/mediapipe/python/solutions/face_mesh_connections.py @@ -13,58 +13,57 @@ # limitations under the License. """MediaPipe FaceMesh connections.""" -FACEMESH_LIPS = frozenset([(61, 146), (146, 91), (91, 181), (181, 84), (84, 17), - (17, 314), (314, 405), (405, 321), (321, 375), - (375, 291), (61, 185), (185, 40), (40, 39), (39, 37), - (37, 0), (0, 267), - (267, 269), (269, 270), (270, 409), (409, 291), - (78, 95), (95, 88), (88, 178), (178, 87), (87, 14), - (14, 317), (317, 402), (402, 318), (318, 324), - (324, 308), (78, 191), (191, 80), (80, 81), (81, 82), - (82, 13), (13, 312), (312, 311), (311, 310), - (310, 415), (415, 308)]) +FACEMESH_LIPS = ((61, 146), (146, 91), (91, 181), (181, 84), (84, 17), + (17, 314), (314, 405), (405, 321), (321, 375), + (375, 291), (61, 185), (185, 40), (40, 39), (39, 37), + (37, 0), (0, 267), + (267, 269), (269, 270), (270, 409), (409, 291), + (78, 95), (95, 88), (88, 178), (178, 87), (87, 14), + (14, 317), (317, 402), (402, 318), (318, 324), + (324, 308), (78, 191), (191, 80), (80, 81), (81, 82), + (82, 13), (13, 312), (312, 311), (311, 310), + (310, 415), (415, 308)) -FACEMESH_LEFT_EYE = frozenset([(263, 249), (249, 390), (390, 373), (373, 374), - (374, 380), (380, 381), (381, 382), (382, 362), - (263, 466), (466, 388), (388, 387), (387, 386), - (386, 385), (385, 384), (384, 398), (398, 362)]) +FACEMESH_LEFT_EYE = ((263, 249), (249, 390), (390, 373), (373, 374), + (374, 380), (380, 381), (381, 382), (382, 362), + (263, 466), (466, 388), (388, 387), (387, 386), + (386, 385), (385, 384), (384, 398), (398, 362)) -FACEMESH_LEFT_IRIS = frozenset([(474, 475), (475, 476), (476, 477), - (477, 474)]) +FACEMESH_LEFT_IRIS = ((474, 475), (475, 476), (476, 477), + (477, 474)) -FACEMESH_LEFT_EYEBROW = frozenset([(276, 283), (283, 282), (282, 295), - (295, 285), (300, 293), (293, 334), - (334, 296), (296, 336)]) +FACEMESH_LEFT_EYEBROW = ((276, 283), (283, 282), (282, 295), + (295, 285), (300, 293), (293, 334), + (334, 296), (296, 336)) -FACEMESH_RIGHT_EYE = frozenset([(33, 7), (7, 163), (163, 144), (144, 145), - (145, 153), (153, 154), (154, 155), (155, 133), - (33, 246), (246, 161), (161, 160), (160, 159), - (159, 158), (158, 157), (157, 173), (173, 133)]) +FACEMESH_RIGHT_EYE = ((33, 7), (7, 163), (163, 144), (144, 145), + (145, 153), (153, 154), (154, 155), (155, 133), + (33, 246), (246, 161), (161, 160), (160, 159), + (159, 158), (158, 157), (157, 173), (173, 133)) -FACEMESH_RIGHT_EYEBROW = frozenset([(46, 53), (53, 52), (52, 65), (65, 55), - (70, 63), (63, 105), (105, 66), (66, 107)]) +FACEMESH_RIGHT_EYEBROW = ((46, 53), (53, 52), (52, 65), (65, 55), + (70, 63), (63, 105), (105, 66), (66, 107)) -FACEMESH_RIGHT_IRIS = frozenset([(469, 470), (470, 471), (471, 472), - (472, 469)]) +FACEMESH_RIGHT_IRIS = ((469, 470), (470, 471), (471, 472), + (472, 469)) -FACEMESH_FACE_OVAL = frozenset([(10, 338), (338, 297), (297, 332), (332, 284), - (284, 251), (251, 389), (389, 356), (356, 454), - (454, 323), (323, 361), (361, 288), (288, 397), - (397, 365), (365, 379), (379, 378), (378, 400), - (400, 377), (377, 152), (152, 148), (148, 176), - (176, 149), (149, 150), (150, 136), (136, 172), - (172, 58), (58, 132), (132, 93), (93, 234), - (234, 127), (127, 162), (162, 21), (21, 54), - (54, 103), (103, 67), (67, 109), (109, 10)]) +FACEMESH_FACE_OVAL = ((10, 338), (338, 297), (297, 332), (332, 284), + (284, 251), (251, 389), (389, 356), (356, 454), + (454, 323), (323, 361), (361, 288), (288, 397), + (397, 365), (365, 379), (379, 378), (378, 400), + (400, 377), (377, 152), (152, 148), (148, 176), + (176, 149), (149, 150), (150, 136), (136, 172), + (172, 58), (58, 132), (132, 93), (93, 234), + (234, 127), (127, 162), (162, 21), (21, 54), + (54, 103), (103, 67), (67, 109), (109, 10)) -FACEMESH_CONTOURS = frozenset().union(*[ - FACEMESH_LIPS, FACEMESH_LEFT_EYE, FACEMESH_LEFT_EYEBROW, FACEMESH_RIGHT_EYE, - FACEMESH_RIGHT_EYEBROW, FACEMESH_FACE_OVAL -]) +FACEMESH_CONTOURS = \ + FACEMESH_LIPS + FACEMESH_LEFT_EYE + FACEMESH_LEFT_EYEBROW + FACEMESH_RIGHT_EYE + \ + FACEMESH_RIGHT_EYEBROW+ FACEMESH_FACE_OVAL -FACEMESH_IRISES = frozenset().union(*[FACEMESH_LEFT_IRIS, FACEMESH_RIGHT_IRIS]) +FACEMESH_IRISES = FACEMESH_LEFT_IRIS + FACEMESH_RIGHT_IRIS -FACEMESH_TESSELATION = frozenset([ +FACEMESH_TESSELATION = ( (127, 34), (34, 139), (139, 127), (11, 0), (0, 37), (37, 11), (232, 231), (231, 120), (120, 232), (72, 37), (37, 39), (39, 72), (128, 121), (121, 47), (47, 128), (232, 121), (121, 128), (128, 232), @@ -490,4 +489,4 @@ FACEMESH_TESSELATION = frozenset([ (437, 343), (343, 399), (399, 437), (344, 360), (360, 440), (440, 344), (420, 437), (437, 456), (456, 420), (360, 420), (420, 363), (363, 360), (361, 401), (401, 288), (288, 361), (265, 372), (372, 353), (353, 265), - (390, 339), (339, 249), (249, 390), (339, 448), (448, 255), (255, 339)]) + (390, 339), (339, 249), (249, 390), (339, 448), (448, 255), (255, 339))