def get_face_parts(model='COCO'):
    if model == 'COCO':
        return [
            HKP.Value('NOSE'),
            HKP.Value('LEFT_EYE'),
            HKP.Value('LEFT_EAR'),
            HKP.Value('RIGHT_EYE'),
            HKP.Value('RIGHT_EAR')
        ]
    elif model == 'MPI':
        # TODO
        return []
    else:
        return []
Пример #2
0
def data_frame_to_object_annotations(annotations,
                                     model,
                                     has_z=False,
                                     frame_id=0,
                                     resolution=None):

    is_valid_model(model)

    if annotations.empty:
        return ObjectAnnotations()

    n_model_joints = int(model.strip('joints'))
    joints_values = len(
        annotations.drop(['sample_id', 'person_id'], axis=1).columns)
    n_annotations_joints = int(joints_values / (4 if has_z else 3))
    n_joints = min(n_model_joints, n_annotations_joints)

    annotations_pb = ObjectAnnotations()
    annotations_pb.frame_id = frame_id
    if resolution is not None:
        annotations_pb.resolution.width = resolution[0]
        annotations_pb.resolution.height = resolution[1]

    for _, annotation in annotations.iterrows():
        skeleton = annotations_pb.objects.add()
        skeleton.id = int(annotation['person_id'])

        for joint_id in range(n_joints):
            x = annotation['j{:d}x'.format(joint_id)]
            y = annotation['j{:d}y'.format(joint_id)]
            z = annotation['j{:d}z'.format(joint_id)] if has_z else 0.0
            c = annotation['j{:d}c'.format(joint_id)]
            human_keypoint = index_to_human_keypoint(joint_id, model)

            # check for invalid joint
            if (x == 0.0 and y == 0.0 and z == 0.0) or c < 0.0:
                continue

            if human_keypoint == HKP.Value('UNKNOWN_HUMAN_KEYPOINT'):
                continue

            keypoint = skeleton.keypoints.add()
            keypoint.position.x = x
            keypoint.position.y = y
            keypoint.position.z = z
            keypoint.score = c
            keypoint.id = human_keypoint

    return annotations_pb
Пример #3
0
def joints_to_object_annotation(joints, model, valid_joints=None):
    ob = ObjectAnnotation()
    if joints.shape[0] < 2 or joints.shape[0] > 3:
        return ob
    is_3d = joints.shape[0] == 3
    model = model.lower()
    if model == 'coco':
        n_joints = 19
        PB_PARTS = COCO_PB_PARTS
    elif model == 'mpii':
        n_joints = 15
        PB_PARTS = MPII_PB_PARTS
    else:
        __raise_wrong_model__()

    if joints.shape[1] != n_joints:
        raise Exception('Invalid number of joints for this model.')

    invalid_joints = np.zeros(n_joints, dtype=bool)
    for c in range(n_joints):
        if isinstance(valid_joints, np.ndarray) and not valid_joints[c]:
            invalid_joints[c] = True
            continue
        human_keypoint = PB_PARTS[c]
        if human_keypoint == HumanKeypoints.Value('UNKNOWN_HUMAN_KEYPOINT'):
            invalid_joints[c] = True
            continue
        x, y, z = joints[0, c], joints[1, c], joints[2, c] if is_3d else 0.0
        if all([x == 0.0, y == 0.0, z == 0.0]):
            invalid_joints[c] = True
            continue
        keypoint = ob.keypoints.add()
        keypoint.position.x = x
        keypoint.position.y = y
        if is_3d:
            keypoint.position.z = z
        keypoint.id = human_keypoint

    return ob, invalid_joints
def get_links(model='COCO'):
    if model == 'COCO':
        return [(HKP.Value('NECK'), HKP.Value('LEFT_SHOULDER')),
                (HKP.Value('LEFT_SHOULDER'), HKP.Value('LEFT_ELBOW')),
                (HKP.Value('LEFT_ELBOW'), HKP.Value('LEFT_WRIST')),
                (HKP.Value('NECK'), HKP.Value('LEFT_HIP')),
                (HKP.Value('LEFT_HIP'), HKP.Value('LEFT_KNEE')),
                (HKP.Value('LEFT_KNEE'), HKP.Value('LEFT_ANKLE')),
                (HKP.Value('NECK'), HKP.Value('RIGHT_SHOULDER')),
                (HKP.Value('RIGHT_SHOULDER'), HKP.Value('RIGHT_ELBOW')),
                (HKP.Value('RIGHT_ELBOW'), HKP.Value('RIGHT_WRIST')),
                (HKP.Value('NECK'), HKP.Value('RIGHT_HIP')),
                (HKP.Value('RIGHT_HIP'), HKP.Value('RIGHT_KNEE')),
                (HKP.Value('RIGHT_KNEE'), HKP.Value('RIGHT_ANKLE')),
                (HKP.Value('NOSE'), HKP.Value('LEFT_EYE')),
                (HKP.Value('LEFT_EYE'), HKP.Value('LEFT_EAR')),
                (HKP.Value('NOSE'), HKP.Value('RIGHT_EYE')),
                (HKP.Value('RIGHT_EYE'), HKP.Value('RIGHT_EAR'))]
    elif model == 'MPI':
        # TODO
        return []
    else:
        return []
