Warping Brien - Image Reprojection with Python OpenCV
My friend Brien is a bit of an artist and a bit of a tech nerd so he thought it would be a great idea to make a timelapse video of him drawing. So he put the CHDK firmware on his Canon S90 camera and set it up to take an exposure every 2-3 seconds. He reprojected the drawing portion of the image back into a rectangle and made a video out of it. He managed to do the original video using only ImageMagick command line tools. You can watch his Timelapse Drawing 1 on YouTube.
That worked out pretty well, but we thought it would also be cool to make a video with both the original image containing Brien and the extracted drawing image shown side by side. This would allow one to see the drawing progress and the artist at work.
I thought this would be a good chance for me to do a little image manipulation in Python, so I fired up my IPython notebook and make use of OpenCV.
I started the process off by working through and validating each step I wanted to perform, beginning with standard imports and reading in the sample image.
import numpy as np from scipy import ndimage import matplotlib.pyplot as plt import cv2 from cvutil import url_to_array, color_flip from pylab import rcParams %matplotlib inline # set the figsize and dpi globally for all images rcParams['figure.figsize'] = (16, 16) rcParams['figure.dpi'] = 300 # color_flip converts cv2 BGR image to numpy RGB image brien_drawing = color_flip(cv2.imread('IMG_1482.JPG'))
Now that I have read in the sample image, I want to see what it looks like. Note that below I place a
; at the end of my call to
imshow(), this supresses the return value that the IPython Notebook automatically prints out for every cell. We only care to see the image itself. I'll do this every time I use