def satisfies_prerequisites(humans: List) -> Tuple[bool, str]:
    """Check whether the prerequisites for the exercise are met.

    Y axis increases downwards  (hence the `1-`)
    X axis increases rightwards

    Coordinates are 0 to 1 scaled hence the `+0.5` in X axis

    Prerequisites:
    1. Only 1 human in frame.
    2. Both legs fully visible.
    3. Right leg in lying position.
    """
    if len(humans) == 0:
        return False, 'No human in sight'

    if len(humans) > 1:
        return False, 'More than 1 human in sight'

    right_ankle = humans[0]['coordinates'][CocoPart.RAnkle.value][:2]
    right_knee = humans[0]['coordinates'][CocoPart.RKnee.value][:2]
    right_hip = humans[0]['coordinates'][CocoPart.RHip.value][:2]
    left_ankle = humans[0]['coordinates'][CocoPart.LAnkle.value][:2]
    left_knee = humans[0]['coordinates'][CocoPart.LKnee.value][:2]
    left_hip = humans[0]['coordinates'][CocoPart.LHip.value][:2]

    if any(
            joint == [0, 0] for joint in
        [left_ankle, left_knee, left_hip, right_ankle, right_knee, right_hip]):
        return False, 'Full legs not visible'

    # X coordinate of hip should be before knee which should be before ankle
    # and the max difference between Y coordinates should be of 0.1
    if not (right_hip[0] < right_knee[0] < right_ankle[0]
            and max(right_ankle[1], right_knee[1], right_hip[1]) -
            min(right_ankle[1], right_knee[1], right_hip[1]) <= 0.1):
        return False, 'Right leg not in lying position'

    angle = get_angle(p0=[right_hip[0], 1 - right_hip[1]],
                      p1=[right_knee[0], 1 - right_knee[1]],
                      p2=[right_ankle[0], 1 - right_ankle[1]])

    if not (165 <= int(abs(angle)) <= 180):
        return False, 'Right leg not straight'

    angle = get_angle(p0=[left_hip[0], 1 - left_hip[1]],
                      p1=[left_knee[0], 1 - left_knee[1]],
                      p2=[left_ankle[0], 1 - left_ankle[1]])

    if not (165 <= int(abs(angle)) <= 180):
        return False, 'Left leg not straight'

    return True, 'Satisfies'
def satisfies_prerequisites(humans: List) -> Tuple[bool, str]:
    """Check whether the prerequisites for the exercise are met.

    Y axis increases downwards  (hence the `1-`)
    X axis increases rightwards

    Coordinates are 0 to 1 scaled hence the `+0.5` in X axis

    Prerequisites:
    1. Only 1 human in frame.
    2. Both legs fully visible.
    3. Right leg in lying position.
    """
    if len(humans) == 0:
        return False, 'Không tìm thấy người tập trong tầm quan sát'

    if len(humans) > 1:
        return False, 'Có nhiều hơn 1 người trong tầm quan sát'

    right_ankle = humans[0]['coordinates'][CocoPart.RAnkle.value][:2]
    right_knee = humans[0]['coordinates'][CocoPart.RKnee.value][:2]
    right_hip = humans[0]['coordinates'][CocoPart.RHip.value][:2]
    left_ankle = humans[0]['coordinates'][CocoPart.LAnkle.value][:2]
    left_knee = humans[0]['coordinates'][CocoPart.LKnee.value][:2]
    left_hip = humans[0]['coordinates'][CocoPart.LHip.value][:2]

    if any(
            joint == [0, 0] for joint in
        [left_ankle, left_knee, left_hip, right_ankle, right_knee, right_hip]):
        return False, 'Không nhìn thấy toàn bộ hai chân'

    # X coordinate of hip should be before knee which should be before ankle
    # and the max difference between Y coordinates should be of 0.1
    if not (right_hip[0] < right_knee[0] < right_ankle[0]
            and max(right_ankle[1], right_knee[1], right_hip[1]) -
            min(right_ankle[1], right_knee[1], right_hip[1]) <= 0.1):
        return False, 'Chân phải không ở tư thế nằm'

    angle = get_angle(p0=[right_hip[0], 1 - right_hip[1]],
                      p1=[right_knee[0], 1 - right_knee[1]],
                      p2=[right_ankle[0], 1 - right_ankle[1]])

    if not (165 <= int(abs(angle)) <= 180):
        return False, 'Chân phải không thẳng'

    angle = get_angle(p0=[left_hip[0], 1 - left_hip[1]],
                      p1=[left_knee[0], 1 - left_knee[1]],
                      p2=[left_ankle[0], 1 - left_ankle[1]])

    if not (165 <= int(abs(angle)) <= 180):
        return False, 'Chân trái không thẳng'

    return True, 'Thỏa mãn'
