File size: 2,358 Bytes
39b4c8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import numpy as np
import os
from pyVHR.datasets.dataset import Dataset
from pyVHR.signals.bvp import BVPsignal

class PURE(Dataset):
    """
    PURE dataset structure:
    -----------------
        datasetDIR/
        |
        |-- 01-01/
        |---- Image...1.png
        |---- Image.....png
        |---- Image...n.png
        |-- 01-01.json
        |...
        |...
        |-- nn-nn/
        |---- Image...1.png
        |---- Image.....png
        |---- Image...n.png        
        |-- nn-nn.json
        |...
    """
    name = 'PURE'
    signalGT = 'BVP'      # GT signal type
    numLevels = 1         # depth of the filesystem collecting video and BVP files
    numSubjects = 10      # number of subjects
    video_EXT = 'png'     # extension of the video files
    frameRate = 30        # vieo frame rate
    VIDEO_SUBSTRING = '-' # substring contained in the filename
    SIG_EXT = 'json'      # extension of the BVP files
    SIG_SUBSTRING = '-'   # substring contained in the filename
    SIG_SampleRate = 60   # sample rate of the BVP files
    skinThresh = [40,60]  # thresholds for skin detection

    def readSigfile(self, filename):
        """ Load BVP signal.
            Must return a 1-dim (row array) signal
        """
        bvp = []
        with open(filename) as json_file:
            json_data = json.load(json_file)
            for p in json_data['/FullPackage']:
                bvp.append(p['Value']['waveform'])

        data = np.array(bvp)

        return BVPsignal(data, self.SIG_SampleRate)


    def loadFilenames(self):
        """
        Load dataset file names and directories of frames: 
        define vars videoFilenames and BVPFilenames
        """

        # -- loop on the dir struct of the dataset getting directories and filenames
        for root, dirs, files in os.walk(self.videodataDIR):

            for f in files:
                filename = os.path.join(root, f)
                path, name = os.path.split(filename)
                
                # -- select signal
                if name.endswith(self.SIG_EXT) and (name.find(self.SIG_SUBSTRING)>=0):
                    self.sigFilenames.append(filename)
                    self.videoFilenames.append(filename[:-5] + '/file.' + self.video_EXT)

        # -- number of videos
        self.numVideos = len(self.videoFilenames)