esp32-opencv icon indicating copy to clipboard operation
esp32-opencv copied to clipboard

Adjustments for ESP32-cam and ESP-IDF 5.3.0

Open nicklasb opened this issue 1 year ago • 2 comments

Hi,

Not sure if this will work for you, the PR perhaps does way too much, but it makes the hello- and benchmark examples work on ESP-IDF 5.3.0 and a normal ESP32 CAM, I adjusted down the spiffs to fit in 4MB. It should work on the ttgo aswell, but I am not sure. Either way the ESP32 CAM is super cheap and everyone seem to have one.

It might be possible to get the ttgo-demo to work as well actually, but then it would need to use a newer version of lgvl, which is beyond my use case.

nicklasb avatar Aug 10 '24 16:08 nicklasb

@nicklasb

That's nice work.

I built esp32/examples/esp_opencv_tests using your repository. https://github.com/nicklasb/esp32-opencv/tree/master/esp32/examples/esp_opencv_tests

We need sdkconfig.defaults in esp_opencv_tests directory.

Contents of sdkconfig.defaults

#
# Partition Table
#
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"

#
# Serial flasher config
#
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y

#
# Compiler options
#
CONFIG_COMPILER_CXX_EXCEPTIONS=y
CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE=0
CONFIG_CXX_EXCEPTIONS=y
CONFIG_CXX_EXCEPTIONS_EMG_POOL_SIZE=0

#
# Memory protection
#
CONFIG_ESP_MAIN_TASK_STACK_SIZE=20480
CONFIG_ESP_TASK_WDT_EN=n

How to build

We need a esp32/esp32s3 development board that has PSRAM and 4M flash. esp32s2 don't work. esp32s2's ROM is smaller than others. Probably something is missing in the esp32s2 rom component. And we also need to enable PSRAM using menuconfig. PSRAM configuration is different for ESP32 and ESP32S3. For ESP32S3, you need to select QUAD mode PSRAM or OCTAL mode PSRAM depending on your board. Therefore, enabling PSRAM is not included in sdkconfig.defaults. We need to enable PSRAM using memoconfig.


$ idf.py --version
ESP-IDF v5.3-dirty

$ git clone https://github.com/nicklasb/esp32-opencv

$ cd esp32-opencv/esp32/examples/esp_opencv_tests

# Create sdkconfig.defaults

$ idf.py set-target {esp32/esp32s3}

$ idf.py menuconfig

# Enable PSRAM 

$ idf.py flash monitor


libpng warning: iCCP: known incorrect sRGB profile
I (2633) opencv_tests: Image read of 120x160x1, with 0 pixel depth
libpng warning: iCCP: known incorrect sRGB profile
I (2943) opencv_tests: Image read of 240x320x1, with 0 pixel depth
libpng warning: iCCP: known incorrect sRGB profile
I (3793) opencv_tests: Image read of 480x640x1, with 0 pixel depth
libpng warning: iCCP: known incorrect sRGB profile

+------------------------------------------------+-------------+-------------+-------------+-------------+
| Function name and arguments                    | BUILD_TYPE=Release                                    |
+------------------------------------------------+-------------+-------------+-------------+-------------+
|                                                |     160x120 |     320x240 |     640x480 |    1024x768 |
+================================================+=============+=============+=============+=============+
|                                                                                                        |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| **Threshold**                                                                                          |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| binaryThreshold                                |         3.1 |          15 |          60 |         154 |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| triangleThreshold                              |         4.0 |          21 |          83 |         213 |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| OTSUThreshold                                  |         7.7 |          25 |          87 |         216 |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| toZeroThreshold                                |         3.2 |          15 |          60 |         155 |
+------------------------------------------------+-------------+-------------+-------------+-------------+
|                                                                                                        |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| **Blurring**                                                                                           |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| GaussianBlur 3x3 kernel                        |         5.3 |          19 |          72 |         181 |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| medianBlur 3x3 kernel                          |          27 |         106 |         423 |        1081 |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| bilateralFilter diameter=5                     |          67 |         250 |         976 |        2483 |
+------------------------------------------------+-------------+-------------+-------------+-------------+
|                                                                                                        |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| **Morphological tranforms**                                                                            |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| erode 5x5 kernel                               |         7.0 |          27 |         105 |         266 |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| dilate 5x5 kernel                              |         7.1 |          27 |         105 |         266 |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| open 5x5 kernel                                |          12 |          52 |         204 |         519 |
+------------------------------------------------+-------------+-------------+-------------+-------------+
|                                                                                                        |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| **Resize image**                                                                                       |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| resize linear interpolation                    |         4.2 |          17 |          63 |         155 |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| resize cubic interpolation                     |         7.4 |          27 |         106 |         278 |
+------------------------------------------------+-------------+-------------+-------------+-------------+
|                                                                                                        |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| **Edge detection**                                                                                     |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| Sobel                                          |          16 |          57 |         216 |         821 |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| Canny                                          |          38 |         132 |         489 |        1941 |
+------------------------------------------------+-------------+-------------+-------------+-------------+
|                                                                                                        |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| **Hough tranformations**                                                                               |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| HoughLines                                     |         385 |         963 |        3472 |        5409 |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| HoughLines probabilistic                       |         924 |        2189 |        6473 |       11174 |
+------------------------------------------------+-------------+-------------+-------------+-------------+

Using ESP32-CAM

ESP32-CAM is a good choice, but it gives errors in some tests.

I don't know why.

+------------------------------------------------+-------------+-------------+-------------+-------------+
| **Edge detection**                                                                                     |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| Sobel                                          |          23 |          80 |         302 |         821 |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| Canny                                          |          56 |         188 |         655 |         ERR |
+------------------------------------------------+-------------+-------------+-------------+-------------+
|                                                                                                        |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| **Hough tranformations**                                                                               |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| HoughLines                                     |         536 |        1184 |        3717 |         ERR |
+------------------------------------------------+-------------+-------------+-------------+-------------+
| HoughLines probabilistic                       |        1113 |        2505 |        6963 |         ERR |
+------------------------------------------------+-------------+-------------+-------------+-------------+

nopnop2002 avatar Sep 05 '24 23:09 nopnop2002

ERROR


Error: app partition is too small for binary hello_opencv.bin size 0x103fb0:

  • Part 'factory' 0/0 @ 0x10000 size 0x100000 (overflow 0x3fb0) ninja: build stopped: subcommand failed.

SOLUTION

Just leaving this comment for easy navigation.

for the vscode extension ESP-IDF, go to SDK Configuration editor (Ctrl + Shift + P type Menuconfig) then like @nopnop2002's comment, edit the configurations given under the heading Contents of sdkconfig.defaults. (thanks for the solution @nopnop2002)

Partition table

choose the value: Custom partition table CSV (Notice the name paritions.csv in your folder and in the setting be same) image

serial flasher

set the flash size to higher image

Compiler

set the Enable C++ exceptions image

memory protection

change the value of Main task stack size to 20480

image

the watch dog is not set so no need to change it. you can see the search word in each pictures.

memory error in esp32s3

riderman10000 avatar Sep 17 '24 18:09 riderman10000