我正在尝试从我的皮肤视频中找出心率。为此,我从我的视频帧中截取了一个像素矩形,然后对所有这些像素中的红色(或绿色)分量进行平均(然后,当然,看看这个平均值如何逐帧变化)。
我对矢量(每帧裁剪部分的平均颜色值)进行快速傅立叶变换,以查看哪些频率最为突出。我希望看到人类静息心率 ~1Hz 非常突出。
作为测试,我只拍了一面墙或其他不应有周期性颜色变化的物体的视频。我使用了一个三脚架和三个不同品牌的不同相机。它们中的每一个都具有相似但不相同的背景频率峰值,特别是在 1Hz、2Hz、5Hz 和 10Hz 处。我在自然光和荧光灯下拍摄过,但它仍然出现。
我的最终目标是通过这种分析来区分活体皮肤和无血管皮肤。因此,理解为什么我会得到无生命物体的这些频率峰值是至关重要的。
你们中的任何人都可以在自己的视频上运行此代码并帮助解释我是否只是个白痴?
相机拍摄:
柯达 Playsport
1920x1080 30 帧/秒(60i) 导入为 mp4
佳能 Vixia HF200 1440x1080 30 帧/秒(60i) 12mbps 比特率 导入为 .mts,我将其重新编码为 mp4
代码基于:
http://www.ignaciomellado.es/blog/Measuring-heart-rate-with-a-smartphone-camera#video
clear all
close all
clc
%% pick data file name to be analyzed, set directory it is found in
dataDir = './data';
vidname = ['Filename.MP4'];
%% define path to file and pull out video
inFile = fullfile(dataDir,vidname);
video = VideoReader(inFile);
%% make 1D array with length equal to number of frames (time)
brightness = zeros(1, video.NumberOfFrames);
video_framerate = round( video.FrameRate); % note some places in the code must use integer value for framerate, others we directly use the unrounded frame rate
%% set region of interest for what you want to get average brightness of
frame = read(video, 1);
imshow(frame)
rect = getrect;
close all
xmin_pt = round(rect(1));
ymin_pt = round(rect(2));
section_width = round(rect(3));
section_height = round(rect(4));
%% select component of video (red green or blue)
component_selection = 1; % pick red , green, or blue
%% make 1D array of ROI averages
for i = 1:video.NumberOfFrames,
frame = read(video, i);
section_of_interest = frame(ymin_pt:ymin_pt+section_height,xmin_pt:xmin_pt+section_width,:);
colorPlane = section_of_interest(:, :, component_selection);
brightness(i) = sum(sum(colorPlane)) / (size(frame, 1) * size(frame, 2));
end
%% Filter out non-physiological frequencies
BPM_L = 40; % Heart rate lower limit [bpm]
BPM_H = 600; % Heart rate higher limit [bpm] This is currently set high to investigate the signal
% Butterworth frequencies must be in [0, 1], where 1 corresponds to half the sampling rate
[b, a] = butter(2, [((BPM_L / 60) / video_framerate * 2), ((BPM_H / 60) / video_framerate * 2)]);
filtBrightness = filter(b, a, brightness);
%% Trim the video to exlude the time where the camera is stabilizing
FILTER_STABILIZATION_TIME = 3; % [seconds]
filtBrightness = filtBrightness((video_framerate * FILTER_STABILIZATION_TIME + 1):size(filtBrightness, 2));
%% Do FFT on filtered/trimmed signal
fftMagnitude = abs(fft(filtBrightness));
%% Plot results
figure(1)
subplot(3,1,1)
plot([1:length(brightness)]/video.FrameRate,brightness)
xlabel('Time (seconds)')
ylabel('Color intensity')
title('original signal')
subplot(3,1,2)
plot([1:length(filtBrightness)]/video.FrameRate,filtBrightness)
xlabel('Time (seconds)')
ylabel('Color intensity')
title('after butterworth filter and trim')
freq_dimension = ((1:round(length(filtBrightness)))-1)*(video_framerate/length(filtBrightness));
subplot(3,1,3)
plot(freq_dimension,fftMagnitude)
axis([0,15,-inf,inf])
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
title('Fft of filtered signal')
最佳答案
您的目的是“从我的皮肤视频中找到心率”和“……通过这种分析来区分活体皮肤和无血管皮肤”,但您的方法是“拍摄视频……裁剪...平均红色(或绿色)成分..看看它是如何变化的。
我觉得前提有问题。平均值意味着多数信号占主导地位。人类视觉是视觉数据的(惊人的)处理器,通常需要数十年的辛勤工作才能让机器达到他们所做工作的一小部分。如果您不能用眼睛注视周围 90% 的人并测量他们的心率,那么平均方法可能不是可行的方法。
您可以使用无数种统计数据来了解分布如何随时间变化,均值只是其中之一。如果您只看均值,您可能会遗漏信息。
我会怎么做:
- 我会根据帧与帧之间的差异进行操作。
- 大多数视频编解码器都具有不均匀的时间间隔。我会得到这些值,这样我就可以跟踪实际(非假设)时间的变化。您当前的(可能是错误的)信号可能来自 CODEC 以及硬件。
- 我会制作一部电影,使每个新帧都是它与前一帧之间的差异。我会看 20 遍,看看我的(惊人的)人类视觉处理系统是否可以清楚地看到任何与心跳相关或不相关的东西。
- 对于“NOT”,通过掩码、过滤器等将它们从处理中移除。 对于相关的,找到使它们成为感兴趣区域的方法 删除其他所有内容,截断像素强度直方图,或 其他图像增强功能(模糊、锐化、重新着色、边缘、旋转等 最大信号沿更新的像素轴,然后处理..)
在人类视觉装置能够获得良好信号之后,我将致力于让数学/计算机获得信号,并清楚地知道人类装置是优越的。
如果我要跟踪随时间移动的点/特征,我会考虑亚像素计量方法。我在十年前 (thesis) 做过一些这样的事情,虽然我认为内容可能相关,但它也可能有所不同,值得在复制和运行代码之前先通读一遍。
祝你好运。
关于ios - 从简单视频中获取心率 : code inside,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24190295/