This project contains the API to load and interact with Bonn Activity Maps datasets. (WIP)
- The framerate of the videos is 25 Hz.
Using pip:
pip3 install git+https://github.com/bonn-activity-maps/aikapi
or
- Clone the repository:
git clone https://github.com/bonn-activity-maps/aikapi.git
- Install the required Python3 packages with:
pip3 install -r requirements.txt
Constructor for the BAM class used to perform all actions over the dataset.
- Parameters:
- datset_dir: (String) path to the folder containing the datasets.
- dataset_name: (String) name of the dataset folder.
- image_format: (String, Optional) format wanted for the image extraction. "png"/"jpeg". default=
"png"
- half_resolution: (Boolean) True if you want to use the data annotation time resolution. default=
"False"
- Returns:
- (BAM Object) object to perform operations over the dataset
Unrolls (converts each frame to an individial image) all the videos from the dataset and stores them in the videos
folder. This folder will be created if it not exists and will contain another 12 folders (cameraXX), each one containing the unrolled frames for the camera noted with XX.
- Parameters:
- force: (Bool, Optional) if
True
, the already unrolled frames will be deleted (if they exist) and the unroll will be performed. default=False
- video: (Integer, Optional) if
None
all videos will be unrolled. If it has a value between 1 and 12, only that camera will be unrolled. default=None
- force: (Bool, Optional) if
Note: if video is None
and force is True
all the already unrolled videos will be deleted and unrolled again.
Returns the existing person ids in the dataset
- Returns:
- (numpy) numpy array with the existing IDs of the persons in the dataset
Returns the existing static object ids in the dataset
- Returns:
- (numpy) numpy array with the existing IDs of the static objects in the dataset
Returns the total number of frames in the dataset
- Returns:
- (int) total number of frames in the dataset
Returns the total number of cameras in the dataset
- Returns:
- (int) total number of cameras in the dataset
Returns the existing activity names in the dataset
- Returns:
- (numpy) numpy array with the existing activity names in the dataset
Obtains the images for the specified frame in all the cameras.
- Parameters:
- frame: (Integer) frame number to get the images from.
- Returns:
- (numpy) array with the 12 images for the specified frame.
Note: If the videos are not unrolled before getting the individual frames, then they will be automatically unrolled when you try to get the frames.
Obtains the camera object for the specified video and frame.
- Parameters:
- video: (Integer) camera/video number to get the object from.
- frame: (Integer) frame number to get the object from.
- Returns:
- (Camera) camera object (will be explained in the next section)
Get all persons
annotated in the given frame.
- Parameters:
- frame: (Integer) frame number to get the persons from.
- Returns:
- (numpy[personJSON]) persons annotated in the given frame in JSON format (for the structure of the JSON see section JSON structures)
Gets the annotation for the specified person in the specified frame
- Parameters:
- frame: (Integer) frame number to get the person from.
- person_id: (Integer) person identifier.
- Returns:
- (numpy) numpy array with the 3d coordinates for the specified person
Gets all the annotations for the specified person in the dataset
- Parameters:
- person_id: (Integer) person identifier.
- Returns:
- (numpy[personJSON]) all annotations for the specified person in JSON format (for the structure of the JSON see section JSON structures)
Get all poses
annotated in the given frame.
- Parameters:
- frame: (Integer) frame number to get the poses from.
- Returns:
- (numpy[poseJSON]) poses annotated in the given frame in JSON format (for the structure of the JSON see section JSON structures)
Gets the pose annotation for the specified person in the specified frame
- Parameters:
- frame: (Integer) frame number to get the person from.
- person_id: (Integer) person identifier.
- Returns:
- (numpy) numpy array with the 3D coordinates for the specified person
Gets all the pose annotations for the specified person in the dataset
- Parameters:
- person_id: (Integer) person identifier.
- Returns:
- (numpy[poseJSON]) all annotated poses for the specified person in JSON format (for the structure of the JSON see section JSON structures)
Get all static objects
annotated in the given frame.
- Parameters:
- frame: (Integer) frame number to get the static objects from.
- Returns:
- (numpy[staticobjectJSON]) static objects annotated in the given frame in JSON format (for the structure of the JSON see section JSON structures)
Gets the annotation for the specified static object in the specified frame
- Parameters:
- frame: (Integer) frame number to get the static object from.
- static_object_id: (Integer) static object identifier.
- Returns:
- (numpy) numpy array with the 3D coordinates for the specified static object
Gets all the annotations for the specified person in the dataset
- Parameters:
- static_object_id: (Integer) static object identifier.
- Returns:
- (numpy[staticobjectJSON]) all annotations for the specified static object in JSON format (for the structure of the JSON see section JSON structures)
- Parameters:
- person_id: (Integer) person identifier.
- Returns:
- (numpy[activityJSON]) numpy array with activities for the specified person in JSON format (for the structure of the JSON see section JSON structures)
Calculates the distance vector between a point and a static object's closest point to that point.
- Parameters:
- static_object_type: (String) static object type string (boxAIK or cylinderAIK).
- static_object_points: (numpy) static object's points as stored in the dataset.
- point: (numpy) point for which we want to calculate the distance to.
- Returns:
- (numpy) numpy array representing the minimum distance between the point and the object (the vector is the direction and its module the distance magnitude). If the point lies inside of the object it returns [0,0,0].
Extracts 2d poses from folder_name folder into poses folder. The zip file has to be located in the dataset folder.
- Parameters:
- file_name: (String) name of the zip file that contains the 2d data.
- force: (Boolean) if True, the folder poses will be overwritten
Gets 2d poses for frame and camera from poses directory.
- Parameters:
- frame: (Integer) name of the zip file that contains the 2d data.
- camera: (Integer) if True, the folder poses will be overwritten
- Returns:
- (numpy) all poses for frame and camera and scores for each joint in the 3rd coordinate
[
[
[x, y, score],
...
(17 joints)
],
...
(X poses in each frame)
]
- Returns:
- (numpy) (x,y,z) of the camera center in world coordinates.
Undistorts the given image.
- Parameters:
- image: (numpy) image to be undistorted.
- Returns:
- (numpy) the image undistorted.
Undistorts the given points.
- Parameters:
- point2d: (numpy) points to be undistorted [(x,y,w), ...].
- Returns:
- (numpy) the points undistorted.
Projects 3D points into 2D with no distortion.
- Parameters:
- points3d: (numpy) 3D points to be projected.
- Returns:
- (numpy) the points in 2D undistorted.
Projects 3D points into 2D with distortion being considered.
- Parameters:
- points3d: (numpy) 3D points to be projected.
- withmask: (Bool, Optional) if
True
returns mask that tell if a point is in the view or not. default=False
- Returns:
- (numpy) the projected points in 2D.
- (numpy) if withmask is
True
only. Array representing the mask.
Contains:
- person identifier
- array with 3D coordinates corresponding to the nose of the person
- object type, always personAIK for persons
{
'pid': {int},
'location': [
[x, y, z]
],
'type': 'personAIK'
}
Contains:
- person identifier
- array with 3D coordinates corresponding to the 24 joints of the person
- object type, always poseAIK for poses
{
'pid': {int},
'location': [
[x, y, z],
[x, y, z],
...
],
'type': 'poseAIK'
}
Contains:
- static object identifier
- array with 3D coordinates corresponding to the main points of the objects:
- boxAIK: [top front left, top front right, bottom back left]
- cylinderAIK: [top center, top border] (the bottom part is always in contact with the floor).
- object type, boxAIK or cylinderAIK
- array with labels describing the object
{
'oid': {int},
'location': [
[x, y, z],
[x, y, z],
...
],
'type': 'boxAIK' or 'cylinderAIK',
'labels': ['label1', ...]
}
Contains:
- activity name
- frame where the activity begins
- frame where the activity ends
{
'label': {string},
'start_frame': {int},
'end_frame': {int}
}
The dataset folder has the following structure:
- dataset/
- cameras/
- camera00.json
- ...
- camera11.json
- <dataset_name>_unroll.json
- dataset.json
- <dataset_name>_00.mp4
- ...
- <dataset_name>_11.mp4
- videos/
- camera00/
- frame000000001.png
- ...
- ...
- camera01/
- camera00/
- dataset_2d.zip
- poses/
- camera00/
- frame000000001.poses
- ...
- ...
- camera01/
- camera00/
- cameras/
It contains 12 json files, cameraXX.json, with the camera parameters for each camera.
[
{
'w': {int},
'h': {int},
'start_frame': {int},
'end_frame': {int},
'tvec': [x, y, z],
'rvec': [x, y, z],
'distCoef': [a, b, c, d, e],
'K': [3x3 matrix]
}
]
It contains 3 jsons with the annotations for persons, objects and poses for all the videos. The format of each concrete type has been previously explained.
{
'persons': [...]
}
{
'objects': [...]
}
{
'actions': [...]
}
It contains relevant information about the dataset.
{
'n_cameras': {int},
'scale_to_mm': {int},
'image_extension': {string},
'valid_frames': [...]
}
12 videos, dataset_XX.mp4, which are unrolled if it is necessary.
It is created when the videos are unrolled and contains 12 folders, cameraXX, with the corresponding frames for each camera.
It contains the poses folder with 2d poses for each camera and frame.
The 2d data from dataset_2d.zip is extracted in this folder. It contains 12 folders, cameraXX, with the corresponding poses for each frame. Each file contains a numpy array with X poses for different persons and each pose has 17 joints [x, y, score] with:
- x and y coordinates of the joint position
- score for the joint prediction
For examples of how to use the API you can check the Jupyter Notebook test_api.ipynb
provided inside the repository.