ESP32 Camera Driver

ESP32 Camera Driver

General Information

This repository hosts ESP32 series Soc compatible driver for image sensors. Additionally it provides a few tools, which allow converting the captured frame data to the more common BMP and JPEG formats.

Supported Soc

  • ESP32
  • ESP32-S2
  • ESP32-S3

Supported Sensor

model max resolution color type output format Len Size
OV2640 1600 x 1200 color YUV(422/420)/YCbCr422
RGB565/555
8-bit compressed data
8/10-bit Raw RGB data
1/4"
OV3660 2048 x 1536 color raw RGB data
RGB565/555/444
CCIR656
YCbCr422
compression
1/5"
OV5640 2592 x 1944 color RAW RGB
RGB565/555/444
CCIR656
YUV422/420
YCbCr422
compression
1/4"
OV7670 640 x 480 color Raw Bayer RGB
Processed Bayer RGB
YUV/YCbCr422
GRB422
RGB565/555
1/6"
OV7725 640 x 480 color Raw RGB
GRB 422
RGB565/555/444
YCbCr 422
1/4"
NT99141 1280 x 720 color YCbCr 422
RGB565/555/444
Raw
CCIR656
JPEG compression
1/4"
GC032A 640 x 480 color YUV/YCbCr422
RAW Bayer
RGB565
1/10"
GC0308 640 x 480 color YUV/YCbCr422
RAW Bayer
RGB565
1/6.5"
GC2145 1600 x 1200 color YUV/YCbCr422
RAW Bayer
RGB565
1/5"
BF3005 640 x 480 color YUV/YCbCr422
RAW Bayer
RGB565
1/4"

Important to Remember

  • Except when using CIF or lower resolution with JPEG, the driver requires PSRAM to be installed and activated.
  • Using YUV or RGB puts a lot of strain on the chip because writing to PSRAM is not particularly fast. The result is that image data might be missing. This is particularly true if WiFi is enabled. If you need RGB data, it is recommended that JPEG is captured and then turned into RGB using fmt2rgb888 or fmt2bmp/frame2bmp.
  • When 1 frame buffer is used, the driver will wait for the current frame to finish (VSYNC) and start I2S DMA. After the frame is acquired, I2S will be stopped and the frame buffer returned to the application. This approach gives more control over the system, but results in longer time to get the frame.
  • When 2 or more frame bufers are used, I2S is running in continuous mode and each frame is pushed to a queue that the application can access. This approach puts more strain on the CPU/Memory, but allows for double the frame rate. Please use only with JPEG.

Installation Instructions

Using esp-idf

  • Clone or download and extract the repository to the components folder of your ESP-IDF project
  • Enable PSRAM in menuconfig (also set Flash and PSRAM frequiencies to 80MHz)
  • Include esp_camera.h in your code

Using PlatformIO

The easy way – on the env section of platformio.ini, add the following:

[env]
lib_deps =
  esp32-camera

Now the esp_camera.h is available to be included:

#include "esp_camera.h"

Enable PSRAM on menuconfig or type it direclty on sdkconfig. Check the official doc for more info.

CONFIG_ESP32_SPIRAM_SUPPORT=y

Arduino The easy-way (content above) only seems to work if you’re using framework=arduino which seems to take a bunch of the guesswork out (thanks Arduino!) but also suck up a lot more memory and flash, almost crippling the performance. If you plan to use the framework=espidf then read the sections below carefully!!

Platform.io lib/submodule (for framework=espidf)

It’s probably easier to just skip the platform.io library registry version and link the git repo as a submodule. (i.e. using code outside the platform.io library management). In this example we will install this as a submodule inside the platform.io $project/lib folder:

cd $project\lib
git submodule add -b master https://github.com/espressif/esp32-camera.git

Then in platformio.ini file

build_flags =
   -I../lib/esp32-camera

After that #include "esp_camera.h" statement will be available. Now the module is included, and you’re hopefully back to the same place as the easy-Arduino way.

Warning about platform.io/espidf and fresh (not initialized) git repos
There is a sharp-edge on you’ll discover in the platform.io build process (in espidf v3.3 & 4.0.1) where a project which has only had git init but nothing committed will crash platform.io build process with highly non-useful output. The cause is due to lack of a version (making you think you did something wrong, when you didn’t at all) - the output is horribly non-descript. Solution: the devs want you to create a file called version.txt with a number in it, or simply commit any file to the projects git repo and use git. This happens because platform.io build process tries to be too clever and determine the build version number from the git repo - it’s a sharp edge you’ll only encounter if you’re experimenting on a new project with no commits … like wtf is my camera not working let’s try a ‘clean project’?!

Platform.io Kconfig

Kconfig is used by the platform.io menuconfig (accessed by running: pio run -t menuconfig) to interactively manage the various #ifdef statements throughout the espidf and supporting libraries (i.e. this repo: esp32-camera and arduino-esp32.git). The menuconfig process generates the sdkconfig file which is ultimately used behind the scenes by espidf compile+build process.

Make sure to append or symlink this Kconfig content into the Kconfig of your project.

You symlink (or copy) the included Kconfig into your platform.io projects src directory. The file should be named Kconfig.projbuild in your projects src\ directory or you could also add the library path to a CMakefile.txt and hope the Kconfig (or Kconfig.projbuild) gets discovered by the menuconfig process, though this unpredictable for me.

The unpredictable wonky behavior in platform.io build process around Kconfig naming (Kconfig vs. Kconfig.projbuild) occurs between espidf versions 3.3 and 4.0 - but if you don’t see “Camera configuration” in your pio run -t menuconfig then there is no point trying to test camera code (it may compile, but it probably won’t work!) and it seems the platform.io devs (when they built their wrapper around the espidf menuconfig) didn’t implement it properly. You’ve probably already figured out you can’t use the espidf build tools since the files are in totally different locations and also different versions with sometimes different syntax. This is one of those times you might consider changing the platformio.ini from platform=espressif32 to platform=https://github.com/platformio/platform-espressif32.git#develop to get a more recent version of the espidf 4.0 tools.

However with a bit of patience and experimenting you’ll figure the Kconfig out. Once Kconfig (or Kconfig.projbuild) is working then you will be able to choose the configurations according to your setup or the camera libraries will be compiled. Although you might also need to delete your .pio/build directory before the options appear … again, the pio run -t menuconfig doens’t always notice the new Kconfig files!

If you miss-skip-ignore this critical step the camera module will compile but camera logic inside the library will be ‘empty’ because the Kconfig sets the proper #ifdef statements during the build process to initialize the selected cameras. It’s very not optional!

Examples

Initialization

#include "esp_camera.h"

//WROVER-KIT PIN Map
#define CAM_PIN_PWDN    -1 //power down is not used
#define CAM_PIN_RESET   -1 //software reset will be performed
#define CAM_PIN_XCLK    21
#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

藤一泓

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值