def perform_step(human: Dict, cur_step: int) -> Tuple[int, str]:
    """
    Steps:
    1. Left leg should be straight and in a lying position, i.e., making an inner angle in range [170, 180]
        and hip coord less than knee and knee coord less than ankle.
    2. Extend the left leg upwards keeping it straight such that the inner angle between thighs is more than 45.
    3. Bring the left leg back to the starting position.
    """
    if cur_step == 0:
        left_ankle = human['coordinates'][CocoPart.LAnkle.value][:2]
        left_knee = human['coordinates'][CocoPart.LKnee.value][:2]
        left_hip = human['coordinates'][CocoPart.LHip.value][:2]

        # X coordinate of hip should be before knee which should be before ankle
        # and the max difference between Y coordinates should be of 0.1
        if not (
            left_hip[0] < left_knee[0] < left_ankle[0]
            and max(left_ankle[1], left_knee[1], left_hip[1]) - min(left_ankle[1], left_knee[1], left_hip[1]) <= 0.1
        ):
            return cur_step + 1, 'Initial position set\nSlowly move the left leg up'

        return cur_step, 'Move left leg to lying position'

    elif cur_step == 1:
        left_knee = human['coordinates'][CocoPart.LKnee.value][:2]
        left_hip = human['coordinates'][CocoPart.LHip.value][:2]
        right_knee = human['coordinates'][CocoPart.RKnee.value][:2]
        right_hip = human['coordinates'][CocoPart.RHip.value][:2]

        try:
            inter = get_intersection_point(line1=[left_hip, left_knee], line2=[right_hip, right_knee])
        except:
            return cur_step, 'Legs are parallel'

        angle = get_angle(p0=[left_knee[0], 1 - left_knee[1]],
                          p1=[inter[0], 1 - inter[1]],
                          p2=[right_knee[0], 1 - right_knee[1]])

        if -45 < angle < -40:
            return cur_step + 1, 'Extension limit reached\nLower the left leg'

        return cur_step, 'Continue moving the left leg up'

    elif cur_step == 2:
        left_ankle = human['coordinates'][CocoPart.LAnkle.value][:2]
        left_knee = human['coordinates'][CocoPart.LKnee.value][:2]
        left_hip = human['coordinates'][CocoPart.LHip.value][:2]

        # X coordinate of hip should be before knee which should be before ankle
        # and the max difference between Y coordinates should be of 0.1
        if (
            left_hip[0] < left_knee[0] < left_ankle[0]
            and max(left_ankle[1], left_knee[1], left_hip[1]) - min(left_ankle[1], left_knee[1], left_hip[1]) <= 0.1
        ):
            return cur_step + 1, 'Back in starting position'

        return cur_step, 'Continue lowering the left leg'

    return cur_step, ''
def perform_step(human: Dict, cur_step: int) -> Tuple[int, str]:
    """
    Steps:
    1. Left leg should be straight and in a lying position, i.e., making an inner angle in range [170, 180]
        and hip coord less than knee and knee coord less than ankle.
    2. Extend the left leg upwards keeping it straight such that the inner angle between thighs is more than 45.
    3. Bring the left leg back to the starting position.
    """
    if cur_step == 0:
        left_ankle = human['coordinates'][CocoPart.LAnkle.value][:2]
        left_knee = human['coordinates'][CocoPart.LKnee.value][:2]
        left_hip = human['coordinates'][CocoPart.LHip.value][:2]

        # X coordinate of hip should be before knee which should be before ankle
        # and the max difference between Y coordinates should be of 0.1
        if not (left_hip[0] < left_knee[0] < left_ankle[0]
                and max(left_ankle[1], left_knee[1], left_hip[1]) -
                min(left_ankle[1], left_knee[1], left_hip[1]) <= 0.1):
            return cur_step + 1, 'Đặt vị trí ban đầu\nNâng chân trái lên dần'

        return cur_step, 'Di chuyển chân trái sang tư thế nằm'

    elif cur_step == 1:
        left_knee = human['coordinates'][CocoPart.LKnee.value][:2]
        left_hip = human['coordinates'][CocoPart.LHip.value][:2]
        right_knee = human['coordinates'][CocoPart.RKnee.value][:2]
        right_hip = human['coordinates'][CocoPart.RHip.value][:2]

        try:
            inter = get_intersection_point(line1=[left_hip, left_knee],
                                           line2=[right_hip, right_knee])
        except:
            return cur_step, 'Legs are parallel'

        angle = get_angle(p0=[left_knee[0], 1 - left_knee[1]],
                          p1=[inter[0], 1 - inter[1]],
                          p2=[right_knee[0], 1 - right_knee[1]])

        if -45 < angle < -40:
            return cur_step + 1, 'Đã đạt đến giới hạn phần mở rộng\nHạ thấp chân trái dần'

        return cur_step, 'Tiếp tục nâng chân trái lên'

    elif cur_step == 2:
        left_ankle = human['coordinates'][CocoPart.LAnkle.value][:2]
        left_knee = human['coordinates'][CocoPart.LKnee.value][:2]
        left_hip = human['coordinates'][CocoPart.LHip.value][:2]

        # X coordinate of hip should be before knee which should be before ankle
        # and the max difference between Y coordinates should be of 0.1
        if (left_hip[0] < left_knee[0] < left_ankle[0]
                and max(left_ankle[1], left_knee[1], left_hip[1]) -
                min(left_ankle[1], left_knee[1], left_hip[1]) <= 0.1):
            return cur_step + 1, 'Trở về vị trí ban đầu'

        return cur_step, 'Tiếp tục hạ thấp chân trái'

    return cur_step, ''
