Пример #1
0
def get_heartrate(filename, dir):
    """ Read video file and estimate heart rate """
    # Frequency range for Fast-Fourier Transform
    freq_min = 1
    freq_max = 1.8

    # Preprocessing phase
    hr = -1  # Valor por defecto

    fn = os.path.join(dir, filename)
    video_frames, frame_ct, fps = preprocessing.read_video(fn)

    # Build Laplacian video pyramid

    lap_video = pyramids.build_video_pyramid(video_frames)

    amplified_video_pyramid = []

    for i, video in enumerate(lap_video):
        if i == 0 or i == len(lap_video) - 1:
            continue

        # Eulerian magnification with temporal FFT filtering

        result, fft, frequencies = eulerian.fft_filter(video, freq_min,
                                                       freq_max, fps)
        lap_video[i] += result

        # Calculate heart rate

        hr = find_heart_rate(fft, frequencies, freq_min, freq_max)

    filename, _ = os.path.splitext(filename)
    return hr, filename
def mMain(pPath):
    # Frequency range for Fast-Fourier Transform
    freq_min = 1
    freq_max = 1.8

    # Preprocessing phase
    # print("Reading + preprocessing video...")
    video_frames, frame_ct, fps = preprocessing.read_video("videos/" + pPath)

    # Build Laplacian video pyramid
    # print("Building Laplacian video pyramid...")
    lap_video = pyramids.build_video_pyramid(video_frames)

    amplified_video_pyramid = []

    for i, video in enumerate(lap_video):
        if i == 0 or i == len(lap_video) - 1:
            continue

        # Eulerian magnification with temporal FFT filtering
        # print("Running FFT and Eulerian magnification...")
        result, fft, frequencies = eulerian.fft_filter(video, freq_min,
                                                       freq_max, fps)
        lap_video[i] += result

        # Calculate heart rate
        # print("Calculating heart rate...")
        heart_rate = heartrate.find_heart_rate(fft, frequencies, freq_min,
                                               freq_max)
        print(heart_rate)
    return heart_rate
Пример #3
0
def processing():
    video = []
    freq_min = 1
    freq_max = 1.8
    fps = 30

    for i in range(300):
        iimg = cv2.imread('Frames/Frame' + str(i) + '.png')

        video.append(iimg)

    # cv2.imshow('image',video[50])
    # Output img with window name as 'image'

    # Maintain output window utill
    # user presses a key
    cv2.waitKey(0)
    # time.sleep(5)

    # print("processing started")
    # print(str(len(video)) + " initial-framecount")

    lap_video = pyramids.build_video_pyramid(video)
    amplified_video_pyramid = []

    for i, video in enumerate(lap_video):
        # print(i)
        if i == 0 or i == len(lap_video) - 1:
            continue

        # Eulerian magnification with temporal FFT filtering
        # print("Running FFT and Eulerian magnification...")
        result, fft, frequencies = eulerian.fft_filter(video, freq_min,
                                                       freq_max, fps)
        lap_video[i] += result

        # Calculate heart rate
        # print("Calculating heart rate...")
        heart_rate = heartrate.find_heart_rate(fft, frequencies, freq_min,
                                               freq_max)

    # Collapse laplacian pyramid to generate final video
    # print("Rebuilding final video...")
    # amplified_frames = pyramids.collapse_laplacian_video_pyramid(lap_video, self.frame_ct)

    # Output heart rate and final video
    print(heart_rate)
Пример #4
0
    def __call__(self, source):

        self.source = source

        print("Reading + pre-processing video...")
        if self.ml_model is True:
            capture_frames = CaptureFrames()
            self.video_frames, self.frame_ct, self.fps = capture_frames(
                self.source)
        else:
            self.video_frames, self.frame_ct, self.fps = read_video(source)

        print("Building Laplacian video pyramid...")
        self.lap_video = build_video_pyramid(self.video_frames)

        amplified_video_pyramid = []

        # Eulerian magnification with temporal FFT filtering
        print("Running FFT and Eulerian magnification...")
        self.result, self.fft, self.frequencies = fft_filter(
            self.lap_video[1], self.freq_min, self.freq_max, self.fps)
        self.lap_video[1] += self.result

        print("Calculating heart rate...")
        self.heart_rate = find_heart_rate(self.fft, self.frequencies,
                                          self.freq_min, self.freq_max)
        print(self.heart_rate)

        if self.final_video:
            # Collapse laplacian pyramid to generate final video
            print("Rebuilding final video...")
            self.amplified_frames = collapse_laplacian_video_pyramid(
                self.lap_video, self.frame_ct)

            # Output heart rate and final video
            print("Heart rate: ", self.heart_rate, "bpm")
            if show_frames:
                print("Displaying final video...")
                for frame in self.amplified_frames:
                    cv2.imshow("frame", frame)
                    cv2.waitKey(20)

        return self.heart_rate
Пример #5
0
import heartrate
import preprocessing
import eulerian

# Frequency range for Fast-Fourier Transform
freq_min = 1
freq_max = 1.8

# Preprocessing phase
print("Reading + preprocessing video...")
video_frames, frame_ct, fps = preprocessing.read_video(
    "videos/rohin_active.mov")

# Build Laplacian video pyramid
print("Building Laplacian video pyramid...")
lap_video = pyramids.build_video_pyramid(video_frames)

amplified_video_pyramid = []

for i, video in enumerate(lap_video):
    if i == 0 or i == len(lap_video) - 1:
        continue

    # Eulerian magnification with temporal FFT filtering
    print("Running FFT and Eulerian magnification...")
    result, fft, frequencies = eulerian.fft_filter(video, freq_min, freq_max,
                                                   fps)
    lap_video[i] += result

    # Calculate heart rate
    print("Calculating heart rate...")