|
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' |
|
numLevels = 1 |
|
numSubjects = 10 |
|
video_EXT = 'png' |
|
frameRate = 30 |
|
VIDEO_SUBSTRING = '-' |
|
SIG_EXT = 'json' |
|
SIG_SUBSTRING = '-' |
|
SIG_SampleRate = 60 |
|
skinThresh = [40,60] |
|
|
|
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 |
|
""" |
|
|
|
|
|
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) |
|
|
|
|
|
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) |
|
|
|
|
|
self.numVideos = len(self.videoFilenames) |
|
|
|
|