Error compiling to board ai thinker

hello i am new to the forum so i dont know much, i have been working on a project in which i use a esp32 cam modudle but when i try to upload the code it says error compiling to board esp32. Here is my code:

#include <WiFi.h>
#include <WiFiAP.h>
#include <WiFiClient.h>
#include <WiFiGeneric.h>
#include <WiFiMulti.h>
#include <WiFiScan.h>
#include <WiFiServer.h>
#include <WiFiSTA.h>
#include <WiFiType.h>
#include <WiFiUdp.h>
#include "Arduino.h"
#include "esp_camera.h"
#include <base64.h>
#include "camera_pins.h"

// Select camera model
//#define CAMERA_MODEL_WROVER_KIT // Has PSRAM
//#define CAMERA_MODEL_ESP_EYE // Has PSRAM
//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM
//#define CAMERA_MODEL_M5STACK_WIDE  // Has PSRAM
#define CAMERA_MODEL_AI_THINKER // Has PSRAM
//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM

const char* ssid = "Hope Cottage";
const char* password = "pereira07";

void setup() {
  Serial.begin(9600);
  Serial1.begin(19200);
  ESP_BT.begin; //Name of your Bluetooth Signal
  Serial1.println("Bluetooth Device is Ready to Pair");
  if (ESP_BT.available()) //Check if we receive anything from Bluetooth
  {Serial1.println("connected");
  
  Serial.setDebugOutput(true);
  Serial.println();
 
  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_sscb_sda = SIOD_GPIO_NUM;
  config.pin_sscb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn = PWDN_GPIO_NUM;
  config.pin_reset = RESET_GPIO_NUM;
  config.xclk_freq_hz = 20000000;
  config.pixel_format = PIXFORMAT_JPEG;
  
  // if PSRAM IC present, init with UXGA resolution and higher JPEG quality
  //                      for larger pre-allocated frame buffer.
  if(psramFound()){
    config.frame_size = FRAMESIZE_QVGA;
    config.jpeg_quality = 10;
    config.fb_count = 2;
  } else {
    config.frame_size = FRAMESIZE_QVGA;
    config.jpeg_quality = 12;
    config.fb_count = 1;
  }

#if defined(CAMERA_MODEL_ESP_EYE)
  pinMode(13, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
#endif

  // camera init
  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);
    return;
  }


#if defined(CAMERA_MODEL_M5STACK_WIDE)
  s->set_vflip(s, 1);
  s->set_hmirror(s, 1);
#endif

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  
  classifyImage();
  
}
void classifyImage() {
  
  // Capture picture
   camera_fb_t * fb = NULL;
   fb = esp_camera_fb_get();
   
   if(!fb) {
    Serial.println("Camera capture failed");
    return;
   }

  size_t size = fb->len;
  String buffer = base64::encode((uint8_t *) fb->buf, fb->len);


String payload = "{\"inputs\": [{ \"data\": {\"image\": {\"base64\": \"" + buffer + "\"}}}]}";
buffer = "";

  // Uncomment this if you want to show the payload
  // Serial.println(payload);
  esp_camera_fb_return(fb);
  // Generic model
  String model_id = "aaa03c23b3724a16a56b629203edc62c";

  HTTPClient http;
  http.begin("https://api.clarifai.com/v2/models/" + model_id + "/outputs");
  http.addHeader("Content-Type", "application/json");     
  http.addHeader("Authorization", "Key your_key"); 
  int response_code = http.POST(payload);
  // Parse the json response: Arduino assistant
const int jsonSize = JSON_ARRAY_SIZE(1) + JSON_ARRAY_SIZE(20) + 3*JSON_OBJECT_SIZE(1) + 6*JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + 20*JSON_OBJECT_SIZE(4) + 2*JSON_OBJECT_SIZE(6);
DynamicJsonDocument doc(jsonSize);


for (int i=0; i < 10; i++) {
  const int name = doc["outputs"][0]["data"]["concepts"][i]["name"];
  const float p = doc["outputs"][0]["data"]["concepts"][i]["value"];
    
  Serial.println("=====================");
  Serial.print("Name:");
  Serial.println(name);
  Serial.print("Prob:");
  Serial.println(p);
  Serial.println();
 }
}

