yoursunny / esp32cam

OV2640 camera on ESP32-CAM, Arduino library
https://esp32cam.yoursunny.dev
ISC License
499 stars 174 forks source link

Compile error #56

Closed anandhusiva97 closed 3 months ago

anandhusiva97 commented 5 months ago

Compile Error

D:\NIMISHA\driver drowsiness (2)\hardware\imgByFrame\imgByFrame.ino:18:21: error: 'esp32cam' has not been declared
 static auto loRes = esp32cam::Resolution::find(320, 240);
                     ^~~~~~~~
D:\NIMISHA\driver drowsiness (2)\hardware\imgByFrame\imgByFrame.ino:19:22: error: 'esp32cam' has not been declared
 static auto midRes = esp32cam::Resolution::find(350, 530);
                      ^~~~~~~~
D:\NIMISHA\driver drowsiness (2)\hardware\imgByFrame\imgByFrame.ino:20:21: error: 'esp32cam' has not been declared
 static auto hiRes = esp32cam::Resolution::find(800, 600);
                     ^~~~~~~~
D:\NIMISHA\driver drowsiness (2)\hardware\imgByFrame\imgByFrame.ino: In function 'void serveJpg()':
D:\NIMISHA\driver drowsiness (2)\hardware\imgByFrame\imgByFrame.ino:24:14: error: 'esp32cam' has not been declared
 auto frame = esp32cam::capture();
              ^~~~~~~~
D:\NIMISHA\driver drowsiness (2)\hardware\imgByFrame\imgByFrame.ino: In function 'void handleJpgLo()':
D:\NIMISHA\driver drowsiness (2)\hardware\imgByFrame\imgByFrame.ino:45:6: error: 'esp32cam' has not been declared
 if (!esp32cam::Camera.changeResolution(loRes)) {
      ^~~~~~~~
D:\NIMISHA\driver drowsiness (2)\hardware\imgByFrame\imgByFrame.ino: In function 'void handleJpgHi()':
D:\NIMISHA\driver drowsiness (2)\hardware\imgByFrame\imgByFrame.ino:52:5: error: 'esp32cam' has not been declared
 if(!esp32cam::Camera.changeResolution(hiRes)) {
     ^~~~~~~~
D:\NIMISHA\driver drowsiness (2)\hardware\imgByFrame\imgByFrame.ino: In function 'void handleJpgMid()':
D:\NIMISHA\driver drowsiness (2)\hardware\imgByFrame\imgByFrame.ino:58:6: error: 'esp32cam' has not been declared
 if (!esp32cam::Camera.changeResolution(midRes)) {
      ^~~~~~~~
D:\NIMISHA\driver drowsiness (2)\hardware\imgByFrame\imgByFrame.ino: In function 'void setup()':
D:\NIMISHA\driver drowsiness (2)\hardware\imgByFrame\imgByFrame.ino:68:17: error: 'esp32cam' is not a namespace-name
 using namespace esp32cam;
                 ^~~~~~~~
D:\NIMISHA\driver drowsiness (2)\hardware\imgByFrame\imgByFrame.ino:68:25: error: expected namespace-name before ';' token
 using namespace esp32cam;
                         ^
D:\NIMISHA\driver drowsiness (2)\hardware\imgByFrame\imgByFrame.ino:69:1: error: 'Config' was not declared in this scope
 Config cfg;
 ^~~~~~
D:\NIMISHA\driver drowsiness (2)\hardware\imgByFrame\imgByFrame.ino:69:1: note: suggested alternative: 'long'
 Config cfg;
 ^~~~~~
 long
D:\NIMISHA\driver drowsiness (2)\hardware\imgByFrame\imgByFrame.ino:70:1: error: 'cfg' was not declared in this scope
 cfg.setPins(pins::AiThinker);
 ^~~
D:\NIMISHA\driver drowsiness (2)\hardware\imgByFrame\imgByFrame.ino:70:13: error: 'pins' has not been declared
 cfg.setPins(pins::AiThinker);
             ^~~~
D:\NIMISHA\driver drowsiness (2)\hardware\imgByFrame\imgByFrame.ino:75:11: error: 'Camera' was not declared in this scope
 bool ok = Camera.begin(cfg);
           ^~~~~~
D:\NIMISHA\driver drowsiness (2)\hardware\imgByFrame\imgByFrame.ino:75:11: note: suggested alternative: 'gamma'
 bool ok = Camera.begin(cfg);
           ^~~~~~
           gamma

exit status 1

Compilation error: 'esp32cam' has not been declared

Programme

#include <WebServer.h>
#include <WiFi.h>
#include <esp_camera.h>
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"

const char* WIFI_SSID = "SIV";
const char* WIFI_PASS = "suash24";

WebServer server(80);

static auto loRes = esp32cam::Resolution::find(320, 240);
static auto midRes = esp32cam::Resolution::find(350, 530);
static auto hiRes = esp32cam::Resolution::find(800, 600);

void serveJpg()
{
auto frame = esp32cam::capture();
if (frame == nullptr) {
Serial.println("CAPTURE FAIL");
server.send(503, "", "");
return;
}
Serial.printf("CAPTURE OK %dx%d %db\n", frame->getWidth(), frame->getHeight(),
static_cast<int>(frame->size()));
server.setContentLength(frame->size());

server.sendHeader("Access-Control-Allow-Origin", "*");
server.sendHeader("Access-Control-Max-Age", "600");
server.sendHeader("Access-Control-Allow-Methods", "PUT,POST,GET,OPTIONS");
server.sendHeader("Access-Control-Allow-Headers", "*");

server.send(200, "image/jpeg");
WiFiClient client = server.client();
frame->writeTo(client);
}
void handleJpgLo()
{
if (!esp32cam::Camera.changeResolution(loRes)) {
Serial.println("SET-LO-RES FAIL");
}
serveJpg();
}
void handleJpgHi()
{
if(!esp32cam::Camera.changeResolution(hiRes)) {
Serial.println("SET-HI-RES FAIL");
}
serveJpg();
}
void handleJpgMid(){
if (!esp32cam::Camera.changeResolution(midRes)) {
Serial.println("SET-MID-RES FAIL");
}
serveJpg();
}
void setup(){
  WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
Serial.begin(115200);
Serial.println();
{
using namespace esp32cam;
Config cfg;
cfg.setPins(pins::AiThinker);
cfg.setResolution(hiRes);
cfg.setBufferCount(2);
cfg.setJpeg(80);

bool ok = Camera.begin(cfg);
Serial.println(ok ? "CAMERA OK" : "CAMERA FAIL");}
WiFi.persistent(false);
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASS);

while(WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(500);
}

Serial.print("http://");
Serial.println(WiFi.localIP());

Serial.println("  /stream");
//Serial.println("  /streammid");
//Serial.println("  /streamhigh");
server.enableCORS();
server.on("/stream", handleJpgHi);
//server.on("/streamhigh", handleJpgLo);
//server.on("/streamhigh", handleJpgMid);
server.begin();
}

void loop()
{
server.handleClient();
}
yoursunny commented 5 months ago

Missing #include <esp32cam.h>