def video_persons_result()

in experiments/notebooks/cloudstory-api/cloudstory.py [0:0]


def video_persons_result(jobId):
    display('In Progress...')
    response_person = rekognition.get_person_tracking(JobId=jobId)
    while response_person['JobStatus'] == 'IN_PROGRESS':
        time.sleep(5)
        response_label = rekognition.get_person_tracking(JobId=jobId)

    display('Getting Person Paths...')
    display(f"Video Codec: {response_person['VideoMetadata']['Codec']}")
    display(f"Video Duration (ms): {str(response_person['VideoMetadata']['DurationMillis'])}")
    display(f"Video Format: {response_person['VideoMetadata']['Format']}")
    display(f"Video FrameRate: {int(response_person['VideoMetadata']['FrameRate'])}")

    persons = []
    while response_person:
        persons.extend(response_person['Persons'])
        if 'NextToken' in response_person:
            response_person = rekognition.get_person_tracking(JobId=jobId, NextToken=response_person['NextToken']) 
        else:
            response_person = None
    
    display(f'Succeeded in detecting {len(persons)} person paths.')
    
    df = pd.DataFrame(persons)
    df['Left'] = df['Person'].apply(lambda x: round(x['BoundingBox']['Left'], 2) if 'BoundingBox' in x else '')
    df['Top'] = df['Person'].apply(lambda x: round(x['BoundingBox']['Top'], 2) if 'BoundingBox' in x else '')
    df['Height'] = df['Person'].apply(lambda x: round(x['BoundingBox']['Height'], 2) if 'BoundingBox' in x else '')
    df['Width'] = df['Person'].apply(lambda x: round(x['BoundingBox']['Width'], 2) if 'BoundingBox' in x else '')
    df['Index'] = df['Person'].apply(lambda x: x['Index'])
    df = df.drop(columns=['Person'])

    return df