Real-time streaming is a great way to interact with our environment. Such as a CCTV camera. But what is the technology behind it?
What if we could do exactly that with a Raspberry Pi – by streaming the Pi Camera’s live feed to any client devices. And even touch on real world applications.
In this tutorial, we’re going to cover this. We’re building a live camera streaming from a Raspberry Pi to your phone (or any internet-connected device). If you recently got a Raspberry Pi and want to work on a new project, this project may be a good one to start on.
Introduction & Top Level Overview
By the end of this tutorial, you’ll be able to set up a wireless stream to view the camera feed from any device on your network. This means you can create your own mini camera stream for any application, think Plant monitor, Smart CCTV camera (with Face recognition), or even a portable camera.
We’re covering the assembly, installing the OS, and Setting up the Python stream. So let’s get started!
Introduction Raspberry Pi
To get a good understanding, it is always good to understand what hardware we’re using. This little piece of Marvel is a Raspberry Pi. Overall, a Raspberry is a computer. (A low-cost computer in fact). Like your MacBook or Desktop, it features USB peripherals and other ports such as an Audio Jack, Ethernet, and HDMI ports. Being able to do what your computer can do – the boards seem to be getting more powerful over time.
The interesting part is the form factor; because of its small size, this ‘credit-size computer’ is useful for different real-world applications and popular in the DIY community.
In this article, we’ll be using the Raspberry Pi 4 (4GB) Mode. However, you can use other models. Keep in mind; performance may vary between models.
What is streaming & How does it work?
Flask can be seen as a back-end web server/micro-framework for Python – making it easier to build web frameworks using Python.
So how does it work?
We’re capturing live footage from the Raspberry Pi camera and using a Flask to create the live stream to our client devices. (which can be any device).
Flask is a great bridge between Python and HTML Web pages and supports Motion JPEG, which works by streaming a sequence of independent JPEG images. Motion JPEG is widely used in Security IP cameras and webcams alike, and this is how we’re streaming our live feed.
Further, a device connected to the same network of the Pi would be able to visit the URL see the live footage of the stream whereby the OpenCV library would be used to access our video stream.
Pi Cam vs. camera module – You may have heard of the latest Pi Camera Module and if you’re wondering about the Image comparison performance of the two. Here it is, although the Pi Camera module is more expensive, it’s definitely an improvement in image quality.
For the benefit of this project, we’re using the cheaper Pi Module.