Imagine the endless possibilities for our home, if we could make a standard CCTV Camera smarter and interactive. Well, introducing the Smart CCTV Camera. A Raspberry Pi IoT based CCTV camera featuring face recognition, home automation, and the ability to interact with your camera's live stream. In essence, it's more like a DIY Ring Camera.
The smart CCTV Camera keeps tabs on your valuable assets as well as informing you of its surroundings, whether you’re indoors or outdoors.
Check out the Full YouTube Tutorial on How to Build a Smart CCTV Camera.
Taking advantage of the new Raspberry Pi High-Quality Camera, the Smart CCTV Camera also features:
- 1) Face Recognition – Identifying who’s at the door
- 2) Camera Movement – Reach those blind spots a typical CCTV camera is limited to with a controllable servo motor.
- 3) Smart Home Automation – Integrate with your Smart Home Appliances and Smart Plugs.
- 4) Dedicated Camera Monitor Feed – Interact with who’s at the door
- 5) Live Stream – Watch videos in Realtime
- 6) Live Notifications – When not around, get a message at who’s at your door via email.
Whether you place the SmartCCTV indoors or on your front porch this works as your intelligent watchdog camera.
The following article details how to build your own Smart CCTV camera using a Raspberry Pi with the new High-Quality Pi Camera - as well as its dedicated monitor. Let’s get started!
Pre-requisite: Raspberry Pi 4 (RAM 2GB+) Recommended.
Parts List – What you’ll needFor more details on the Smart CCTV Parts Installation Guide and partsvisit the smartbuilds.io.
Software and Platforms
- Open CV
- Python 3.7+ & Flask
- Face recognition and dlib
Costs: The total project cost ~$180 dollars, however with a bit of research you can bring this price down. You could also make a cost-effective version using the standard Pi Camera module V2. View the video on the comparison of the two Pi Camera modules.
How it Works:The smart CCTV work by capturing live footage from the camera build and using Flask to create the live stream for our client devices to view the stream. Flask is a lightweight micro web framework which is a great bridge between Python and HTML Web pages. This makes it ideal for touch screen interaction.
Devices connected to the same network of the Pi (CCTV Camera) would be able to visit the URL and see the live footage of the stream. OpenCV would be used to access our video stream. Finally, we would use a face recognition library to identify users.
Assembly of Parts:The assembly of parts is broken into two sections:
- 1) Camera Build
- 2) Dedicated Display Monitor
The camera build consists of a Raspberry Pi 4, micro SD card, Pi High-Quality Camera, and a Plastic Dome Camera Enclosure. The Raspberry Pi is powered by a USB-C Power Supply. In essence, this is all you need to complete the build is a Pi and Pi Camera module.
Similar to the Raspberry Pi V2 Camera module the High-Quality Pi Camera module ribbon cable is inserted into the Camera Port of the Pi.
The CCTV camera enclosure was made by stripping out a cheap plastic dome CCTV camera and using the plastic camera Chassis as the enclosure. Finding a CCTV enclosure is optional, however, this does help with the aesthetics. The original color of the camera came in white, the camera and enclosure were then spray painted to a matte black finish - which helped give it a stealthy look.
Servo Motor Implementation:The Smart CCTV camera won’t be as ‘smart’ if we can’t interact with it. The question is how can we interact with the CCTV camera to make it move into known blind spots?
This is where a servo motor comes into the picture. Servo Motors are really great for precision. The MG90S servo motor allows for a full 180-degree rotation which is ideal for a camera mounted to a wall.
To mount the servo motor we would strip the wires and solder female header pins to plug into the GPIO pin of the Raspberry Pi header.
Note: These would be programmed in the software section and can be re-programmed in the servo.py file.
The following configuration.
A hole can be drilled into the Camera Chassis to screw the motor in - enabling the camera to rotate when the servo rotates. Once completed, re-assemble your Smart CCTV back together.
Note: A camera enclosure was used to house the Raspberry Pi. Keep in mind to build an enclosure that has some form of ventilation to prevent the Pi from getting warm overtime.
Dedicated Monitor Display:The Smart CCTV camera live stream can be accessed from any smartphone via Web URL. However, for the times we want to view the live stream at that immediate instant without pulling out our phones every time, a dedicated touchscreen display monitor would be practical. This Interactive display monitor indefinitely shows the live stream, as well as you can interact with the camera moving left and right.
The Dedicated touchscreen monitor frame was assembled using 1x4 MDF Fiberboard wood which can be found at your local DIY store. Using a hacksaw, the wood was used to cut to the exact dimensions of 13 H cm x 22.5 W cm x 4.5 D cm. The frame was then assembled and was held together with PVA glue and nails. In addition, a glossy Black finish was applied, giving a modern aesthetic look that can blend on your bookshelf.
Great! We're on the Software part. Now the next part is installing face recognition and the dlib library.
SoftwareSetup of Pi Camera ModuleHaving flashed the latest Raspbian OS onto your Micro SD, and completed the setup of Pi. The next part involves installing the face recognition & dib library to the camera build Raspbian OS.
Note: This was installed on the Raspbian OS release inMay 2020.
After logging in via VNC and completing the Pi OS Setup Wizard. We're going to enable the Pi Camera Port ports.
- The Smart CCTV uses the Pi Camera Module. Firstly, ensure that the camera port is enabled.
Open the terminal window and run:
sudo rasp-config
Select Interface Options, Camera Port, and select Enabled. You can now exit. This may cause your Pi to reboot.
You can make sure that the camera module is all working well by taking a picture via the Pi camera module by running this in the below terminal command:
raspistill -o Desktop/image.jpg
This would save a picture of what your camera is viewing to the desktop as image.jpg. You can view the image.
Note: If you’re using the Pi HQ camera you may need to adjust your lens if the picture is too blurry.
The Smart CCTV camera relies on a few dependencies that are required to be installed before running the lives stream. The dlib library is a pre-requisite to start using the face recognition library. Visit the Smartbuilds.io for the terminal commands library dependencies for face recognition. Copy and paste the library commands to install the dlib library. (This also, including face recognition).
Note: The process took about ~40 minutes on the Raspberry Pi 4 (4 GB), but can take several hours on other Pi models. If unsure of the installation, you can also refer to the video tutorial.
Smart CCTV Git InstallationOnce the dlib library and face recognition is installed you can now clone the Smart CCTV Git Repo. This repository contains Flask to establish live streams from Pi to other devices connected to the network.
Breakdown of files in the Smart CCTV repo
- Profile Folder – Where all Face recognition profiles are stored.
- Templates Folder – This is where the HTML webpage would be stored
Python script:
- Camera.py – The script access open CV and the face recognition library to identify persons from its encoding matrix.
- main.py – Where the Flask stream is created - importing servo.py and camera.py
- Servo.py – This python script controls the servo motor rotating the Smart CCTV in the location desired. (Left or Right)
Demo Python Scripts:
- facerec_pi_test.py – Test script to detect faces
- face_pi_test_profiles.py – Test script to detect multiple faces.
To access the live stream with face recognition run Main.py. You can start your live stream by visiting the IP address of your Pi on a browser connected to the same network. The address can be found by entering ifconfig in the terminal of the Pi.
Visit the URL on your browser: <your_pi_ip>:5000 to view your stream. (5000 being your port number)
Via the Livestream, you can now interact with your camera by rotating the camera to cover your blinds spots. Moreover, you can add additional functionalities such as light control. (That’s a whole other topic).
- Adding a profile is as simple as placing your ‘passport-style’ in the Profiles folder as a.png file.
- The camera script encodes the following face into a matrix to be matched against via the face recognition library. The script then performs a comparison of the face it sees relative to the current frame of the camera stream. (This uses the same library as the Smart Mirror Face ID Module)
Note: Picture size 100kb max – The smaller the picture is the faster the face recognition feature performs.
If you have any questions, leave a comment below or watch the full tutorial video.
Next Steps:There you have it, your own SmartCCTV camera. If you like this project, feel free to leave comments /contribute and develop the SmartCCTV repo. You can now program the camera to theoretically perform any action based on an intent (being face recognition). Think of IR LEDs, night vision smart locks... the possibilities are endless!
Comments