ESP32-CAM IP Camera With Face Detection
This post is different compared to the others and we take a look at the very interesting ESP32-CAM board that is surprisingly cheap (less than $9) and easy to use. We create a simple IP camera that can be used to stream a live video feed using the 2MP camera module. We also try out the face detection and face recognition feature.
The video above covers everything you need in under 4 minutes.
Step 1: Configure The Arduino IDE
We start by adding the ESP32 board support package to the Arduino IDE. You need to add the following link to the boards manager URL from the File menu.
Then, open up the boards manager, search for ESP32 and install the package. Wait for it to complete and close the window. Make sure you have selected the right board settings from the tools menu, as seen in the image. The COM port will not be available until you carry out the next step.
Step 2: Wire Up The Board
The ESP32-CAM board does not have an onboard USB connector so you need to use an external USB to serial converter to upload the sketch. You can use the wiring connections shown above but make sure that the USB to serial converter is connected in the 3.3V mode.
It is recommended to use an external 5V supply to power the board, particularly if you are using an FTDI breakout board. For the external 5V supply, a simple USB breakout board will do just fine. There has been some success in powering the board directly from the CP2102 breakout board so you can try that first. The board also has a 3.3V power pin if needed.
The jumper is needed to put the board in the download mode. Once you have everything connected, power up the board, open a serial terminal (Tools->Serial Monitor) with a baud rate of 115, 200 and press the reset button. You should obtain an output as shown in the image and this will indicate that everything is working as expected.
Step 3: Prepare The Sketch
Open up the CameraWebServer example sketch as shown in the image above. Make sure you add your WiFi network name and password as the board will have to connect to it. Also, be sure to select the AI_THINKER camera model as seen in the image. One this is done. Upload the sketch and then open the serial monitor again.
Give the board a few seconds to connect to the WiFi network and you will then see the connection status along with the IP address. Keep a note of this as we move to the next step.
Step 4: View Camera Stream
Open up a web browser and enter the IP address that was obtained in the previous step. You should obtain a page like the one in the image. Click the “START STREAM” button and you should be able to view the live stream. You change the resolution to something higher, depending on your needs. There are also a few settings and effects that you can play around with.
If you do get horizontal lines in the video feed, then this is an indication of insufficient power. Try using a shorter USB cable or an alternate power source in that case.
You can also obtain a still image, but since this is not stored anywhere, you will have to right-click and save it if required.
Step 5: Face Detection & Recognition
In order for face detection to work, you would need to select a CIF or lower resolution. The board will process the video feed to detect a face and highlight it on screen. If you enable face recognition, then it will check to see if the face that is detected is known or enrolled, if not, it will tag it as an intruder. If you want to save a face then you can hit the enrol face button to register multiple samples that it will use as a reference.
That’s how easy it is to build a simple IP camera using the ESP32-CAM. The video quality is not excellent but they have really simplified the whole process of working with camera modules like this.