Advertisement
rhandycan1

ESP32CAM_EDGE IMPULSE

Mar 22nd, 2025
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | Source Code | 0 0
  1. // include your library created here
  2. #include <Wire.h>
  3. #include <LiquidCrystal_I2C.h>
  4. #include <eloquent_esp32cam.h>
  5. #include <eloquent_esp32cam/edgeimpulse/fomo.h>
  6.  
  7.  
  8. using eloq::camera;
  9. using eloq::ei::fomo;
  10.  
  11. // Initialize the LCD (I2C address 0x27, 16 columns, 2 rows)
  12. LiquidCrystal_I2C lcd(0x27, 16, 2);
  13.  
  14. void setup() {
  15.     delay(3000);
  16.     Serial.begin(115200);
  17.     Serial.println("__EDGE IMPULSE FOMO (NO-PSRAM)__");
  18.    
  19.     // Initialize I2C LCD
  20.     Wire.begin(14, 15);  // SDA = GPIO 14, SCL = GPIO 15
  21.     lcd.init();
  22.     lcd.backlight();
  23.     lcd.setCursor(0, 0);
  24.     lcd.print("Initializing...");
  25.  
  26.     // Camera settings
  27.     camera.pinout.aithinker(); //replace aithinker with your model of your ESP32cam
  28.     camera.brownout.disable();
  29.     camera.resolution.yolo();
  30.     camera.pixformat.rgb565();
  31.  
  32.     // Initialize camera
  33.     while (!camera.begin().isOk()) {
  34.         Serial.println(camera.exception.toString());
  35.         lcd.setCursor(0, 1);
  36.         lcd.print("Cam Error!");
  37.     }
  38.  
  39.     Serial.println("Camera OK");
  40.     lcd.clear();
  41.     lcd.setCursor(0, 0);
  42.     lcd.print("Ready!");
  43. }
  44.  
  45. void loop() {
  46.     // Capture picture
  47.     if (!camera.capture().isOk()) {
  48.         Serial.println(camera.exception.toString());
  49.         lcd.setCursor(0, 1);
  50.         lcd.print("Capture Failed");
  51.         return;
  52.     }
  53.  
  54.     // Run FOMO inference
  55.     if (!fomo.run().isOk()) {
  56.         Serial.println(fomo.exception.toString());
  57.         lcd.setCursor(0, 1);
  58.         lcd.print("Inference Error");
  59.         return;
  60.     }
  61.  
  62.     // Display number of detected objects
  63.     Serial.printf("Found %d object(s) in %dms\n", fomo.count(), fomo.benchmark.millis());
  64.     lcd.clear();
  65.     lcd.setCursor(0, 0);
  66.     lcd.printf("Objects: %d", fomo.count());
  67.  
  68.     // If no objects detected, return
  69.     if (!fomo.foundAnyObject()) {
  70.         lcd.setCursor(0, 1);
  71.         lcd.print("No object found");
  72.         return;
  73.     }
  74.  
  75.     // Display detected object
  76.     lcd.setCursor(0, 1);
  77.     lcd.printf("%s", fomo.first.label);
  78.     Serial.printf("Found %s at (x = %d, y = %d) (size %d x %d). Proba: %.2f\n",
  79.                   fomo.first.label, fomo.first.x, fomo.first.y,
  80.                   fomo.first.width, fomo.first.height, fomo.first.proba);
  81. }
Tags: Esp32cam
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement