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

class UBFC1(Dataset):
    """
    UBFC dataset structure:
    -----------------
        datasetDIR/
        |   |-- SubjDIR1/
        |       |-- vid.avi
        |...
        |   |-- SubjDIRM/
        |       |-- vid.avi
    """
    name = 'UBFC1'
    signalGT = 'BVP'     # GT signal type
    numLevels = 2        # depth of the filesystem collecting video and BVP files
    numSubjects = 8     # 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 = 'xmp'     # extension of the BVP files
    SIG_SUBSTRING = '' # substring contained in the filename
    SIG_SampleRate = 62 # 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 csvfile:
            xmp = csv.reader(csvfile)
            for row in xmp:
                gtTrace.append(float(row[3]))
                gtTime.append(float(row[0])/1000.)
                gtHR.append(float(row[1]))

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

        '''import matplotlib.pyplot as plt
        plt.plot(hr)
        plt.show()'''

        return BVPsignal(data, self.SIG_SampleRate)