File size: 3,277 Bytes
4f9ce06
 
 
 
1515783
 
 
 
 
 
4f9ce06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
## Dataset Overview
This dataset contains sequences of MediaPipe pose landmarks for several padel strokes. 

### Classes
- Forehand - filename: forehand (i).pkl
- Backhand - filename: backhand (i).pkl
- Forehand Volley - filename: fhvolley (i).pkl
- Backhand Volley - filename: bhvolley (i).pkl
- Bandeja - filename: bandeja (i).pkl
- Smash - filename: smash (i).pkl

### File Contents
Each `.pkl` file contains the `PoseLandmarkerResult` returned by `detect_for_video` from MediaPipe.

#### `PoseLandmarkerResult` Structure
- **Landmarks**:
  - `Landmark #0`:
    - `x`: 0.638852
    - `y`: 0.671197
    - `z`: 0.129959
    - `visibility`: 0.9999997615814209
    - `presence`: 0.9999984502792358
  - `Landmark #1`:
    - `x`: 0.634599
    - `y`: 0.536441
    - `z`: -0.06984
    - `visibility`: 0.999909
    - `presence`: 0.999958
  - ... (33 landmarks per pose)

- **WorldLandmarks**:
  - `Landmark #0`:
    - `x`: 0.067485
    - `y`: 0.031084
    - `z`: 0.055223
    - `visibility`: 0.9999997615814209
    - `presence`: 0.9999984502792358
  - `Landmark #1`:
    - `x`: 0.063209
    - `y`: -0.00382
    - `z`: 0.020920
    - `visibility`: 0.999976
    - `presence`: 0.999998
  - ... (33 world landmarks per pose)

More information on its format can be found [here](https://ai.google.dev/edge/mediapipe/solutions/vision/pose_landmarker/python).

## Loading Data

### Loading `PoseLandmarkerResult`
To load a `PoseLandmarkerResult` from a `.pkl` file, use the following code:

```python
import joblib

detection_results = joblib.load(pkl_filepath)

```
### Loading the Complete Dataset
To load the dataset into arrays `X`, `Y`, `Z`, and `labels`, use the sample code below. Make sure to point `folderpath` to the directory containing the dataset files.

```python
import os
import joblib

def build_coordinates_dataset(folderpath):
    all_files = os.listdir(folderpath)
    pkl_filepaths = [os.path.join(folderpath, pkl_filepath) for pkl_filepath in all_files if pkl_filepath.endswith(".pkl")]
    print(f'{len(pkl_filepaths)} samples found')
    
    X, Y, Z, labels = [], [], [], []

    for pkl_filepath in pkl_filepaths:
        detection_results = joblib.load(pkl_filepath)
        try:
            loaded_pose_landmarks = detection_results
            x_frames, y_frames, z_frames = [], [], []

            for frame_detection_result in loaded_pose_landmarks:
                landmarks = frame_detection_result.pose_world_landmarks[0]

                x_landmarks, y_landmarks, z_landmarks = [], [], []

                for i in landmarks:
                    x_landmarks.append(i.x)
                    y_landmarks.append(i.y)
                    z_landmarks.append(i.z)

                x_frames.append(x_landmarks)
                y_frames.append(y_landmarks)
                z_frames.append(z_landmarks)

            X.append(x_frames)
            Y.append(y_frames)
            Z.append(z_frames)

            labels.append(os.path.basename(pkl_filepath)[:3])

        except Exception as e:
            print(e)
            print(f"Error loading {pkl_filepath}")
            
    return X, Y, Z, labels

```
To load the dataset into arrays X, Y, Z, and labels, use the sample code below. Make sure to point folderpath to the directory containing the dataset files.