Did you know that there is a python library that allows you to to capture both a webcam stream or a single webcam image? Did you know that this works on every OS? This is what I want to share in this post: A tutorial on how to use imageio to access your webcam on Linux, Windows, or MacOS that works in either a Python script or a Jupyter Notebook. No OpenCV needed 🙂
Before we begin, a caveat for Jupyter: While the notebook is displayed on your current machine, and widgets run locally, your kernel (that runs the python code) may be hosted on a remote server, docker container, virtual machine, … depending on your setup. If this is the case for you, please note that IPython can only access the remote server’s webcam, not your local one.
pip install imageio[ffmpeg]
Get a single Image/Screenshot
Get a Video as a Sequence of Frames
Full example (record a short MP4)
If you happen to run into problems, you have three options to ask for help:
- Ask a question on StackOverflow and tag it with imageio (I monitor the tag)
- Comment on this post
- Create a New Issue / Bug Report on GitHub.
Thanks for reading and Happy Coding!