├── Images ├── 1.jpg └── 2.png ├── README.md └── demo.ino /Images/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FunCodersTeam/ESP32CAM_BaiduAI/5b364d6994b26c2cbbae67b3e3aefd491675d196/Images/1.jpg -------------------------------------------------------------------------------- /Images/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FunCodersTeam/ESP32CAM_BaiduAI/5b364d6994b26c2cbbae67b3e3aefd491675d196/Images/2.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FunCodersTeam/ESP32CAM_BaiduAI/5b364d6994b26c2cbbae67b3e3aefd491675d196/README.md -------------------------------------------------------------------------------- /demo.ino: -------------------------------------------------------------------------------- 1 | #include "esp_camera.h" 2 | #include "soc/soc.h" 3 | #include "soc/rtc_cntl_reg.h" 4 | #include 5 | #include 6 | 7 | #define SSID "......" 8 | #define PASSWORD "......" 9 | #define ACCESS_TOKEN "......" 10 | #define Json_begin "{\"image\":\"" 11 | #define Json_end "\",\"image_type\":\"BASE64\",\"group_id_list\":\"......\"}" 12 | 13 | #define PWDN_GPIO_NUM 32 14 | #define RESET_GPIO_NUM -1 15 | #define XCLK_GPIO_NUM 0 16 | #define SIOD_GPIO_NUM 26 17 | #define SIOC_GPIO_NUM 27 18 | #define Y9_GPIO_NUM 35 19 | #define Y8_GPIO_NUM 34 20 | #define Y7_GPIO_NUM 39 21 | #define Y6_GPIO_NUM 36 22 | #define Y5_GPIO_NUM 21 23 | #define Y4_GPIO_NUM 19 24 | #define Y3_GPIO_NUM 18 25 | #define Y2_GPIO_NUM 5 26 | #define VSYNC_GPIO_NUM 25 27 | #define HREF_GPIO_NUM 23 28 | #define PCLK_GPIO_NUM 22 29 | 30 | static void Baidu_AI(camera_fb_t* &fb){ 31 | String base64 = base64::encode(fb->buf,fb->len); 32 | uint16_t len = base64.length(); 33 | WiFiClientSecure client; 34 | if(client.connect("aip.baidubce.com",443)){ 35 | Serial.println("Connection succeeded"); 36 | client.println("POST /rest/2.0/face/v3/search?access_token=" + String(ACCESS_TOKEN) + " HTTP/1.1"); 37 | client.println(F("Host: aip.baidubce.com")); 38 | client.println("Content-Length: " + String(len + strlen(Json_begin Json_end))); 39 | client.println(F("Content-Type: application/json")); 40 | client.println(); 41 | client.print(F(Json_begin)); 42 | for(uint16_t i = 0;i < len;i += 4096) //分段发送 43 | if(len > i + 4096) 44 | client.print(base64.substring(i,i+4096)); 45 | else{ 46 | client.print(base64.substring(i)); 47 | break; 48 | } 49 | client.print(F(Json_end)); 50 | Serial.println("Waiting for response..."); 51 | uint8_t i = 0; 52 | while (!client.available()){ 53 | i += 1; 54 | delay(100); 55 | if(i > 200){ //timeout 56 | Serial.println("No response..."); 57 | break; 58 | } 59 | } 60 | while (client.available()){ 61 | Serial.print(char(client.read())); 62 | } 63 | client.stop(); 64 | Serial.println(); 65 | }else Serial.println("Connection failed"); 66 | } 67 | 68 | void setup() 69 | { 70 | WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG,0); //关闭欠压检测 71 | Serial.begin(115200); 72 | WiFi.begin(SSID,PASSWORD); 73 | while (WiFi.status() != WL_CONNECTED){ 74 | Serial.println("Waitting for wifi connection..."); 75 | delay(500); 76 | } 77 | camera_config_t config; 78 | config.ledc_channel = LEDC_CHANNEL_0; 79 | config.ledc_timer = LEDC_TIMER_0; 80 | config.pin_d0 = Y2_GPIO_NUM; 81 | config.pin_d1 = Y3_GPIO_NUM; 82 | config.pin_d2 = Y4_GPIO_NUM; 83 | config.pin_d3 = Y5_GPIO_NUM; 84 | config.pin_d4 = Y6_GPIO_NUM; 85 | config.pin_d5 = Y7_GPIO_NUM; 86 | config.pin_d6 = Y8_GPIO_NUM; 87 | config.pin_d7 = Y9_GPIO_NUM; 88 | config.pin_xclk = XCLK_GPIO_NUM; 89 | config.pin_pclk = PCLK_GPIO_NUM; 90 | config.pin_vsync = VSYNC_GPIO_NUM; 91 | config.pin_href = HREF_GPIO_NUM; 92 | config.pin_sscb_sda = SIOD_GPIO_NUM; 93 | config.pin_sscb_scl = SIOC_GPIO_NUM; 94 | config.pin_pwdn = PWDN_GPIO_NUM; 95 | config.pin_reset = RESET_GPIO_NUM; 96 | config.xclk_freq_hz = 20000000; 97 | config.pixel_format = PIXFORMAT_JPEG; 98 | config.frame_size = FRAMESIZE_VGA; 99 | config.jpeg_quality = 10; 100 | config.fb_count = 1; 101 | while(esp_camera_init(&config) != ESP_OK){ 102 | Serial.println("Waitting for camera init..."); 103 | delay(500); 104 | } 105 | } 106 | 107 | void loop() 108 | { 109 | while(WiFi.status() != WL_CONNECTED){ //断线重连 110 | WiFi.reconnect(); 111 | delay(500); 112 | } 113 | camera_fb_t *fb = esp_camera_fb_get(); 114 | if(!fb)return; 115 | Serial.println("Got image"); 116 | Baidu_AI(fb); 117 | esp_camera_fb_return(fb); 118 | } 119 | --------------------------------------------------------------------------------