Exemple #5
0
def perform_step(human: Dict, cur_step: int) -> Tuple[int, str]:
    """
    Steps:
    1. Right leg should be in a seated position, i.e., making an inner angle in range (120, 150).
    2. Extend the right leg such that the inner angle is more than 180.
    3. Bring the right leg back to the starting position.
    """
    right_ankle = human['coordinates'][CocoPart.RAnkle.value][:2]
    right_knee = human['coordinates'][CocoPart.RKnee.value][:2]
    right_hip = human['coordinates'][CocoPart.RHip.value][:2]

    angle = get_angle(p0=[right_ankle[0], 1 - right_ankle[1]],
                      p1=[right_knee[0], 1 - right_knee[1]],
                      p2=[right_hip[0], 1 - right_hip[1]])

    if cur_step == 0:
        if 120 < angle < 150:
            return cur_step + 1, 'Initial position set\nSlowly extend the right leg'

        return cur_step, 'Move right leg to seating position'

    elif cur_step == 1:
        if 120 < angle < 150:
            return cur_step, 'Initial position set\nSlowly extend the right leg'

        if make_360(angle=angle) >= 180:
            return cur_step + 1, 'Extension limit reached\nSlowly lower right leg'

        return cur_step, 'Continue extending the right leg'

    elif cur_step == 2:
        if make_360(angle=angle) >= 180:
            return cur_step, 'Extension limit reached\nSlowly lower right leg'

        if 0 < angle < 150:
            return cur_step + 1, 'Right leg back in starting position'

        return cur_step, 'Continue lowering the right leg'

    return cur_step, ''
Exemple #6
0
def perform_step(human: Dict, cur_step: int) -> Tuple[int, str]:
    """
    Steps:
    1. Left leg should be in a lying position, i.e., making an inner angle in range [165, 180].
    2. Slide the heel backwards such that the inner angle is less than 90.
    3. Slide the heel forward to the starting position.
    """
    left_ankle = human['coordinates'][CocoPart.LAnkle.value][:2]
    left_knee = human['coordinates'][CocoPart.LKnee.value][:2]
    left_hip = human['coordinates'][CocoPart.LHip.value][:2]

    angle = get_angle(p0=[left_ankle[0], 1 - left_ankle[1]],
                      p1=[left_knee[0], 1 - left_knee[1]],
                      p2=[left_hip[0], 1 - left_hip[1]])

    if cur_step == 0:
        if 165 <= angle <= 180:
            return cur_step + 1, 'Initial position set\nSlowly slide left leg backwards'

        return cur_step, 'Move left leg to lying position'

    elif cur_step == 1:
        if 165 <= angle <= 180:
            return cur_step, 'Initial position set\nSlowly slide left leg backwards'

        if angle <= 40:
            return cur_step + 1, 'Limit reached\nSlide left leg forwards'

        return cur_step, 'Continue sliding left leg backwards'

    elif cur_step == 2:
        if angle <= 40:
            return cur_step, 'Limit reached\nSlide left leg forwards'

        if 165 <= angle <= 180:
            return cur_step + 1, 'Left leg back in starting position'

        return cur_step, 'Continue sliding left leg forwards'

    return cur_step, ''
