Skip to main content
  1. About
  2. For Teams
Asked
Viewed 75 times
0

Given:

[{'chin': [(297, 322), (297, 339), (299, 356), (301, 373), (305, 390), (312, 405), (325, 415), (342, 418),
                 (362, 420), (383, 421), (402, 421), (418, 415), (427, 403), (433, 387), (437, 370), (440, 352),
                 (443, 335)],
        'left_eyebrow': [(306, 296), (313, 282), (326, 276), (342, 276), (357, 281)],
        'right_eyebrow': [(378, 283), (393, 278), (410, 281), (423, 289), (431, 303)],
        'nose_bridge': [(366, 297), (365, 305), (364, 314), (363, 323)],
        'nose_tip': [(347, 337), (355, 340), (364, 341), (373, 340), (382, 339)],
        'left_eye': [(321, 304), (328, 296), (339, 296), (349, 304), (339, 305), (328, 305)],
        'right_eye': [(386, 307), (397, 299), (407, 300), (415, 309), (407, 309), (396, 308)],
        'top_lip': [(332, 363), (343, 355), (355, 351), (363, 353), (372, 352), (385, 357), (399, 366), (394, 365),
                    (372, 359), (363, 359), (355, 359), (337, 362)],
        'bottom_lip': [(399, 366), (385, 368), (372, 369), (363, 369), (354, 368), (343, 366), (332, 363), (337, 362),
                       (354, 360), (363, 361), (372, 361), (394, 365)]}]

I want to get all the values of coordinates, removing the chin, etc. just co-ordinates like (297, 322)

0

4 Answers 4

1

You can loop through your lst element and then find the values of the dictionaries it contains like this:

coords = []
for d in lst:
    coord.append(d.values())

print(coords)
Sign up to request clarification or add additional context in comments.

Comments

0

This becomes a lot easier if the code is formatted correctly:

lst = [
    {
        'chin': [
            (297, 322), (297, 339), (299, 356), (301, 373), (305, 390), (312, 405), (325, 415), (342, 418), (362, 420), (383, 421), (402, 421), (418, 415), (427, 403), (433, 387), (437, 370), (440, 352), (443, 335)
        ],
        'left_eyebrow': [
            (306, 296), (313, 282), (326, 276), (342, 276), (357, 281)
        ],
        'right_eyebrow': [
            (378, 283), (393, 278), (410, 281), (423, 289), (431, 303)
        ],
        'nose_bridge': [
            (366, 297), (365, 305), (364, 314), (363, 323)
        ],
        'nose_tip': [
            (347, 337), (355, 340), (364, 341), (373, 340), (382, 339)
        ],
        'left_eye': [
            (321, 304), (328, 296), (339, 296), (349, 304), (339, 305), (328, 305)
        ],
        'right_eye': [
            (386, 307), (397, 299), (407, 300), (415, 309), (407, 309), (396, 308)
        ],
        'top_lip': [
            (332, 363), (343, 355), (355, 351), (363, 353), (372, 352), (385, 357), (399, 366), (394, 365), (372, 359), (363, 359), (355, 359), (337, 362)
        ],
        'bottom_lip': [
            (399, 366), (385, 368), (372, 369), (363, 369), (354, 368), (343, 366), (332, 363), (337, 362), (354, 360), (363, 361), (372, 361), (394, 365)
        ]
    }
]

It's a list containing a dictionary where the value of each key is a list of tuples.

for k in lst[0].keys():
    print(lst[0][k])

To skip chin:

for k in lst[0].keys():
    if k == "chin":
        continue

    print(lst[0][k])

3 Comments

I think the idea was to not include the string chin, not to ignore the coordinates assigned to chin.
@ScottHunter I believe that's one of many valid interpretations of the question.. ;)
Hence I think.
0

you can do this: first, separate all co-ordinates assigned to the chin, eye, ...etc, and append in a separate array.

then loop through all the arrays present in a single array put it in another array. now the final array is ready to use.

test = []
for a in landmark[0]:
    test.append(landmark[0][a])

final = []
for a in range(0, 17):
    final.append(test[0][a])

for b in range(1, 3):
    for a in range(0, 5):
        final.append(test[b][a])

for a in range(0, 4):
    final.append(test[3][a])

for a in range(0, 5):
    final.append(test[4][a])

for b in range(5, 7):
    for a in range(0, 6):
        final.append(test[b][a])

for b in range(7, 9):
    for a in range(0, 12):
        final.append(test[b][a])

length = len(final)
print(final)

Comments

0
co_ordinates = []

for rec in you_data:
    for data in rec:
        co_ordinates.extend(rec[data])

Output:
[(297, 322), (297, 339), (299, 356), (301, 373), (305, 390), (312, 405), (325, 415), (342, 418), (362, 420), (383, 421), (402, 421), (418, 415), (427, 403), (433, 387), (437, 370), (440, 352), (443, 335), (306, 296), (313, 282), (326, 276), (342, 276), (357, 281), (378, 283), (393, 278), (410, 281), (423, 289), (431, 303), (366, 297), (365, 305), (364, 314), (363, 323), (347, 337), (355, 340), (364, 341), (373, 340), (382, 339), (321, 304), (328, 296), (339, 296), (349, 304), (339, 305), (328, 305), (386, 307), (397, 299), (407, 300), (415, 309), (407, 309), (396, 308), (332, 363), (343, 355), (355, 351), (363, 353), (372, 352), (385, 357), (399, 366), (394, 365), (372, 359), (363, 359), (355, 359), (337, 362), (399, 366), (385, 368), (372, 369), (363, 369), (354, 368), (343, 366), (332, 363), (337, 362), (354, 360), (363, 361), (372, 361), (394, 365)]

Comments

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.