One of the nice things about
using the Jupyter Notebooks system,
is that there's a rich set of
contributed plugins that seek to extend this system.
In this lecture, I want to introduce you to
one such plugin called ipy web rtc.
Web rtc is a fairly new protocol
for real-time communication on the web.
I'm talking about chatting.
The widget brings this to Jupyter notebook systems.
Let's take a look. First, let's
import this from the library,
two different classes which we're going to use in a demo.
One for the camera and one for the images.
So from ipy web rtc,
import camera stream and image recorder.
Then let's take a look at the camera stream objects,
or help camera stream.
We see from the docs that it's easy to
get a camera facing the user.
Then we have the audio on or off.
We don't need audio for this demo so
let's create a new camera instance.
So camera equals cameras stream.facing
user and audio equals false.
The next object we want to look at is the image recorder,
so help image recorder.
The image recorder let us actually
grab images from the camera stream.
There are features for downloading
and using the image as well.
We see that the default format is a ping file.
Let's look up the image recorder to our stream.
So image recorder equals
image recorder and stream is equal to the camera.
Now, the dogs are a little
unclear about how you use this within Jupyter.
But if we call the download function,
it will actually store the results of the camera,
which is hooked up in image
recorder.image. Let's try it out.
First, let's tell the image recorder
to start capturing data.
So image reporter.recording equals true.
Now, let's download the image,
so image recorder.download.
Then, let's inspect the type of the image,
so type, image recorder.image.
Okay. So the object that it's stored
as an ipywidgets.widget.widget media.image.
How did we do something useful with this?
Well, an inspection of the object shows that there's
a handy value field which
actually holds the bytes behind the image,
and we know how to display those.
So let's import PIL image import PIL.Image.
Now, let's import IO import IO.
Now, let's create a PIL image from the bytes.
So images equal to pil.Image.open, and then,
io.BytesIO to create a stream,
and then image recorder.image.value.
Wow. That's a lot of dots.
Let's render it to the screen.
So that's just display image,
because it's just a PIL image down.
Great. You see a picture.
Hopefully, you're following along and one of
the note bugs and you've been able to
try this out for yourself.
So what can you do with this?
Well, this is a great way to get
started with a better computer vision.
You already know how to identify
a face and a webcam in the picture,
or try and capture texts from within the picture.
With Open CV, there's
any number of things that you can do.
Simply with a webcam,
the Jupyter notebooks and Python.