Attempts to automatically adjust the speed of time-lapse movies (Part 1)
This is a continuation of the above article.
I didn't have enough power to investigate, so I moved my hand for the time being.
https://youtu.be/BOHDtW9_tlQ
The hash distance between frames of this time-lapse movie was like this.
clip = moviepy.editor.VideoFileClip("path to video file")
phashs = [imagehash.phash(PIL.Image.fromarray(frame)) for frame in clip.iter_frames()]
distances = [phashs[i+1] - phashs[i] for i in range(len(phashs)-1)]
z score
For the time being, I took the z score.
z_scores = scipy.stats.zscore(distances)
gaussian blur
I blurred the z score and set the minus of the average of the absolute values as the threshold.
blured = cv2.GaussianBlur(z_scores, (49, 49), 0)
threshold = numpy.average(numpy.sqrt(numpy.power(z_scores, 2)))
One sequence below the threshold in the above figure is regarded as one event. The following is a video playback with different speeds.
https://youtu.be/iPMuMYygbDg
It's close to what I had in mind, I thought that it would be a little better if the speed gradually slowed down or became faster before and after the part detected as an event so that there was a margin at the boundary.
This time I used a python library called moviepy
I would like to challenge if I understand how to use it a little more.
https://github.com/Zulko/moviepy
Place the library you used.
# requirements.txt
ImageHash==3.1
matplotlib==1.3.1
moviepy==0.2.2.11
numpy==1.7.1
Pillow==3.4.2
progressbar2==3.11.0
scipy==0.13.2
seaborn==0.7.1
Click here for the code. https://github.com/sosuke-k/timelapse-optimizer
Recommended Posts