ESP32-CAM--使用(四)

ESP32 同时被 2 个专栏收录
17 篇文章 8 订阅
28 篇文章 3 订阅
#include "SSD1306.h"
#include "esp_camera.h"

SSD1306 display(0x3c, 15, 14); // sda:15,scl:14

#define PWDN_GPIO_NUM     32
#define RESET_GPIO_NUM    -1
#define XCLK_GPIO_NUM      0
#define SIOD_GPIO_NUM     26
#define SIOC_GPIO_NUM     27

#define Y9_GPIO_NUM       35
#define Y8_GPIO_NUM       34
#define Y7_GPIO_NUM       39
#define Y6_GPIO_NUM       36
#define Y5_GPIO_NUM       21
#define Y4_GPIO_NUM       19
#define Y3_GPIO_NUM       18
#define Y2_GPIO_NUM        5
#define VSYNC_GPIO_NUM    25
#define HREF_GPIO_NUM     23
#define PCLK_GPIO_NUM     22


static camera_config_t camera_config = {
    .pin_pwdn  = PWDN_GPIO_NUM,
    .pin_reset = RESET_GPIO_NUM,
    .pin_xclk = XCLK_GPIO_NUM,
    .pin_sscb_sda = SIOD_GPIO_NUM,
    .pin_sscb_scl = SIOC_GPIO_NUM,

    .pin_d7 = Y9_GPIO_NUM,
    .pin_d6 = Y8_GPIO_NUM,
    .pin_d5 = Y7_GPIO_NUM,
    .pin_d4 = Y6_GPIO_NUM,
    .pin_d3 = Y5_GPIO_NUM,
    .pin_d2 = Y4_GPIO_NUM,
    .pin_d1 = Y3_GPIO_NUM,
    .pin_d0 = Y2_GPIO_NUM,
    .pin_vsync = VSYNC_GPIO_NUM,
    .pin_href = HREF_GPIO_NUM,
    .pin_pclk = PCLK_GPIO_NUM,

    //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_GRAYSCALE,//YUV422,GRAYSCALE,RGB565,JPEG
    .frame_size = FRAMESIZE_QQVGA,//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(){
    //initialize the camera
    esp_err_t err = esp_camera_init(&camera_config);
    if (err != ESP_OK) {
        Serial.print("Camera Init Failed");
        return err;
    }
    return ESP_OK;
}

void process_image(int16_t x, int16_t y, int16_t width, int16_t height, const uint8_t *image, int16_t len)
{

  Serial.println("");

  display.drawXbm(0, 0, width, height, image);
  display.display();
}

esp_err_t camera_capture(){
    uint8_t * buf = NULL;
    size_t buf_len = 0;  
    
    //acquire a frame
    camera_fb_t * fb = esp_camera_fb_get();
    if (!fb) {
        Serial.print("Camera Capture Failed");
        return ESP_FAIL;
    }
    
    //bool converted = frame2bmp(fb, &buf, &buf_len);

//    for(int i = 0;i < fb->len;i++)
//    {
//      Serial.print(fb->buf[i], HEX);
//      Serial.print(" ");
//    } 
//    Serial.println();   
    
    Serial.print(fb->len);
    //process_image(0, 0,128, 64, buf, buf_len);
    
    process_image(0, 0,128, 64, fb->buf, fb->len);
  
    esp_camera_fb_return(fb);
    return ESP_OK;
}


void setup() {
  Serial.begin(115200);
  display.init();
  camera_init();
  camera_capture();
  Serial.println("sys is running");
}

void loop() {
  delay(5000);
  camera_capture();

}
  • 2
    点赞
  • 1
    评论
  • 13
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

相关推荐
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值