Пример #5
0
from video_loader import MultipleVideoLoader
from is_wire.core import Logger
from collections import defaultdict, OrderedDict
import matplotlib
import statistics
from is_msgs.image_pb2 import ObjectAnnotations
from is_msgs.image_pb2 import HumanKeypoints as HKP
from google.protobuf.json_format import ParseDict
from itertools import permutations
from analysis import SkeletonsCoord

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

colors = list(permutations([0, 255, 85, 170], 3))
links = [(HKP.Value('HEAD'), HKP.Value('NECK')),
         (HKP.Value('NECK'), HKP.Value('CHEST')),
         (HKP.Value('CHEST'), HKP.Value('RIGHT_HIP')),
         (HKP.Value('CHEST'), HKP.Value('LEFT_HIP')),
         (HKP.Value('NECK'), HKP.Value('LEFT_SHOULDER')),
         (HKP.Value('LEFT_SHOULDER'), HKP.Value('LEFT_ELBOW')),
         (HKP.Value('LEFT_ELBOW'), HKP.Value('LEFT_WRIST')),
         (HKP.Value('NECK'), HKP.Value('LEFT_HIP')),
         (HKP.Value('LEFT_HIP'), HKP.Value('LEFT_KNEE')),
         (HKP.Value('LEFT_KNEE'), HKP.Value('LEFT_ANKLE')),
         (HKP.Value('NECK'), HKP.Value('RIGHT_SHOULDER')),
         (HKP.Value('RIGHT_SHOULDER'), HKP.Value('RIGHT_ELBOW')),
         (HKP.Value('RIGHT_ELBOW'), HKP.Value('RIGHT_WRIST')),
         (HKP.Value('NECK'), HKP.Value('RIGHT_HIP')),
         (HKP.Value('RIGHT_HIP'), HKP.Value('RIGHT_KNEE')),
         (HKP.Value('RIGHT_KNEE'), HKP.Value('RIGHT_ANKLE')),
from src.panoptic_dataset.utils import is_valid_model
from is_msgs.image_pb2 import HumanKeypoints as HKP


def _reverse_model_joints(joints_list):
    reverse_list = [-1] * (max(joints_list) + 1)
    for joint_index, human_keypoint in enumerate(joints_list):
        reverse_list[human_keypoint] = joint_index

    return reverse_list

MODEL_15_JOINTS = [
    HKP.Value('NECK'),           \
    HKP.Value('HEAD'),           \
    HKP.Value('CHEST'),          \
    HKP.Value('LEFT_SHOULDER'),  \
    HKP.Value('LEFT_ELBOW'),     \
    HKP.Value('LEFT_WRIST'),     \
    HKP.Value('LEFT_HIP'),       \
    HKP.Value('LEFT_KNEE'),      \
    HKP.Value('LEFT_ANKLE'),     \
    HKP.Value('RIGHT_SHOULDER'), \
    HKP.Value('RIGHT_ELBOW'),    \
    HKP.Value('RIGHT_WRIST'),    \
    HKP.Value('RIGHT_HIP'),      \
    HKP.Value('RIGHT_KNEE'),     \
    HKP.Value('RIGHT_ANKLE')
]

# HumanKeyPoint.Value('UNKNOWN_HUMAN_KEYPOINT') represents the Background
MODEL_19_JOINTS = [
Пример #7
0
import json
import numpy as np
from is_msgs.image_pb2 import ObjectAnnotation, HumanKeypoints
from is_msgs.camera_pb2 import CameraCalibration
from .numpy import to_tensor

REGEX_DETECTION_ID = re.compile(r'body3DScene_([0-9]+).json')
DETECTION_FILE = 'body3DScene_{:08d}.json'
'''
    http://domedb.perception.cs.cmu.edu/tools.html

    Neck, HeadTop, BodyCenter, lShoulder,lElbow, lWrist, lHip,
    lKnee, lAnkle, rShoulder, rElbow, rWrist, rHip, rKnee, rAnkle
'''
MPII_PB_PARTS = [
    HumanKeypoints.Value('NECK'),           \
    HumanKeypoints.Value('HEAD'),           \
    HumanKeypoints.Value('CHEST'),          \
    HumanKeypoints.Value('LEFT_SHOULDER'),  \
    HumanKeypoints.Value('LEFT_ELBOW'),     \
    HumanKeypoints.Value('LEFT_WRIST'),     \
    HumanKeypoints.Value('LEFT_HIP'),       \
    HumanKeypoints.Value('LEFT_KNEE'),      \
    HumanKeypoints.Value('LEFT_ANKLE'),     \
    HumanKeypoints.Value('RIGHT_SHOULDER'), \
    HumanKeypoints.Value('RIGHT_ELBOW'),    \
    HumanKeypoints.Value('RIGHT_WRIST'),    \
    HumanKeypoints.Value('RIGHT_HIP'),      \
    HumanKeypoints.Value('RIGHT_KNEE'),     \
    HumanKeypoints.Value('RIGHT_ANKLE')
]
        sid = 0
        while True:
            sks = reader.next(Skeletons())
            if not sks:
                log.info("[Done][{}] camera \'{}\' with {} sequences", dataset,
                         camera, sid + 1)
                break

            objs = ObjectAnnotations()
            # panoptic dataset HD cameras resolution
            objs.resolution.width = width
            objs.resolution.height = height
            for sk in sks.skeletons:
                obj = objs.objects.add()
                for part in sk.parts:
                    type_str = SkeletonPartType.Name(part.type)
                    if type_str == 'UNKNOWN' or type_str == 'BACKGROUND':
                        continue
                    keypoint = obj.keypoints.add()
                    keypoint.id = HumanKeypoints.Value(type_str)
                    keypoint.score = part.score
                    keypoint.position.x = part.x
                    keypoint.position.y = part.y

            sequence_id = Int64Value()
            sequence_id.value = sid
            writer.insert(sequence_id)
            writer.insert(objs)
            sid += 1
Пример #9
0
 def __init__(self, options):
     if not isinstance(options, Options):
         raise Exception(
             'Invalid parameter on \'SkeletonsDetector\' constructor: not a Options type'
         )
     self.__op = options
     model = '{}x{}'.format(self.__op.resize.width, self.__op.resize.height)
     w, h = model_wh(model)
     self.__resize_to_default = (w > 0 and h > 0)
     model_name = Options.Model.Name(self.__op.model).lower()
     graph_path = get_graph_path(model_name=model_name,
                                 base_path=self.__op.models_folder)
     self.__e = TfPoseEstimator(
         graph_path,
         target_size=(w, h),
         gpu_mem_allow_growth=options.gpu_mem_allow_growth,
         per_process_gpu_memory_fraction=options.
         per_process_gpu_memory_fraction)
     self.__to_sks_part = {
         0: HumanKeypoints.Value('NOSE'),
         1: HumanKeypoints.Value('NECK'),
         2: HumanKeypoints.Value('RIGHT_SHOULDER'),
         3: HumanKeypoints.Value('RIGHT_ELBOW'),
         4: HumanKeypoints.Value('RIGHT_WRIST'),
         5: HumanKeypoints.Value('LEFT_SHOULDER'),
         6: HumanKeypoints.Value('LEFT_ELBOW'),
         7: HumanKeypoints.Value('LEFT_WRIST'),
         8: HumanKeypoints.Value('RIGHT_HIP'),
         9: HumanKeypoints.Value('RIGHT_KNEE'),
         10: HumanKeypoints.Value('RIGHT_ANKLE'),
         11: HumanKeypoints.Value('LEFT_HIP'),
         12: HumanKeypoints.Value('LEFT_KNEE'),
         13: HumanKeypoints.Value('LEFT_ANKLE'),
         14: HumanKeypoints.Value('RIGHT_EYE'),
         15: HumanKeypoints.Value('LEFT_EYE'),
         16: HumanKeypoints.Value('RIGHT_EAR'),
         17: HumanKeypoints.Value('LEFT_EAR'),
     }