def ppg_filtered(self, frames):
        camera_specs = Camera_specs()
        vps_940_green = list()
        vps_600_red = list()
        for frame in frames:
            vp_600_green, vp_600_red = self.ppg_lamonaca(frame, camera_specs)
            vps_940_green.append(vp_600_green)
            vps_600_red.append(vp_600_red)

        # First, design the Buterworth filter
        vps_940_green_filtered = utils.cutoff(vps_940_green)
        vps_600_red_filtered = utils.cutoff(vps_600_red)

        return (vps_940_green_filtered, vps_600_red_filtered)
Пример #2
0
 def add_file(self, data):
     recno = self._tar.next_recno()
     info = TarInfo('%08d' % recno)
     self._tar.add_record(info, bytes2gzip(data))
     msg = message_from_bytes(data)
     text = cutoff(msg2str(msg), self.MAX_TEXT_SIZE)
     self._text.add_text(recno, text)
     for tag in msg2tags(msg):
         self._text.add_tag(recno, tag)
     return recno
    def ppg_filtered_from_video_file(self, video_file):
        camera_specs = Camera_specs()
        vps_940_green = list()
        vps_600_red = list()
        frame_count = 0

        cap = cv2.VideoCapture(video_file)
        fps = cap.get(cv2.CAP_PROP_FPS)

        timestamps = list()

        while cap.isOpened():

            ret, frame = cap.read()
            if ret == True:

                if frame_count % 50 == 0:
                    print("Frame:", frame_count)

                timestamps.append(frame_count / fps)
                frame_count = frame_count + 1

                vp_600_green, vp_600_red = self.ppg_lamonaca(
                    frame, camera_specs)
                vps_940_green.append(vp_600_green)
                vps_600_red.append(vp_600_red)
            else:
                break

        cap.release()

        duration = frame_count / fps

        # First, design the Buterworth filter
        vps_940_green_filtered = utils.cutoff(vps_940_green)
        vps_600_red_filtered = utils.cutoff(vps_600_red)

        return (vps_940_green_filtered, vps_600_red_filtered, duration,
                timestamps)
Пример #4
0
def NewQNewtonMethod(f, fDer, fHessian, z0, NIterate, mode, gamma0, v0,
                     stopCriterion, rtol, atol, dimN, verbose):
    if mode == 'gd':
        print(
            "Use New Q-Newton method with pertubation by orthogonal matrices Full version"
        )
    else:
        print(
            "Use New Q-Newton method with pertubation by orthogonal matrices Full version for NAG with gamma ",
            gamma0, "; initial direction =", v0)

    print("With parameters: f=", f, "; initial point =", z0)
    print("We will stop when both z_{n+1}-z_n and f(z_{n+1})-f(z_n) are small")

    zn = z0

    t0 = time.time()

    delta = 1

    print("Number of maximum iterates:", NIterate,
          "; But note that the number of actual iterates may be much smaller")
    for m in range(NIterate):
        tmp, w = fHessian(zn)
        if dimN == 1:
            HessTr = tmp
            if HessTr == 0:
                HessTr = HessTr + delta * cutoff(L2Norm2(fDer(zn), dimN))

            HessInv = 1 / HessTr
            gn = fDer(zn) * HessInv
            gn = NegativeOrthogonalDecomposition(HessTr, gn, dimN)
        elif dimN > 1:
            HessTr = tmp.transpose()
            if LA.det(HessTr) == 0:
                HessTr = HessTr + delta * cutoff(L2Norm2(
                    fDer(zn), dimN)) * np.identity(dimN, dtype=float)
            HessInv = LA.inv(HessTr)
            gn = np.matmul(fDer(zn), HessInv)
            gn = NegativeOrthogonalDecomposition(HessTr, gn, dimN)
        zn_old = zn
        zn = zn - gn
        if verbose:
            print("Step = ", m, "; zn=", zn_old,
                  "; Square of Displacement = ||z_{n+1}-z_n||^2= ",
                  L2Norm2(gn, dimN), " ; Square of gradient ",
                  L2Norm2(fDer(zn), dimN))

        if stopCriterion == 0:
            if (L2Norm2(gn, dimN) < atol) and (
                    abs(f(zn) - f(zn_old)) < rtol
            ):  # stop when meet the relative and absolute tolerances
                break
        elif stopCriterion == 1:
            if (abs(f(zn)) < rtol
                ):  # stop when meet the relative and absolute tolerances
                break
    print("Time:",
          time.time() - t0, "; Step:", m, "; z_n:", zn, "; f(z_n):", f(zn),
          ": Error:", L2Norm2(fDer(zn), dimN))
    CheckCriticalType(fHessian, zn)

    return
Пример #5
0
with open('PatRec17_KWS_Data/task/train.txt', 'r') as f:
    lines = f.read().splitlines()
    for line in lines:
        train_check.append(line)

with open('PatRec17_KWS_Data/task/valid.txt', 'r') as f:
    lines = f.read().splitlines()
    for line in lines:
        valid_check.append(line)

train = {}
valid = {}
for filename in os.listdir("words"):
    if filename.endswith(".png"):
        image = utils.greyMatrix("words/" + str(filename))
        image = utils.cutoff(image)
        image = utils.resizeArray(image)
        features = utils.featuresExtraction(image)

        name = filename.replace(".png", "")
        id = name.split("-")
        if id[0] in train_check:
            train[name] = features
        elif id[0] in valid_check:
            valid[name] = features

print("Train and Valid set loaded")

keyWords = utils.load_keyWords()
groundTruth = utils.load_truth()