Book Image

IPython Interactive Computing and Visualization Cookbook

By : Cyrille Rossant
Book Image

IPython Interactive Computing and Visualization Cookbook

By: Cyrille Rossant

Overview of this book

Table of Contents (22 chapters)
IPython Interactive Computing and Visualization Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Processing webcam images in real time from the notebook


In this recipe, we show how to let the notebook and the Python kernel communicate in both directions.

Specifically, we will retrieve the webcam feed from the browser using HTML5's <video> element, and pass it to Python in real time using the interactive capabilities of the IPython notebook 2.0+. Then, we will process the image in Python with an edge detector (implemented in scikit-image), and display it in the notebook in real time.

Most of the code for this recipe comes from Jason Grout's example, available at https://github.com/jasongrout/ipywidgets.

Getting ready

You need Pillow and scikit-image for this recipe. (For more information, refer to Chapter 11, Image and Audio Processing.)

You also need a recent browser supporting the HTML5 capture API. You can find the specification at http://dev.w3.org/2011/webrtc/editor/getusermedia.html.

How to do it...

  1. We need to import several modules as follows:

    In [1]: from IPython.html.widgets import...