and this is the error that i get:

Arduino: 1.8.19 (Windows 10), Board: "ESP32 Wrover Module, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), QIO, 40MHz, 921600, None"

In file included from C:\Users\USER\OneDrive\Documents\Arduino\sketch_jan22a\sketch_jan22a.ino:14:

C:\Users\USER\OneDrive\Documents\Arduino\libraries\esp32-cam-mjpeg-master/camera_pins.h:98:2: error: #error "Camera model not selected"

#error "Camera model not selected"

^~~~~

Multiple libraries were found for "WiFi.h"

Used: C:\Users\USER\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.2\libraries\WiFi

Not used: H:\Arduino\libraries\WiFi

exit status 1

Error compiling for board ESP32 Wrover Module.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Pls help me to solve this issue and thanks in advance
cheers
sumithPreformatted text

this error happens because this line of your sketch:

must be located above this line in the sketch:

1 Like

i will try this thank you

i made the changes as you said but now it is showing this error:

Arduino: 1.8.19 (Windows 10), Board: "ESP32 Wrover Module, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), QIO, 40MHz, 921600, None"

C:\Users\USER\OneDrive\Documents\Arduino\sketch_jan22a\sketch_jan22a.ino: In function 'void classifyImage()':

sketch_jan22a:127:22: error: 'JSON_ARRAY_SIZE' was not declared in this scope

const int jsonSize = JSON_ARRAY_SIZE(1) + JSON_ARRAY_SIZE(20) + 3JSON_OBJECT_SIZE(1) + 6JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + 20JSON_OBJECT_SIZE(4) + 2JSON_OBJECT_SIZE(6);

                  ^~~~~~~~~~~~~~~

C:\Users\USER\OneDrive\Documents\Arduino\sketch_jan22a\sketch_jan22a.ino:127:22: note: suggested alternative: 'LWIP_ARRAYSIZE'

const int jsonSize = JSON_ARRAY_SIZE(1) + JSON_ARRAY_SIZE(20) + 3JSON_OBJECT_SIZE(1) + 6JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + 20JSON_OBJECT_SIZE(4) + 2JSON_OBJECT_SIZE(6);

                  ^~~~~~~~~~~~~~~

                  LWIP_ARRAYSIZE

sketch_jan22a:127:67: error: 'JSON_OBJECT_SIZE' was not declared in this scope

const int jsonSize = JSON_ARRAY_SIZE(1) + JSON_ARRAY_SIZE(20) + 3JSON_OBJECT_SIZE(1) + 6JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + 20JSON_OBJECT_SIZE(4) + 2JSON_OBJECT_SIZE(6);

                                                               ^~~~~~~~~~~~~~~~

sketch_jan22a:128:1: error: 'DynamicJsonDocument' was not declared in this scope

DynamicJsonDocument doc(jsonSize);

^~~~~~~~~~~~~~~~~~~

sketch_jan22a:132:20: error: 'doc' was not declared in this scope

const int name = doc["outputs"][0]["data"]["concepts"][i]["name"];

                ^~~

Multiple libraries were found for "WiFiClient.h"

Used: C:\Users\USER\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.2\libraries\WiFi

Not used: H:\Arduino\libraries\WiFi

exit status 1

'JSON_ARRAY_SIZE' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

pls help

I guess the compiler is correct as usual. It looks like you have some code for use with the ArduinoJson library, yet you don't appear to have an #include directive for that library.

I'm having trouble understanding how you got to this point.

Did you find this code somewhere on the Internet? If so, please post a link to it. That might provide the helpers here with valuable information that will allow them to more effectively provide you with assistance.

i took the code from this website: ESP32-CAM Image Classification using Machine Learning
and i have made some changes to the code:

#include <HTTPClient.h>
#include <WiFi.h>
#include "Arduino.h"
#include "esp_camera.h"
#include <base64.h>
#include <ArduinoJson.h>

// Select camera model
//#define CAMERA_MODEL_WROVER_KIT // Has PSRAM
//#define CAMERA_MODEL_ESP_EYE // Has PSRAM
//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM
//#define CAMERA_MODEL_M5STACK_WIDE  // Has PSRAM
#define CAMERA_MODEL_AI_THINKER // Has PSRAM
//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM
#include "camera_pins.h"

const char* ssid = "Hope Cottage";
const char* password = "pereira07";

void setup() {
  Serial.begin(9600);
  Serial.setDebugOutput(true);
  Serial.println();
 
  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_sscb_sda = SIOD_GPIO_NUM;
  config.pin_sscb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn = PWDN_GPIO_NUM;
  config.pin_reset = RESET_GPIO_NUM;
  config.xclk_freq_hz = 20000000;
  config.pixel_format = PIXFORMAT_JPEG;
  
  // if PSRAM IC present, init with UXGA resolution and higher JPEG quality
  //                      for larger pre-allocated frame buffer.
  if(psramFound()){
    config.frame_size = FRAMESIZE_QVGA;
    config.jpeg_quality = 10;
    config.fb_count = 2;
  } else {
    config.frame_size = FRAMESIZE_QVGA;
    config.jpeg_quality = 12;
    config.fb_count = 1;
  }

#if defined(CAMERA_MODEL_ESP_EYE)
  pinMode(13, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
#endif

  // camera init
  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);
    return;
  }


#if defined(CAMERA_MODEL_M5STACK_WIDE)
  s->set_vflip(s, 1);
  s->set_hmirror(s, 1);
#endif

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  
  classifyImage();
  
}
void classifyImage() {
  
  // Capture picture
   camera_fb_t * fb = NULL;
   fb = esp_camera_fb_get();
   
   if(!fb) {
    Serial.println("Camera capture failed");
    return;
   }

  size_t size = fb->len;
  String buffer = base64::encode((uint8_t *) fb->buf, fb->len);


String payload = "{\"inputs\": [{ \"data\": {\"image\": {\"base64\": \"" + buffer + "\"}}}]}";
buffer = "";

  // Uncomment this if you want to show the payload
  // Serial.println(payload);
  esp_camera_fb_return(fb);
  // Generic model
  String model_id = "aaa03c23b3724a16a56b629203edc62c";

  HTTPClient http;
  http.begin("https://api.clarifai.com/v2/models/" + model_id + "/outputs");
  http.addHeader("Content-Type", "application/json");     
  http.addHeader("Authorization", "Key your_key"); 
  int response_code = http.POST(payload);
  // Parse the json response: Arduino assistant
 // const int jsonSize = JSON_ARRAY_SIZE(1) + JSON_ARRAY_SIZE(20) + 3*JSON_OBJECT_SIZE(1) + 6*JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + 20*JSON_OBJECT_SIZE(4) + 2*JSON_OBJECT_SIZE(6);
 // DynamicJsonDocument doc(jsonSize);


for (int i=0; i < 10; i++) {
  const int name = ["outputs"][0]["data"]["concepts"][i]["name"];
  const float p = ["outputs"][0]["data"]["concepts"][i]["value"];
    
  Serial.println("=====================");
  Serial.print("Name:");
  Serial.println(name);
  Serial.print("Prob:");
  Serial.println(p);
  Serial.println();
 }
}
1 Like

My suggestion is to start by following the tutorial exactly and make sure it works correctly in an unmodified state. Even though it is not what you want for your own project, this will provide you with a known working baseline to build from.

After that, I recommend trying the ArduinoJson library out on its own in a simple sketch that uses the functionality of that library, but without yet adding in the complexity of the whole camera, image classification, etc. After installing that library, you will find some example sketches under the File > Examples > ArduinoJson menu in the Arduino IDE. These will demonstrate how to use the library, and there is additional documentation at the link in my previous reply you can use if there are things in the examples you don't understand. Make sure your simple standalone ArduinoJson sketch is working as expected and that you understand how it works.

Once you have done that, you will be well prepared to integrate the ArduinoJson code into your image classification sketch.

1 Like

ok i will try that thank you

hello I got the solution to my problem thank you very much for helping me out all this time here is my new code:

#include "Arduino.h"
#include "esp_camera.h"
#include <WiFi.h>
#include <base64.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>

// Select camera model
//#define CAMERA_MODEL_WROVER_KIT // Has PSRAM
//#define CAMERA_MODEL_ESP_EYE // Has PSRAM
//#define CAMERA_MODEL_M5STACK_PSRAM // Has PSRAM
//#define CAMERA_MODEL_M5STACK_WIDE // Has PSRAM
#define CAMERA_MODEL_AI_THINKER // Has PSRAM
//#define CAMERA_MODEL_TTGO_T_JOURNAL // No PSRAM

//CAMERA_MODEL_AI_THINKER
#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

const char* ssid = "Hope Cottage";
const char* password = "pereira07";

void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
Serial.println();

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_sscb_sda = SIOD_GPIO_NUM;
config.pin_sscb_scl = SIOC_GPIO_NUM;
config.pin_pwdn = PWDN_GPIO_NUM;
config.pin_reset = RESET_GPIO_NUM;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_JPEG;

// if PSRAM IC present, init with UXGA resolution and higher JPEG quality
// for larger pre-allocated frame buffer.
if(psramFound()){
config.frame_size = FRAMESIZE_QVGA;
config.jpeg_quality = 10;
config.fb_count = 2;
} else {
config.frame_size = FRAMESIZE_QVGA;
config.jpeg_quality = 12;
config.fb_count = 1;
}

#if defined(CAMERA_MODEL_ESP_EYE)
pinMode(13, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
#endif

// camera init
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf("Camera init failed with error 0x%x", err);
return;
}

#if defined(CAMERA_MODEL_M5STACK_WIDE)
s->set_vflip(s, 1);
s->set_hmirror(s, 1);
#endif

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("WiFi connected to: ");
Serial.println(ssid);

classifyImage();

Serial.println("\nSleep….");
esp_deep_sleep_start();

}

void loop(){
}

void classifyImage() {
String response;

// Capture picture
camera_fb_t * fb = NULL;
fb = esp_camera_fb_get();

if(!fb) {
Serial.println("Camera capture failed");
return;
} else {
Serial.println("Camera capture OK");
}

size_t size = fb->len;
String buffer = base64::encode((uint8_t *) fb->buf, fb->len);

String payloadData = "{\"inputs\": [{ \"data\": {\"image\": {\"base64\": \"" + buffer + "\"}}}]}";

buffer = "";
// Uncomment this if you want to show the payload
Serial.println(payloadData);

esp_camera_fb_return(fb);

// Generic model
String model_id = "aaa03c23b3724a16a56b629203edc62c";

HTTPClient http;
http.begin("https://api.clarifai.com/v2/models/" + model_id + "/outputs");
http.addHeader("Content-Type: ", "application/json");
http.addHeader("Authorization: ", "Key c7cde234537462388e256785c071231");
int httpResponseCode = http.POST(payloadData);

if(httpResponseCode>0){
Serial.print(httpResponseCode);
Serial.print(" Returned String: ");
response = http.getString();
Serial.println(response);
} else {
Serial.print("POST Error: ");
Serial.print(httpResponseCode);
return;
}

// Parse the json response: Arduino assistant
const int jsonSize = 2*JSON_ARRAY_SIZE(0) + JSON_ARRAY_SIZE(1) + JSON_ARRAY_SIZE(20) + 4*JSON_OBJECT_SIZE(0) + 7*JSON_OBJECT_SIZE(1) + 5*JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + 21*JSON_OBJECT_SIZE(4) + JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(6) + JSON_OBJECT_SIZE(7) + JSON_OBJECT_SIZE(18)+ 3251;

DynamicJsonDocument doc(jsonSize);
deserializeJson(doc, response);

//StaticJsonDocument (doc);
// Deserialize the JSON document
response = http.getString();
DeserializationError error = deserializeJson(doc, response);
// Test if parsing succeeds.
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.f_str());
return;
}

for (int i=0; i < 10; i++) {
String name = doc["outputs"][0]["data"]["concepts"][i]["name"];
String p = doc["outputs"][0]["data"]["concepts"][i]["value"];
Serial.println("=====================");
Serial.print("Name:");
Serial.println(name);
Serial.print("Prob:");
Serial.println(p);
Serial.println();
 }
}

You are welcome. I'm glad you found the solution. Thanks for taking the time to post an update!

hey, I am trying out your code, but I am unable to understand how to do the classification of images on the Clarifai platform after I upload the code on the ESP 32 cam

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.