Exemple #7
0
def perform_step(human: Dict, cur_step: int) -> Tuple[int, str]:
    """
    Steps:
    1. Right leg should be in a seated position, i.e., making an inner angle in range (120, 150).
    2. Extend the right leg such that the inner angle is more than 180.
    3. Bring the right leg back to the starting position.
    """
    right_ankle = human['coordinates'][CocoPart.RAnkle.value][:2]
    right_knee = human['coordinates'][CocoPart.RKnee.value][:2]
    right_hip = human['coordinates'][CocoPart.RHip.value][:2]

    angle = get_angle(p0=[right_ankle[0], 1 - right_ankle[1]],
                      p1=[right_knee[0], 1 - right_knee[1]],
                      p2=[right_hip[0], 1 - right_hip[1]])

    if cur_step == 0:
        if 120 < angle < 150:
            return cur_step + 1, 'Đặt vị trí ban đầu\nMở rộng dần chân phải'

        return cur_step, 'Di chuyển chân phải sang tư thế ngồi'

    elif cur_step == 1:
        if 120 < angle < 150:
            return cur_step, 'Đặt vị trí ban đầu\nMở rộng dần chân phải'

        if make_360(angle=angle) >= 180:
            return cur_step + 1, 'Đã đạt đến giới hạn của phần mở rộng\nHạ chân phải xuống thấp dần'

        return cur_step, 'Tiếp tục mở rộng chân phải'

    elif cur_step == 2:
        if make_360(angle=angle) >= 180:
            return cur_step, 'Đã đạt đến giới hạn của phần mở rộng\nHạ chân phải xuống thấp dần'

        if 0 < angle < 150:
            return cur_step + 1, 'Đặt chân phải trở lại vị trí ban đầu'

        return cur_step, 'Tiếp tục hạ thấp chân phải'

    return cur_step, ''
Exemple #8
0
def perform_step(human: Dict, cur_step: int) -> Tuple[int, str]:
    """
    Steps:
    1. Left leg should be in a lying position, i.e., making an inner angle in range [165, 180].
    2. Slide the heel backwards such that the inner angle is less than 90.
    3. Slide the heel forward to the starting position.
    """
    left_ankle = human['coordinates'][CocoPart.LAnkle.value][:2]
    left_knee = human['coordinates'][CocoPart.LKnee.value][:2]
    left_hip = human['coordinates'][CocoPart.LHip.value][:2]

    angle = get_angle(p0=[left_ankle[0], 1 - left_ankle[1]],
                      p1=[left_knee[0], 1 - left_knee[1]],
                      p2=[left_hip[0], 1 - left_hip[1]])

    if cur_step == 0:
        if 165 <= angle <= 180:
            return cur_step + 1, 'Đặt vị trí ban đầu\nTrượt chân trái dần về phía sau'

        return cur_step, 'Di chuyển chân trái sang tư thế nằm'

    elif cur_step == 1:
        if 165 <= angle <= 180:
            return cur_step, 'Đặt vị trí ban đầu\nTrượt chân trái dần về phía sau'

        if angle <= 40:
            return cur_step + 1, 'Đã đạt đến giới hạn\nTrượt chân trái về phía trước'

        return cur_step, 'Tiếp tục trượt chân trái về phía sau'

    elif cur_step == 2:
        if angle <= 40:
            return cur_step, 'Đã đạt đến giới hạn\nTrượt chân trái về phía trước'

        if 165 <= angle <= 180:
            return cur_step + 1, 'Đặt chân trái trở lại vị trí ban đầu'

        return cur_step, 'Tiếp tục trượt chân trái về phía trước'

    return cur_step, ''
Exemple #9
0
def satisfies_prerequisites(humans: List) -> Tuple[bool, str]:
    """Check whether the prerequisites for the exercise are met.

    Y axis increases downwards  (hence the `1-`)
    X axis increases rightwards

    Coordinates are 0 to 1 scaled hence the `+0.5` in X axis

    Prerequisites:
    1. Only 1 human in frame.
    2. Both legs fully visible.
    3. Left leg in seated position.
    """
    if len(humans) == 0:
        return False, 'No human in sight'

    if len(humans) > 1:
        return False, 'More than 1 human in sight'

    right_ankle = humans[0]['coordinates'][CocoPart.RAnkle.value][:2]
    right_knee = humans[0]['coordinates'][CocoPart.RKnee.value][:2]
    right_hip = humans[0]['coordinates'][CocoPart.RHip.value][:2]
    left_ankle = humans[0]['coordinates'][CocoPart.LAnkle.value][:2]
    left_knee = humans[0]['coordinates'][CocoPart.LKnee.value][:2]
    left_hip = humans[0]['coordinates'][CocoPart.LHip.value][:2]

    if any(
            joint == [0, 0] for joint in
        [left_ankle, left_knee, left_hip, right_ankle, right_knee, right_hip]):
        return False, 'Full legs not visible'

    angle = get_angle(p0=[left_ankle[0], 1 - left_ankle[1]],
                      p1=[left_knee[0], 1 - left_knee[1]],
                      p2=[left_hip[0], 1 - left_hip[1]])

    if not (90 <= int(angle) <= 150):
        return False, 'Left leg not seated'

    return True, 'Satisfies'