Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Get body parts coordinates? #262

Open
keko950 opened this issue Jan 23, 2020 · 2 comments
Open

Get body parts coordinates? #262

keko950 opened this issue Jan 23, 2020 · 2 comments

Comments

@keko950
Copy link

keko950 commented Jan 23, 2020

Is it possible to get the body parts coordinates? Im trying to get the head coordinates in order to check the view angle of the detected person. thanks

@rburchcp
Copy link

rburchcp commented Feb 28, 2023

I did it by inserting the following into densepose/vis/densepose_results.py

class DensePoseResultsVisualizer(object):
    def visualize(
        self,
        image_bgr: Image,
        results_and_boxes_xywh: Tuple[Optional[List[DensePoseChartResult]], Optional[Boxes]],
    ) -> Image:
    densepose_result, boxes_xywh = results_and_boxes_xywh #densepose_results returns type of torch.int64

    if densepose_result is None or boxes_xywh is None:
        return image_bgr
    

    patches = {"1":"Torso", "2":"Torso", "3":"Right Hand", "4":"Left Hand", "5":"Left Foot", "6":"Right Foot", "7":"Upper Leg Right", "9":"Upper Leg Right",
    "8":"Upper Leg Left", "10":"Upper Leg Left", "11":"Lower Leg Right", "13":"Lower Leg Right", "12":"Lower Leg Left", "14":"Lower Leg Left", 
    "15":"Upper Arm Left", "17":"Upper Arm Left", "16":"Upper Arm Right", "18":"Upper Arm Right", "19":"Lower Arm Left", "21":"Lower Arm Left",
    "20":"Lower Arm Right", "22":"Lower Arm Right", "23":"Head", "24":"Head"}

    num_labels = len(patches)

    random_colors = [(18, 183, 19), (129, 39, 86), (17, 165, 101), (5, 15, 245), (9, 50, 37), 
    (243, 78, 31), (106, 107, 176), (17, 47, 21), (33, 63, 159), (25, 23, 208), 
    (161, 173, 114), (222, 4, 152), (155, 94, 169), (104, 175, 169), (211, 93, 218), 
    (93, 172, 248), (9, 140, 53), (141, 145, 22), (141, 65, 196), (175, 198, 30), 
    (213, 133, 71), (118, 118, 134), (30, 236, 218), (118, 134, 187), (130, 47, 182)]

    selected = [*range(num_labels)] 
    for lbl in range(1, num_labels+1):
        lwi = densepose_result[0].labels == lbl
        indices = lwi.nonzero(as_tuple=True) 
        #indices is a tuple of tensors, ( tensor(row pixels), tensor(col pixels) ), for detected body parts. Pixels relative to bbox. 
        random_color = random_colors[lbl-1]

        if lbl in selected: #choose parts to find
            if indices[0].numel(): #if a surface patch has been detected
                part = patches[str(lbl)]
                rm = torch.mean(indices[0].float()).int().item() + boxes_xywh[0, 1].int().item()# row mean offset by bbox y
                cm = torch.mean(indices[1].float()).int().item() + boxes_xywh[0, 0].int().item()# col mean offset by bbox x
                org_circle = (cm, rm)
                print(f'{part} centroid located at {org_circle}'

    boxes_xywh = boxes_xywh.cpu().numpy() #etc...

@keko950
Copy link
Author

keko950 commented Mar 23, 2023

Bit late, but thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants