项目简介

heartbeat是一个国外的大佬发起的项目,自2016年维护至今,主要用途是利用视频图像完成非接触式心率测量,主要应用到的技术有深度学习和计算机视觉。
该项目拥有PCWeb安卓三个版本。

Mac m1运行Heartbeat

安装OpenCV

最简单的方法是在自己的电脑上安装brew,然后通过brew install opencv安装。

如果在安装过程中出现:

==> Installing xxx dependency: yyy
==> ...
Error: No such file or directory @ rb_sysopen - ...

这种情况是因为yyy包安装失败,使用brew install yyy单独下载该依赖包即可。

查看opencv

安装完成后,执行pkg-config --cflags --libs opencv命令。

zhinushannan@zhinushannan-deMacBook-Air /usr/local/lib/pkgconfig$ pkg-config --cflags --libs opencv                                
-I/opt/homebrew/Cellar/opencv/4.5.5_2/include/opencv4 -L/opt/homebrew/Cellar/opencv/4.5.5_2/lib -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core

将输出结果中对应的-I/opt/homebrew/Cellar/opencv/4.5.5_2/include/opencv4 -L/opt/homebrew/Cellar/opencv/4.5.5_2/lib记录,后面有用。

若提示没有pkg-config,则直接执行brew install pkg-config命令安装即可。若提示

Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found

是因为没有opencv.pc这个文件。
执行如下命令:

cd /usr/local/lib
sudo mkdir pkgconfig
sudo vim opencv.pc

其中,opencv.pc文件的内容为(其中prefix是brew安装的opencv的路径,可以通过brew info opencv查看):

prefix=/opt/homebrew/Cellar/opencv/4.5.5_2
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib

Name: opencv
Description: The opencv library
Version:4.0.1
Cflags: -I${includedir}/opencv4
Libs: -L${libdir} -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann  -lopencv_core
~

~/.bash_profile中添加:export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig(前提要满足Macbook m1常见环境变量配置中的前置条件),编译一下source ~/.bash_profile

下载、编译、执行Heartbeat

下载:

git clone git@github.com:prouast/heartbeat.git

下载完成后,进入下载目录,查看Makefile文件:

# Makefile for heartbeat
appname := Heartbeat

CXX := g++
RM := rm -f
CXXFLAGS := -Wall -g -std=c++11 -I/usr/local/include/opencv4 -I/usr/include/opencv4
LDFLAGS := -g
LDLIBS := -lopencv_core -lopencv_dnn -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_objdetect -lopencv_video -lopencv_videoio

......

修改其中的CXXFLAGS的两个-I值,值为上一步中记录的内容:

# CXXFLAGS := -Wall -g -std=c++11 -I/usr/local/include/opencv4 -I/usr/include/opencv4
CXXFLAGS := -Wall -g -std=c++11 -I/opt/homebrew/Cellar/opencv/4.5.5_2/include/opencv4 -L/opt/homebrew/Cellar/opencv/4.5.5_2/lib

修完完成后保存,执行

make

待编译完成后,执行./Heartbeat,稍等几秒,会弹出一个窗口(第一次执行会申请摄像头权限):

1Mac版Heartbeat执行效果