Created
September 28, 2017 02:29
-
-
Save SeaOfOcean/ff6ff154a92dba35ff7bd7ee0fa1eb7f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import everything needed to edit/save/watch video clips | |
from moviepy.editor import * | |
from IPython.display import HTML | |
# Prepare input rdd | |
myclip = VideoFileClip("Dog imitates baby.mp4").subclip(0, 10) | |
video_rdd = sc.parallelize(myclip.iter_frames(fps=5)) | |
(data, sizes) = preprocess(video_rdd, means, scale, resolution) | |
# Do detection | |
output = model.predict(data) | |
detection = output.zip(sizes).map(lambda (output_i, img_size): scaleOutput(output_i, img_size)) | |
image_detection = video_rdd.zip(detection).map(lambda (data, result): visualize(data, result, 0.3)) | |
# Save detection to video | |
results = image_detection.collect() | |
results = filter(lambda x: x!=None, results) | |
clip = ImageSequenceClip(results, fps=5) | |
output_path = '/tmp/out.mp4' | |
%time clip.write_videofile(output_path, audio=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment