esp32cam摄像+上位机opencv人脸识别

准备工作

esp32cam带底板,开发平台vscode+platformio,摄像头为ov2640,需要esp32连接热点建立服务器,python上位机访问网址,读取图像后opencv识别人脸.

ESP32代码

基于esp32cam例程修改,首先打开PIO home新建esp32cam工程,选择安信可开发板

修改例程,分辨率图像质量来找个合适的帧率,jpeg输出比rgb565帧率高

#include "esp_camera.h"
#include <WiFi.h>
#include<stdio.h>
#include<WiFiClient.h>
#define CAMERA_MODEL_AI_THINKER // Has PSRAM
#include "camera_pins.h"
#include "app_httpd.cpp"
void startCameraServer();
void setupLedFlash(int pin);
bool flag=false;
WiFiClient client;
void setup() {
  Serial.begin(115200);
  Serial.setDebugOutput(true);
  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;
  config.pin_d0 = Y2_GPIO_NUM;
  config.pin_d1 = Y3_GPIO_NUM;
  config.pin_d2 = Y4_GPIO_NUM;
  config.pin_d3 = Y5_GPIO_NUM;
  config.pin_d4 = Y6_GPIO_NUM;
  config.pin_d5 = Y7_GPIO_NUM;
  config.pin_d6 = Y8_GPIO_NUM;
  config.pin_d7 = Y9_GPIO_NUM;
  config.pin_xclk = XCLK_GPIO_NUM;
  config.pin_pclk = PCLK_GPIO_NUM;
  config.pin_vsync = VSYNC_GPIO_NUM;
  config.pin_href = HREF_GPIO_NUM;
  config.pin_sccb_sda = SIOD_GPIO_NUM;
  config.pin_sccb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn = PWDN_GPIO_NUM;
  config.pin_reset = RESET_GPIO_NUM;
  config.xclk_freq_hz = 20000000;
  config.frame_size = FRAMESIZE_SVGA;   // 2560x1440;
  config.pixel_format = PIXFORMAT_JPEG; // for streaming
  config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
  config.fb_location = CAMERA_FB_IN_PSRAM;
  config.jpeg_quality = 10;
  config.fb_count = 1;

  if(config.pixel_format == PIXFORMAT_JPEG){
    if(psramFound()){
      config.jpeg_quality = 10;
      config.fb_count = 2;
      config.grab_mode = CAMERA_GRAB_LATEST;
    } 
  } 

  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);
    return;
  }
  sensor_t * s = esp_camera_sensor_get();
  // initial sensors are flipped vertically and colors are a bit saturated
  if (s->id.PID == OV2640_PID) {
    s->set_vflip(s, 0); // flip it back
    s->set_brightness(s, 1); // up the brightness just a bit
    s->set_saturation(s, 1); // lower the saturation
  }
// Setup LED FLash if LED pin is defined in camera_pins.h
#if defined(LED_GPIO_NUM)
  setupLedFlash(LED_GPIO_NUM);
#endif
  //改为STA模式
  WiFi.begin("****", "******");
  Serial.println("**** BEGIN CONNECTING");
  WiFi.setSleep(false);
  int count1=0;
  while (WiFi.status() != WL_CONNECTED&&count1<5) {
    delay(500);
    Serial.print(".");
    count1++;
  }
  if(WiFi.localIP().toString()=="0.0.0.0"){//连接失败换到另一个wifi
    Serial.println("\n16303 CONNECT FALL TRY ****");
    WiFi.disconnect
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值