My note:
Run all the cells below to make sure everything is working and ready to go. All cells should run without error.
In [1]:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
%matplotlib inline
In [2]:
img = mpimg.imread('test.jpg')
plt.imshow(img)
Out[2]:
In [3]:
import cv2
In [4]:
# convert the image to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
plt.imshow(gray, cmap='Greys_r')
Out[4]:
In [5]:
import tensorflow as tf
In [6]:
with tf.Session() as sess:
a = tf.constant(1)
b = tf.constant(2)
c = a + b
# Should be 3
print("1 + 2 = {}".format(sess.run(c)))
In [9]:
# Import everything needed to edit/save/watch video clips
from moviepy.editor import VideoFileClip
from IPython.display import HTML
Troubleshooting ffmpeg NOTE: If you don't have ffmpeg installed on your computer you'll have to install it for moviepy to work. If this is the case you'll be prompted by an error in the notebook. You can easily install ffmpeg by running the following in a code cell in the notebook.
import imageio
imageio.plugins.ffmpeg.download()
In [8]:
import imageio
imageio.plugins.ffmpeg.download()
Create a new video with moviepy
by processing each frame to YUV color space.
In [10]:
new_clip_output = 'test_output.mp4'
test_clip = VideoFileClip("test.mp4")
new_clip = test_clip.fl_image(lambda x: cv2.cvtColor(x, cv2.COLOR_RGB2YUV)) #NOTE: this function expects color images!!
%time new_clip.write_videofile(new_clip_output, audio=False)
In [11]:
HTML("""
<video width="640" height="300" controls>
<source src="{0}" type="video/mp4">
</video>
""".format(new_clip_output))
Out[11]:
In [ ]: