|
from sklearn import decomposition |
|
from numpy import vstack |
|
from .base import VHRMethod |
|
|
|
class PCA(VHRMethod): |
|
methodName = 'PCA' |
|
|
|
def __init__(self, **kwargs): |
|
super(PCA, self).__init__(**kwargs) |
|
|
|
def apply(self, X): |
|
|
|
|
|
|
|
|
|
bvp = decomposition.PCA(n_components=3).fit_transform(X.T).T |
|
|
|
return bvp |
|
|
|
|
|
def __preprocess(self, X): |
|
|
|
R = X[:,0].copy() |
|
G = X[:,1].copy() |
|
B = X[:,2].copy() |
|
|
|
|
|
minHz = BVPsignal.minHz |
|
maxHz = BVPsignal.maxHz |
|
fs = self.video.frameRate |
|
|
|
|
|
filteredR = BPfilter(R, minHz, maxHz, fs) |
|
filteredG = BPfilter(G, minHz, maxHz, fs) |
|
filteredB = BPfilter(B, minHz, maxHz, fs) |
|
|
|
X = vstack([filteredR, filteredG, filteredB]) |
|
|
|
return X |