# ESP32 Camera Driver
## General Information
This repository hosts ESP32 compatible driver for OV2640, OV3660, OV5640 and OV7725 image sensors. Additionally it provides a few tools, which allow converting the captured frame data to the more common BMP and JPEG formats.
## 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`
- Include `esp_camera.h` in your code
### Using PlatformIO
On the `env` section of `platformio.ini`, add the following:
```ini
[env]
lib_deps =
esp32-camera
```
Now the `esp_camera.h` is available to be included:
```c
#include "esp_camera.h"
```
Enable PSRAM on `menuconfig` or type it direclty on `sdkconfig`. Check the [official doc](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/kconfig.html#config-esp32-spiram-support) for more info.
```
CONFIG_ESP32_SPIRAM_SUPPORT=y
```
**Make sure to append** [this `Kconfig`](./Kconfig) content into the `Kconfig` of your project. Then, choose the configurations according to your setup.
### Kconfig options
| config | description | default |
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------ |
| CONFIG_OV2640_SUPPORT | Support for OV2640 camera | enabled |
| CONFIG_OV7725_SUPPORT | Support for OV7725 camera | disabled |
| CONFIG_OV3660_SUPPORT | Support for OV3660 camera | enabled |
| CONFIG_OV5640_SUPPORT | Support for OV5640 camera | enabled |
| CONFIG_SCCB_HARDWARE_I2C | Enable this option if you want to use hardware I2C to control the camera. Disable this option to use software I2C. | enabled |
| CONFIG_SCCB_HARDWARE_I2C_PORT | I2C peripheral to use for SCCB. Can be I2C0 and I2C1. | CONFIG_SCCB_HARDWARE_I2C_PORT1 |
| CONFIG_CAMERA_TASK_PINNED_TO_CORE | Pin the camera handle task to a certain core(0/1). It can also be done automatically choosing NO_AFFINITY. Can be CAMERA_CORE0, CAMERA_CORE1 or NO_AFFINITY. | CONFIG_CAMERA_CORE0 |
## Examples
### Initialization
```c
#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
#define CAM_PIN_SIOD 26
#define CAM_PIN_SIOC 27
#define CAM_PIN_D7 35
#define CAM_PIN_D6 34
#define CAM_PIN_D5 39
#define CAM_PIN_D4 36
#define CAM_PIN_D3 19
#define CAM_PIN_D2 18
#define CAM_PIN_D1 5
#define CAM_PIN_D0 4
#define CAM_PIN_VSYNC 25
#define CAM_PIN_HREF 23
#define CAM_PIN_PCLK 22
static camera_config_t camera_config = {
.pin_pwdn = CAM_PIN_PWDN,
.pin_reset = CAM_PIN_RESET,
.pin_xclk = CAM_PIN_XCLK,
.pin_sscb_sda = CAM_PIN_SIOD,
.pin_sscb_scl = CAM_PIN_SIOC,
.pin_d7 = CAM_PIN_D7,
.pin_d6 = CAM_PIN_D6,
.pin_d5 = CAM_PIN_D5,
.pin_d4 = CAM_PIN_D4,
.pin_d3 = CAM_PIN_D3,
.pin_d2 = CAM_PIN_D2,
.pin_d1 = CAM_PIN_D1,
.pin_d0 = CAM_PIN_D0,
.pin_vsync = CAM_PIN_VSYNC,
.pin_href = CAM_PIN_HREF,
.pin_pclk = CAM_PIN_PCLK,
//XCLK 20MHz or 10MHz for OV2640 double FPS (Experimental)
.xclk_freq_hz = 20000000,
.ledc_timer = LEDC_TIMER_0,
.ledc_channel = LEDC_CHANNEL_0,
.pixel_format = PIXFORMAT_JPEG,//YUV422,GRAYSCALE,RGB565,JPEG
.frame_size = FRAMESIZE_UXGA,//QQVGA-QXGA Do not use sizes above QVGA when not JPEG
.jpeg_quality = 12, //0-63 lower number means higher quality
.fb_count = 1 //if more than one, i2s runs in continuous mode. Use only with JPEG
};
esp_err_t camera_init(){
//power up the camera if PWDN pin is defined
if(CAM_PIN_PWDN != -1){
pinMode(CAM_PIN_PWDN, OUTPUT);
digitalWrite(CAM_PIN_PWDN, LOW);
}
//initialize the camera
esp_err_t err = esp_camera_init(&camera_config);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Camera Init Failed");
return err;
}
return ESP_OK;
}
esp_err_t camera_capture(){
//acquire a frame
camera_fb_t * fb = esp_camera_fb_get();
if (!fb) {
ESP_LOGE(TAG, "Camera Capture Failed");
return ESP_FAIL;
}
//replace this with your own function
process_image(fb->width, fb->height, fb->format, fb->buf, fb->len);
//return the frame buffer back to the driver for reuse
esp_camera_fb_return(fb);
return ESP_OK;
}
```
### JPEG HTTP Capture
```c
#include "esp_camera.h"
#include "esp_http_server.h"
#include "esp_timer.h"
typedef struct {
httpd_req_t *req;
size_t len;
} jpg_chunking_t;
static size_t jpg_encode_stream(void * arg, size_t index, const void* data, size_t len){
jpg_chunking_t *j = (jpg_chunking_t *)arg;
if(!index){
j->len = 0;
}
if(httpd_resp_send_chunk(j->req, (const char *)data, len) != ESP_OK){
return 0;
}
j->len += len;
return len;
}
esp_err_t jpg_httpd_handler(httpd_req_t *req){
camera_fb_t * fb = NULL;
esp_err_t res = ESP_OK;
size_t fb_len = 0;
int64_t fr_start = esp_timer_get_time();
fb = esp_camera_fb_get();
if (!fb) {
ESP_LOGE(TAG, "Camera capture failed");
httpd_resp_send_500(req);
return ESP_FAIL;
}
res = httpd_resp_set_type(req, "image/jpeg");
if(res == ESP_OK){
res = httpd_resp_set_hdr(req, "Content-Disposition", "inline; filename=capture.jpg");
}
if(res == ESP_OK){
if(fb->format == PIXFORMAT_JPEG){
fb_len = fb->len;
res = httpd_resp_send(req, (const char *)fb->buf, fb->len);
} else {
jpg_chunking_t jchunk = {req, 0};
res = frame2jpg_cb(fb, 80, jpg_encode_stream, &jchunk)?ESP_OK:ESP_FAIL;
httpd_resp_send_chunk(req, NULL, 0);
fb_len = jchunk
没有合适的资源?快使用搜索试试~ 我知道了~
esp32 通过WiFi联网控制摄像头采集图像并通过oled屏幕显示
共130个文件
c:65个
h:25个
bak:5个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 5 下载量 112 浏览量
2022-07-13
07:38:03
上传
评论 10
收藏 1.11MB ZIP 举报
温馨提示
esp32 通过WiFi联网控制摄像头采集图像并通过oled屏幕显示
资源推荐
资源详情
资源评论
收起资源包目录
esp32 通过WiFi联网控制摄像头采集图像并通过oled屏幕显示 (130个子文件)
camera.c.bak 47KB
main.c.bak 16KB
esp_camera.h.bak 7KB
README.md.bak 1KB
CMakeLists.txt.bak 267B
feature_tests.bin 43KB
CMakeDetermineCompilerABI_CXX.bin 41KB
CMakeDetermineCompilerABI_C.bin 40KB
u8g_font_data.c 4.46MB
chessengine.c 62KB
camera.c 47KB
u8g_font.c 36KB
ov5640.c 33KB
ov3660.c 30KB
main.c 19KB
CMakeCCompilerId.c 19KB
u8g_dev_ssd1306_128x64.c 17KB
ov2640.c 16KB
ov7725.c 15KB
u8g_ll_api.c 15KB
u8g_com_i2c.c 13KB
u8g_rot.c 13KB
yuv.c 12KB
u8g_dev_ssd1306_128x32.c 11KB
twi.c 11KB
u8g_pb8h1.c 9KB
u8g_circle.c 9KB
to_bmp.c 9KB
sccb.c 8KB
u8g_ellipse.c 8KB
u8g_polygon.c 8KB
u8g_dev_ssd1306_64x48.c 7KB
u8g_com_io.c 7KB
u8g_pbxh24.c 7KB
u8g_delay.c 6KB
u8g_com_msp430_hw_spi.c 6KB
u8g_pb16h1.c 5KB
u8g_pb32h1.c 5KB
u8g_pb16h2.c 5KB
u8g_pb8h1f.c 5KB
u8g_scale.c 5KB
u8g_pb14v1.c 5KB
u8g_pb16v1.c 5KB
u8g_rect.c 5KB
u8g_pb8v1.c 5KB
u8g_pb8h8.c 5KB
u8g_pbxh16.c 5KB
u8g_com_api.c 4KB
u8g_virtual_screen.c 4KB
u8g_clip.c 4KB
u8g_pb16v2.c 4KB
u8g_pb.c 4KB
u8g_pb8h2.c 4KB
u8g_com_raspberrypi_ssd_i2c.c 4KB
u8g_state.c 4KB
u8g_pb8v2.c 4KB
u8g_bitmap.c 4KB
u8g_com_std_sw_spi.c 4KB
esp_jpg_decode.c 4KB
take_picture.c 4KB
u8g_com_api_16gr.c 3KB
u8g_com_raspberrypi_hw_spi.c 3KB
u8g_cursor.c 3KB
u8g_line.c 2KB
u8g_arm.c 2KB
u8g_page.c 2KB
led.c 2KB
u8g_u8toa.c 2KB
u8g_u16toa.c 2KB
u8g_com_null.c 2KB
xclk.c 2KB
sensor.c 1KB
feature_tests.c 688B
cmake.check_cache 85B
CMakeCXXCompiler.cmake 5KB
CMakeCCompiler.cmake 2KB
CMakeSystem.cmake 380B
CMakeRCCompiler.cmake 228B
jpge.cpp 28KB
CMakeCXXCompilerId.cpp 18KB
to_jpg.cpp 7KB
.cproject 1KB
.cproject 1KB
feature_tests.cxx 10KB
a.exe 41KB
a.exe 40KB
.gitignore 8B
u8g.h 90KB
ov7725_regs.h 22KB
ov2640_settings.h 11KB
ov5640_regs.h 10KB
ov3660_regs.h 10KB
ov5640_settings.h 8KB
ov3660_settings.h 7KB
ov2640_regs.h 7KB
esp_camera.h 7KB
sensor.h 6KB
jpge.h 5KB
img_converters.h 5KB
u8g_arm.h 1KB
共 130 条
- 1
- 2
ZCY5202015
- 粉丝: 325
- 资源: 747
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页