File size: 1,755 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
import csv
import numpy as np
from pyVHR.datasets.dataset import Dataset
from pyVHR.signals.bvp import BVPsignal

class UBFC2(Dataset):
    """
    UBFC dataset structure:
    -----------------
        datasetDIR/
        |   |-- SubjDIR1/
        |       |-- vid.avi
        |...
        |   |-- SubjDIRM/
        |       |-- vid.avi
    """
    name = 'UBFC2'
    signalGT = 'BVP'     # GT signal type
    numLevels = 2        # depth of the filesystem collecting video and BVP files
    numSubjects = 26     # number of subjects
    video_EXT = 'avi'    # extension of the video files
    frameRate = 30       # vieo frame rate
    VIDEO_SUBSTRING = ''  # substring contained in the filename
    SIG_EXT = 'txt'     # extension of the BVP files
    SIG_SUBSTRING = '' # substring contained in the filename
    SIG_SampleRate = 30 # 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
        """
        gtTrace = []
        gtTime = []
        gtHR = []
        with open(filename, 'r') as f:
            x = f.readlines()
        
        s = x[0].split(' ')
        s = list(filter(lambda a: a != '', s))
        gtTrace = np.array(s).astype(np.float64)

        t = x[2].split(' ')
        t = list(filter(lambda a: a != '', t))
        gtTime = np.array(t).astype(np.float64)
        
        hr = x[1].split(' ')
        hr = list(filter(lambda a: a != '', hr))
        gtHR = np.array(hr).astype(np.float64)

        data = np.array(gtTrace)
        time = np.array(gtTime)
        self.SIG_SampleRate = np.round(1/np.mean(np.diff(time)))

        return BVPsignal(data, self.SIG_SampleRate)