phuselab / pyVHR

Python framework for Virtual Heart Rate
http://phuselab.di.unimi.it/
GNU General Public License v3.0
453 stars 127 forks source link

Error when generating bpm values from videos (concatenate of several images) #20

Closed hamhanry closed 3 years ago

hamhanry commented 3 years ago

Hi, thanks for sharing this awesome repos.

just would like raise issue with the video that consist of small frames between 2-10 frames. So, i concat several images into video, and try to get the bpm values using pos method. Thus resulting winsize too big.

i had changed the win size, yet the error : IndexError: list index out of range raised.

Do the framework could only handle constraint about the frames within the video or any restriction of the total length?

Thanks

aledamelio commented 3 years ago

Hi @hamhanry,

pyVHR estimates the heart rate from videos using sliding windows. The default window size used in the test.cfg config file is 5 seconds. Obviously, you'll need to provide a video which is longer than 5 seconds in this case. If you have shorter videos (or sequence of frames) you can reduce the winSize. In your case, if you have - say - 10 frames, supposing that the video frame rate at which these 10 frames are reproduced is 20 fps, than you have a 0.5 seconds video. In this case the winSize should be less than 0.5 seconds and pyVHR will produce, of course, just one estimate of HR (the one corresponding to that 0.5 seconds window).

Please notice that, using too narrow windows sizes is discouraged for at least 2 reasons: 1) The accuracy of the spectral estimation reduces with smaller winSizes 2) (more important) The wavelengths of BVP signals are pretty wide, hence you'll need appropriate winSizes to capture the relevant information. Suppose you have a 60bpm HR you want to recover. This means that there is 1 heart beat per second; hence, you'll need a winSize of at least 1 second to recover a 60bpm HR. For lower heart rates you'll need longer winSizes.

In your case, I believe it is practically impossible to recover any kind of HR from just a couple of frames.

Alessandro