Computers
Computer Parts
Custom PC Builder
DIY/ Maker
{$smarty.capture.menu}
Activity
Categories
Discussions
Computers
Computer Parts
Custom PC Builder
DIY/ Maker
Inland ESP32-CAM Video Streaming and Face Recognition with Arduino IDE - Micro Center
<main> <article class="userContent"> <h2 data-id="inland-esp32-cam-video-streaming-and-face-recognition-with-arduino-ide"><strong>Inland ESP32-CAM Video Streaming and Face Recognition with Arduino IDE</strong></h2><p>This article is a quick getting started guide for the ESP32-CAM board. We’ll show you how to setup a video streaming web server with face recognition and detection in less than 5 minutes with Arduino IDE.</p><div class="embedExternal embedImage display-large float-none"> <div class="embedExternal-content"> <a class="embedImage-link" href="https://us.v-cdn.net/6031942/uploads/I2NP8T2XNV5V/image.png" rel="nofollow noreferrer noopener ugc" target="_blank"> <img class="embedImage-img" src="https://us.v-cdn.net/6031942/uploads/I2NP8T2XNV5V/image.png" alt="image.png" height="486" width="865" loading="lazy" data-display-size="large" data-float="none"></img></a> </div> </div> <p><strong><em>Note: in this tutorial we use the example from the arduino-esp32 library. This tutorial doesn’t cover how to modify the example.</em></strong></p><h2 data-id="parts-required"><strong>Parts Required</strong></h2><p><em>To follow this tutorial you need the following components:</em></p><ul><li>ESP32-CAM with OV2640</li><li>FTDI programmer</li><li>Female-to-female jumper wires</li></ul><h2 data-id="introducing-the-esp32-cam"><strong>Introducing the ESP32-CAM</strong></h2><div class="embedExternal embedImage display-large float-none"> <div class="embedExternal-content"> <a class="embedImage-link" href="https://us.v-cdn.net/6031942/uploads/EVSBDWSXUQ7W/image.png" rel="nofollow noreferrer noopener ugc" target="_blank"> <img class="embedImage-img" src="https://us.v-cdn.net/6031942/uploads/EVSBDWSXUQ7W/image.png" alt="image.png" height="486" width="865" loading="lazy" data-display-size="large" data-float="none"></img></a> </div> </div> <p>The ESP32-CAM is a very small camera module with the ESP32-S chip that costs approximately $10. Besides the OV2640 camera, and several GPIOs to connect peripherals, it also features a micro SD card slot that can be useful to store images taken with the camera or to store files to serve to clients.</p><div class="embedExternal embedImage display-large float-none"> <div class="embedExternal-content"> <a class="embedImage-link" href="https://us.v-cdn.net/6031942/uploads/OCT1FAHVP4QB/image.png" rel="nofollow noreferrer noopener ugc" target="_blank"> <img class="embedImage-img" src="https://us.v-cdn.net/6031942/uploads/OCT1FAHVP4QB/image.png" alt="image.png" height="483" width="865" loading="lazy" data-display-size="large" data-float="none"></img></a> </div> </div> <ul><li>The ESP32-CAM doesn’t come with a USB connector, so you need an FTDI programmer to upload code through the <strong>U0R </strong>and <strong>U0T </strong>pins (serial pins).</li></ul><div class="embedExternal embedImage display-large float-none"> <div class="embedExternal-content"> <a class="embedImage-link" href="https://us.v-cdn.net/6031942/uploads/13SB0E98ZVAN/image.png" rel="nofollow noreferrer noopener ugc" target="_blank"> <img class="embedImage-img" src="https://us.v-cdn.net/6031942/uploads/13SB0E98ZVAN/image.png" alt="image.png" height="486" width="865" loading="lazy" data-display-size="large" data-float="none"></img></a> </div> </div> <h2 data-id="features"><strong>Features</strong></h2><p><em>Here is a list with the ESP32-CAM features::</em></p><ul><li>The smallest 802.11b/g/n Wi-Fi BT SoC module</li><li>Low power 32-bit CPU, can also serve the application processor</li><li>Up to 160MHz clock speed, summary computing power up to 600 DMIPS</li><li>Built-in 520 KB SRAM, external 4MPSRAM</li><li>Supports UART / SPI / I2C / PWM / ADC / DAC</li><li>Support OV2640 and OV7670 cameras, built-in flash lamp</li><li>Support image WIFI upload</li><li>Support TF card</li><li>Supports multiple sleep modes</li><li>Embedded Lwip and FreeRTOS</li><li>Supports STA / AP / STA + AP operation mode</li><li>Support Smart Config / AirKiss technology</li><li>Support for serial port local and remote firmware upgrades (FOTA)</li></ul><h2></h2><h2 data-id="esp32-cam-pinout"><strong>ESP32-CAM Pinout</strong></h2><p>The following figure shows the ESP32-CAM pinout (AI-Thinker module)</p><div class="embedExternal embedImage display-large float-none"> <div class="embedExternal-content"> <a class="embedImage-link" href="https://us.v-cdn.net/6031942/uploads/CYKZKLF7K823/image.png" rel="nofollow noreferrer noopener ugc" target="_blank"> <img class="embedImage-img" src="https://us.v-cdn.net/6031942/uploads/CYKZKLF7K823/image.png" alt="image.png" height="368" width="854" loading="lazy" data-display-size="large" data-float="none"></img></a> </div> </div> <h5 data-id="image-source-seeed-studio"> Image source - Seeed Studio</h5><p>There are three GND pins and two pins for power: either 3.3V or 5V.</p><p><strong>GPIO 1</strong> and <strong>GPIO 3</strong> are the serial pins. You need these pins to upload code to your board. Additionally, <strong>GPIO 0</strong> also plays an important role, since it determines whether the ESP32 is in flashing mode or not. When <strong>GPIO 0</strong> is connected to <strong>GND</strong>, the ESP32is in flashing mode. </p><p><em>The following pins are internally connected to the micro SD card reader: </em></p><ul><li>GPIO 14:CLK</li><li>GPIO 15:CMD</li><li>GPIO 2:Data 0</li><li>GPIO 4:Data 1(also connected to the on-board LED)</li><li>GPIO 12:Data 2</li><li>GPIO 13:Data 3</li></ul><h2 data-id="video-streaming-server"><strong>Video Streaming Server</strong></h2><p>Follow the next steps to build a video streaming web server with the ESP32-CAM that you can access on your local network. 。 </p><h2 data-id="1.install-the-esp32-add-on"><strong>1.Install the ESP32 add-on</strong></h2><p>In this example, we use Arduino IDE to program the ESP32-CAM board. So, you need to have Arduino IDE installed as well as the ESP32 add-on.</p><h2 data-id="2.-camera-web-server-example-code"><strong>2. Camera Web Server Example Code</strong></h2><p>In your Arduino IDE, go to <strong>File</strong> > <strong>Examples</strong> > <strong>ESP32</strong> ><strong> Camera</strong> and open the <strong>CameraWebServer</strong> example. </p><div class="embedExternal embedImage display-large float-none"> <div class="embedExternal-content"> <a class="embedImage-link" href="https://us.v-cdn.net/6031942/uploads/0JBN9WXRIYKW/image.png" rel="nofollow noreferrer noopener ugc" target="_blank"> <img class="embedImage-img" src="https://us.v-cdn.net/6031942/uploads/0JBN9WXRIYKW/image.png" alt="image.png" height="434" width="865" loading="lazy" data-display-size="large" data-float="none"></img></a> </div> </div> <p>The following code should load.</p><div class="embedExternal embedImage display-large float-none"> <div class="embedExternal-content"> <a class="embedImage-link" href="https://us.v-cdn.net/6031942/uploads/MMJPNIBURT7T/image.png" rel="nofollow noreferrer noopener ugc" target="_blank"> <img class="embedImage-img" src="https://us.v-cdn.net/6031942/uploads/MMJPNIBURT7T/image.png" alt="image.png" height="443" width="865" loading="lazy" data-display-size="large" data-float="none"></img></a> </div> </div> <p>If you can't find the code in the Arduino IDE, you can download it from our GitHub repository. </p><p>Once downloaded, unzip the folder and open the <em>Camera Web Server.ino</em> file.</p><p>Before uploading the code, you need to insert your network credentials in the following variables:</p><pre class="code codeBlock" spellcheck="false" tabindex="0">const char* ssid = "REPLACE_WITH_YOUR_SSID"; const char* password = "REPLACE_WITH_YOUR_PASSWORD"; </pre><p>Then, make sure you select the right camera module. In this case, we’re using the AI-THINKER Model.</p><div class="embedExternal embedImage display-large float-none"> <div class="embedExternal-content"> <a class="embedImage-link" href="https://us.v-cdn.net/6031942/uploads/BU28IO8R111P/image.png" rel="nofollow noreferrer noopener ugc" target="_blank"> <img class="embedImage-img" src="https://us.v-cdn.net/6031942/uploads/BU28IO8R111P/image.png" alt="image.png" height="486" width="865" loading="lazy" data-display-size="large" data-float="none"></img></a> </div> </div> <p>So, comment all the other models and uncomment this one:</p><pre class="code codeBlock" spellcheck="false" tabindex="0">#define CAMERA_MODEL_AI_THINKER </pre><p>Now, the code is ready to be uploaded to your ESP32. </p><p><br></p><h2 data-id="esp32-cam-upload-code"><strong>ESP32-CAM Upload Code</strong></h2><p>Connect the ESP32-CAM board to your computer using an FTDI programmer. Follow the next schematic diagram:</p><div class="embedExternal embedImage display-large float-none"> <div class="embedExternal-content"> <a class="embedImage-link" href="https://us.v-cdn.net/6031942/uploads/X12ZC5OE7IRH/image.png" rel="nofollow noreferrer noopener ugc" target="_blank"> <img class="embedImage-img" src="https://us.v-cdn.net/6031942/uploads/X12ZC5OE7IRH/image.png" alt="image.png" height="358" width="865" loading="lazy" data-display-size="large" data-float="none"></img></a> </div> </div> <p><strong><em>Important: GPIO 0 needs to be connected to GND so that you’re able to upload code.</em></strong></p><p>To upload the code, follow the next steps:</p><p>1. <strong>Go to Tools > Board and select ESP32 Wrover module</strong></p><p>2. Go to <strong>Tools</strong> > Port and select the COM port the ESP32 is connected to.</p><p>3. In<strong> Tools</strong> > <strong>Partitioning scheme</strong>, select " <strong>Huge App</strong> (<strong>3MB</strong> <strong>without</strong> <strong>OTA</strong>) " </p><p>4. Press the ESP32-CAM on-board RESET button</p><p>5. Then, click the upload button to upload the code.</p><div class="embedExternal embedImage display-medium float-none"> <div class="embedExternal-content"> <a class="embedImage-link" href="https://us.v-cdn.net/6031942/uploads/5ZY1X1H8UCZU/image.png" rel="nofollow noreferrer noopener ugc" target="_blank"> <img class="embedImage-img" src="https://us.v-cdn.net/6031942/uploads/5ZY1X1H8UCZU/image.png" alt="image.png" height="641" width="576" loading="lazy" data-display-size="medium" data-float="none"></img></a> </div> </div> <p><strong><em>Important: If you cannot upload the code, double check that GPIO 0 is connected to GND and that the correct settings are selected in the "Tools" menu. You should also press the on-board reset button to restart the ESP32 in blink mode.</em></strong></p><p><br></p><h2 data-id="getting-the-ip-address"><strong>Getting the IP address</strong></h2><p>After uploading the code, disconnect<strong> GPIO 0</strong> from <strong>GND</strong>.</p><p>Open the Serial Monitor at a baud rate of 115200. Press the ESP32-CAM on-board Reset button.</p><p>The ESP32 IP address should be printed in the Serial Monitor.</p><div class="embedExternal embedImage display-medium float-none"> <div class="embedExternal-content"> <a class="embedImage-link" href="https://us.v-cdn.net/6031942/uploads/7HW729DNNTKQ/image.png" rel="nofollow noreferrer noopener ugc" target="_blank"> <img class="embedImage-img" src="https://us.v-cdn.net/6031942/uploads/7HW729DNNTKQ/image.png" alt="image.png" height="602" width="865" loading="lazy" data-display-size="medium" data-float="none"></img></a> </div> </div> <h2 data-id="accessing-the-video-streaming-server"><strong>Accessing the Video Streaming Server</strong></h2><p>Now, you can access your camera streaming server on your local network. Open a browser and type the ESP32-CAM IP address. Press the Start Streaming button to start video streaming. </p><div class="embedExternal embedImage display-medium float-none"> <div class="embedExternal-content"> <a class="embedImage-link" href="https://us.v-cdn.net/6031942/uploads/8LBLODJANNA6/image.png" rel="nofollow noreferrer noopener ugc" target="_blank"> <img class="embedImage-img" src="https://us.v-cdn.net/6031942/uploads/8LBLODJANNA6/image.png" alt="image.png" height="469" width="865" loading="lazy" data-display-size="medium" data-float="none"></img></a> </div> </div> <p>You also have the option to take photos by clicking the “<strong>Get Still</strong>” button. Unfortunately, this example doesn’t save the photos, but you can modify it to use the on board micro SD Card to store the captured photos.</p><p>There are also several camera settings that you can play with to adjust the image settings.</p><p>Finally, you can do face recognition and detection.</p><div class="embedExternal embedImage display-medium float-none"> <div class="embedExternal-content"> <a class="embedImage-link" href="https://us.v-cdn.net/6031942/uploads/6FLVB372OQPV/image.png" rel="nofollow noreferrer noopener ugc" target="_blank"> <img class="embedImage-img" src="https://us.v-cdn.net/6031942/uploads/6FLVB372OQPV/image.png" alt="image.png" height="474" width="865" loading="lazy" data-display-size="medium" data-float="none"></img></a> </div> </div> <p>First, you need to enroll a new face. It will make several attempts to save the face. After enrolling a new user, it should detect the face later on (subject 0). </p><div class="embedExternal embedImage display-medium float-none"> <div class="embedExternal-content"> <a class="embedImage-link" href="https://us.v-cdn.net/6031942/uploads/06TBBT3YNICD/image.png" rel="nofollow noreferrer noopener ugc" target="_blank"> <img class="embedImage-img" src="https://us.v-cdn.net/6031942/uploads/06TBBT3YNICD/image.png" alt="image.png" height="451" width="865" loading="lazy" data-display-size="medium" data-float="none"></img></a> </div> </div> <p>And that’s it. Now you have your video streaming web server up and running with face detection and recognition with the example from the library. </p><p> </p><h3 data-id="the-esp32-cam-provides-an-inexpensive-way-to-build-more-advanced-home-automation-projects-that-feature-video-taking-photos-and-face-recognition.">The ESP32-CAM provides an inexpensive way to build more advanced home automation projects that feature video, taking photos, and face recognition.</h3><h3 data-id="in-this-tutorial-weve-tested-the-camera-web-server-example-to-test-the-camera-functionalities.-now-the-idea-is-to-modify-the-example-or-write-a-completely-new-code-to-build-other-projects.-for-example-take-photos-and-save-them-to-the-micro-sd-card-when-motion-is-detected-integrate-video-streaming-in-your-home-automation-platform-(like-node-red-or-home-assistant)-and-much-more.">In this tutorial we’ve tested the Camera Web Server example to test the camera functionalities. Now, the idea is to modify the example or write a completely new code to build other projects. For example, take photos and save them to the micro SD card when motion is detected, integrate video streaming in your home automation platform (like Node-RED or Home Assistant), and much more.</h3><p><br></p> </article> </main>