Hello. This is Eric. Can you see me here? yeah~ This is running OpenCV on ESP32. It's working as a standalone and handling
everything on ESP32. With the image obtained from the camera, It's doing Canny edge detection
with OpenCV library in real-time. This is very interesting. OpenCV is built to work on many platforms,
but working standalone on ESP32 is really cool. In fact, it does not include a full version
of OpenCV, but works with a shrunk version of OpenCV. I don't know what project you are trying to do,
but I think many applications are possible with this. This is enough for me. In this video, I will show you how I configure
my build environment to use it. If you can build the shrinked OpenCV for ESP32
without any problems, then this video is not for you. Please find more interesting projects on my
channel. All you need to make this work is memory. It needs more memory than normal work. In addition to containing the OpenCV library,
it requires heap space for image processing. The device used here is TTGO Camera Plus model
and includes ESP32-DOWDQ6. It has 520 KB of SRAM, 8 MB of PSRAM, and
4 MB of Flash memory. Please check yours first. So let's get started. The first thing to check is ESP-IDF is installed
on your system. I'm working on ESP-IDF based project using
Visual Studio Code. A long time ago, I uploaded a video of installing
ESP-IDF on Mac. But it's been a while. You can easily configure the environment by
following the instructions provided by the official site. If you need to install it, this method is
highly recommended. So I believe ESP-IDF is ready. To make sure everything is fine, let's open
the hello world example and try to build it. When the project opens, a popup will appear
asking you to select a compiler. I usually choose GCC 8.4.0 Xtensa-esp32. Okay. I won't touch anything. Just select the port which is connected to
my device. And then Just select Build, Flash, and start
a monitor on your device. This is the magic key. Again. This is for testing using ESP-IDF. If you can't do it, you need to stop this
video here and set it up again. Uploaded to my device successfully. You can see not only the build information
but also device information there. Okay, all looks good. Let's move on. It's time to meet today's star. This is a Github repository where all recipes
are prepared to run OpenCV on ESP32. You can make basic preparations for the OpenCV
project with this person's output. He did a great job. This is today's goal. Building the same code on the same device
and having the same result. It wasn't as easy as I thought. There were a lot of issues. Anyway, let's make a shot. The first thing to do is bring this repository
to your local environment. You can clone it to any folder you want. After that, I'll open the Hello OpenCV example
from VS code. You can see a total of 3 examples here. I'm gonna select Hello OpenCV to simply check
if the OpenCV library works properly. And then I'll try the TTGO Demo which is my
goal for this project. Each demo includes all the pre-built OpenCV
libraries. If the build works normally without any changes,
you can start the project very easily. As before, select the compiler and move on. This is the main cpp file of Hello OpenCV. We have nothing to touch here. It's just to check whether the pre-built OpenCV
is working fine or not. Let me build and flash it at once. It takes time to build, but I made this part
play quickly. You got it, right? The build is successful and it's running on
my connected device. Great. The Mat object used in OpenCV is normally
created and printed. This confirmed the basic OpenCV library works
fine. Now, let me open my target project, the TTGO
demo. If this builds successfully, all preparations
for starting a new project are finished. As before, select the compiler and move on. This time, without modifying anything too,
I just build and then flash. Let's how it goes. oh man,
This time, the error occurs. It says undefined reference to 'sysconf' As I recall,
this should be referenced to return the number of threads available on ESP32. Unfortunately, I've spent a lot of time trying
to solve this, but I haven't gotten a perfect solution yet. Before visiting the GitHub page again,
Let me clean up the project. This is to clear the current failed build. There was an issue report for this, and luckily
I was able to find a workaround there. Seems like if you work on Linux,
you can work with the pre-built OpenCV library he made without any problems. And if you have other problems other than
this, it's also recommended to follow this workaround. This author has shown a way of using Docker
Image. This creates the same environment he built. So, using this, we can get the same result
because we are building it in the same environment. Let me check if I have docker. Oops.
I don't have it. Actually, I deleted it just in advance to
show you from the scratch. Please download it from the Docker site or
install it using Brew. This time I'll get it for a desktop app. In fact, all we need is Docker's CLI. Anyway, let's install it. Let's move fast. It's just downloading and installing. There are really good articles about Docker
and containers, so you can find more detailed information
through Googling. Docker installation is complete. Now let's run Docker in the terminal again. This time the Docker command works fine. Let's pull the docker image he mentioned. Just copy and paste it. oh, I don't need the dollar sign though. Pulling is done.
All looks good. Now go to the esp32-OpenCV folder and run
the docker image. If I don't attach the release version to the
last part, the current latest version of the docker image
is newly downloaded again. So I have to use it this way. Now I'm inside the docker image. Here, it has been activated with the root
account. All you have to do is to build OpenCV. All scripts were ready to go. With this, the OpenCV library in the TTGO
demo will be newly built. Okay.
Seems like the new library is ready. Let me check if there are any changes. Go back to VS Code. And One second. See. There are changes in the OpenCV folder. I'm pretty sure we're on the right track. Finally, it's time to build the project. let's build this project with the new library. I have to succeed this time. Again, running ESP-IDF by docker is
Linux-based version 4.2. My VS Code ESP-IDF is currently the latest
version 4.4.1. So because docker's ESP-IDF has to be used
to build for this project, currently it's working in the console. Project Build Complete. Yes! Finally, it works. The rest of the task is to flash the built
project to the device. You can do it with this command, but I will
use my VS Code. Here you can see the newly built OpenCV library. Because this project has already been built,
I just do flash. It's being uploaded to the device without
any problems. All done. Let's see how this TTGO demo works. It's using LVGL for the GUI. A screen called TTGO Demo is displayed first. After that,
Every 3 seconds RGB mode,
Grayscale mode, Binarized mode and Edge mode are executed
repeatedly. The camera resolution used here is 240 x 240
which is the build-in screen size. On the left, you can see the FPS of each state. Canny Edge Detection is showing the lowest
FPS as it requires the most computation. It makes sense. Other than that, it is calculated to be about
6 fps on average. The performance isn't great but considering
the computing power of ESP32, I think it's pretty good. I'm really looking forward to the next project
with this. Thank you for watching. See you on the next project.