Attempt to automatically adjust the speed of time-lapse movies (Part 2)

Part 1

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.

phash (from the first part)

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)]

アートボード_1.png

z score

For the time being, I took the z score.

z_scores = scipy.stats.zscore(distances)

z_scores.png

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)))

blured_z_scores.png

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

Task

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

Attempt to automatically adjust the speed of time-lapse movies (Part 2)
Attempt of automatic speed adjustment of time-lapse movie (Part 1)
I tried to erase the negative part of Meros
Automatically select BGM according to the content of the conversation
Part 1 Attempt to code mathematics (∈)
How to run the Export function of GCP Datastore automatically
[Note] Let's try to predict the amount of electricity used! (Part 1)
Consider the speed of processing to shift the image buffer with numpy.ndarray
A command to easily check the speed of the network on the console
Project Euler 4 Attempt to speed up
Supplement to the explanation of vscode
About the order of learning programming languages (from beginner to intermediate) Part 2
How to crop the lower right part of the image with Python OpenCV
I tried to automatically extract the movements of PES players with software
I tried to get the RSS of the top song of the iTunes store automatically
The story of trying to reconnect the client
How to speed up instantiation of BeautifulSoup
Script to change the description of fasta
How to check the version of Django
I want to handle the rhyme part1
The story of adding MeCab to ubuntu 16.04
I want to handle the rhyme part3
Understand the "temporary" part of UNIX / Linux
The story of pep8 changing to pycodestyle
I want to handle the rhyme part2
I want to handle the rhyme part5
I want to handle the rhyme part4
Defense Techniques When You Have to Fight the Performance of Unfamiliar Applications (Part 2)
Use Pillow to make the image transparent and overlay only part of it
Organize Python tools to speed up the initial movement of data analysis competitions
I made a tool to automatically back up the metadata of the Salesforce organization
Try to detect an object with Raspberry Pi ~ Part 1: Comparison of detection speed ~
[Verification] Try to align the point cloud with the optimization function of pytorch Part 1
Deep learning dramatically makes it easier to see the time-lapse of physical changes
I tried to automatically send the literature of the new coronavirus to LINE with Python