Porównaj commity

...

7 Commity

Autor SHA1 Wiadomość Data
Alan bb88928f97
Update ESP32cam-demo.ino 2023-10-16 14:00:01 +01:00
Alan 5f90f56f04
Update ESP32cam-demo.ino 2023-10-16 13:35:35 +01:00
Alan 557340a25c
Update README.md 2023-10-16 10:01:15 +01:00
Alan cca1a161cc
Update ESP32cam-demo.ino 2023-10-16 10:00:34 +01:00
Alan 16128a28c9
Add files via upload 2023-10-16 09:59:53 +01:00
Alan b73fa63c0c
Update ESP32cam-demo.ino 2023-10-16 08:47:19 +01:00
Alan e275ba3ce9
Update ESP32cam-demo.ino 2023-10-16 08:06:11 +01:00
3 zmienionych plików z 64 dodań i 55 usunięć

Wyświetl plik

@ -11,6 +11,7 @@
* flash led is still available for use (pin 4) and does not flash when accessing sd card
* Stores image in Spiffs if no sd card present
* PWM control of the illumination/flash LED
* Shows how to read the raw image data (greyscale and RGB)
*
* GPIO:
* You can use io pins 13 and 12 for input or output (but 12 must not be high at boot)
@ -58,29 +59,29 @@
#include <Arduino.h>
// forward declarations
bool initialiseCamera(bool);
bool cameraImageSettings();
void changeResolution(framesize_t);
String localTime();
void flashLED(int);
byte storeImage();
void handleRoot();
void handlePhoto();
bool handleImg();
void handleNotFound();
void readRGBImage();
bool getNTPtime(int);
bool handleJPG();
void handleJpeg();
void handleStream();
int requestWebPage(String*, String*, int);
void handleTest();
void brightLed(byte);
void setupFlashPWM();
void handleData();
void readGreyscaleImage();
void resize_esp32cam_image_buffer(uint8_t*, int, int, uint8_t*, int, int);
// forward declarations (this is a list of all procedures in this sketch which Platform IO requires)
bool initialiseCamera(bool); // this sets up and enables the camera (if bool=1 standard settings are applied but 0 allows you to apply custom settings)
bool cameraImageSettings(); // this applies the image settings to the camera (brightness etc.)
void changeResolution(framesize_t); // this changes the capture frame size
String localTime(); // returns the current time as a String
void flashLED(int); // flashes the onboard indicator led
byte storeImage(); // stores an image in Spiffs or SD card
void handleRoot(); // the root web page
void handlePhoto(); // web page to capture an image from camera and save to spiffs or sd card
bool handleImg(); // Display a previously stored image
void handleNotFound(); // if invalid web page is requested
void readRGBImage(); // demo capturing an image and reading its raw RGB data
bool getNTPtime(int); // handle the NTP real time clock
bool handleJPG(); // display a raw jpg image
void handleJpeg(); // display a raw jpg image which periodically refreshes
void handleStream(); // stream live video (note: this can get the camera very hot)
int requestWebPage(String*, String*, int); // procedure allowing the sketch to read a web page its self
void handleTest(); // test procedure for experimenting with bits of code etc.
void brightLed(byte); // turn the onboard flash LED on/off with varying brightness
void setupFlashPWM(); // set up the PWM for the above flash
void handleData(); // the root web page requests this periodically via Javascript in order to display updating information
void readGreyscaleImage(); // demo capturing a greyscale image and reading its raw RGB data
void resize_esp32cam_image_buffer(uint8_t*, int, int, uint8_t*, int, int); // this resizes a captured greyscale image (used by above)
// ---------------------------------------------------------------
@ -88,7 +89,7 @@
// ---------------------------------------------------------------
char* stitle = "ESP32Cam-demo"; // title of this sketch
char* sversion = "15oct23"; // Sketch version
char* sversion = "16oct23"; // Sketch version
bool sendRGBfile = 0; // if set '/rgb' will just return raw rgb data which can be saved as a file rather than display a HTML pag
@ -100,8 +101,9 @@
#define useMCP23017 0 // set if MCP23017 IO expander chip is being used (on pins 12 and 13)
// Camera related
bool flashRequired = 1; // If flash to be used when capturing image (1 = yes)
framesize_t FRAME_SIZE_IMAGE = FRAMESIZE_SVGA; // Image resolution:
bool flashRequired = 0; // If flash to be used when capturing image (1 = yes)
const framesize_t cyclingRes[] = { FRAMESIZE_SVGA, FRAMESIZE_XGA, FRAMESIZE_SXGA, FRAMESIZE_QVGA, FRAMESIZE_VGA }; // resolutions to use
// Image resolutions available:
// default = "const framesize_t FRAME_SIZE_IMAGE = FRAMESIZE_VGA"
// 160x120 (QQVGA), 128x160 (QQVGA2), 176x144 (QCIF), 240x176 (HQVGA),
// 320x240 (QVGA), 400x296 (CIF), 640x480 (VGA, default), 800x600 (SVGA),
@ -155,6 +157,7 @@
//#include "esp_camera.h" // https://github.com/espressif/esp32-camera
// #include "camera_pins.h"
framesize_t FRAME_SIZE_IMAGE = cyclingRes[0];
#include <WString.h> // this is required for base64.h otherwise get errors with esp32 core 1.0.6 - jan23
#include <base64.h> // for encoding buffer to display image on page
#include <WiFi.h>
@ -663,21 +666,23 @@ void resetCamera(bool type = 0) {
// ----------------------------------------------------------------
// -change image resolution
// ----------------------------------------------------------------
// if required resolution not supplied it cycles through several
// cycles through the available resolutions (set in cyclingRes[])
//Note: there seems to be an issue with 1024x768 with later releases of esp software?
void changeResolution(framesize_t tRes = FRAMESIZE_96X96) {
// Resolutions: 160x120 (QQVGA), 128x160 (QQVGA2), 176x144 (QCIF), 240x176 (HQVGA),
// 320x240 (QVGA), 400x296 (CIF), 640x480 (VGA, default), 800x600 (SVGA),
// 1024x768 (XGA), 1280x1024 (SXGA), 1600x1200 (UXGA)
void changeResolution() {
// const framesize_t cyclingRes[] = { FRAMESIZE_QVGA, FRAMESIZE_VGA, FRAMESIZE_SVGA, FRAMESIZE_XGA, FRAMESIZE_SXGA }; // resolutions to cycle through
const int noAvail = sizeof(cyclingRes) / sizeof(cyclingRes[0]);
static int currentRes = 0;
esp_camera_deinit(); // disable camera
delay(50);
if (tRes == FRAMESIZE_96X96) { // taken as none supplied so cycle through several
if (FRAME_SIZE_IMAGE == FRAMESIZE_QVGA) tRes = FRAMESIZE_VGA;
else if (FRAME_SIZE_IMAGE == FRAMESIZE_VGA) tRes = FRAMESIZE_SVGA;
else if (FRAME_SIZE_IMAGE == FRAMESIZE_SVGA) tRes = FRAMESIZE_SXGA;
else tRes = FRAMESIZE_QVGA;
}
FRAME_SIZE_IMAGE = tRes;
delay(200);
currentRes++; // change to next resolution available
if (currentRes >= noAvail) currentRes=0; // reset loop
FRAME_SIZE_IMAGE = cyclingRes[currentRes];
initialiseCamera(1);
if (serialDebug) Serial.println("Camera resolution changed to " + String(tRes));
if (serialDebug) Serial.println("Camera resolution changed to " + String(cyclingRes[currentRes]));
ImageResDetails = "Unknown"; // set next time image captured
}
@ -942,11 +947,14 @@ void handleRoot() {
// links to the other pages available
client.write("<br><br>LINKS: \n");
client.write("<a href='/photo'>Capture an image</a> - \n");
client.write("<a href='/photo'>Store image</a> - \n");
client.write("<a href='/img'>View stored image</a> - \n");
client.write("<a href='/rgb'>Capture frame and display as RGB data</a> - \n");
client.write("<a href='/greydata'>Capture Greyscale frame as data</a> - \n");
client.write("<a href='/rgb'>RGB frame as data</a> - \n");
client.write("<a href='/greydata'>Greyscale frame as data</a> \n");
client.write("<br>");
client.write("<a href='/stream'>Live stream</a> - \n");
client.write("<a href='/jpg'>JPG</a> - \n");
client.write("<a href='/jpeg'>Updating JPG</a> - \n");
client.write("<a href='/test'>Test procedure</a>\n");
// addnl info if sd card present
@ -1538,6 +1546,7 @@ void handleJpeg() {
// ----------------------------------------------------------------
// resize greyscale image
// ----------------------------------------------------------------
// Thanks to Bard A.I. for writing this for me ;-)
// src_buf: The source image buffer.
// src_width: The width of the source image buffer.
// src_height: The height of the source image buffer.
@ -1575,14 +1584,14 @@ void readGreyscaleImage() {
WiFiClient client = server.client(); // open link with client
// html header
// html header
sendHeader(client, "Access greyscale image data");
// change camera to greyscale mode (as by default it is in JPG colour mode)
// change camera to greyscale mode (by default it is in JPG colour mode)
esp_camera_deinit(); // disable camera
delay(50);
config.pixel_format = PIXFORMAT_GRAYSCALE; // change camera setting to greyscale (default is JPG)
initialiseCamera(0); // restart the camera without resetting the camera settings
initialiseCamera(0); // restart the camera (0 = without resetting all the other camera settings)
// capture the image and use flash if required
int currentBrightness = brightLEDbrightness;
@ -1606,24 +1615,23 @@ void readGreyscaleImage() {
avrg += fb->buf[(y * fb->width) + x];
}
}
client.println("<br>Greyscale Image: The average brightness of the " + String(dataSize) + " pixels is " + String(avrg / dataSize));
client.println("Greyscale Image: The average brightness of the " + String(dataSize) + " pixels is " + String(avrg / dataSize));
client.write("<br><br><a href='/'>Return</a>\n"); // link back
// resize image
int newWidth = 64; int newHeight = 32;
// resize the image
int newWidth = 100; int newHeight = 36;
byte newBuf[newWidth * newHeight];
resize_esp32cam_image_buffer(fb->buf, fb->width, fb->height, newBuf, newWidth, newHeight);
// display image
char asciiArt[] = {'@','#','+','!',':','.',' '}; // dark to light characters
const int noAsciiChars = 7; // number of characters
client.write("<br><pre>");
// display image as asciiArt
char asciiArt[] = {' ','.',',',':',';','+','*','?','%','S','#','@'}; // characters to use (light to dark)
int noAsciiChars = sizeof(asciiArt) / sizeof(asciiArt[0]); // number of characters available
client.write("<br><pre>"); // 'pre' stops variable character spacing
for (int y=0; y < newHeight; y++) {
client.write("</pre><pre>");
client.write("</pre><pre style='line-height: 0.2;'>"); // 'line-heigh' adjusts spacing between lines
for (int x=0; x < newWidth; x++) {
int tpos = map(newBuf[y*newWidth+x],0,255,0,noAsciiChars-1);
client.write(asciiArt[tpos]);
int tpos = map(newBuf[y*newWidth+x],0,255,0,noAsciiChars-1); // convert pixel brightness to ascii character
client.write(asciiArt[noAsciiChars - tpos]);
}
}
client.write("<br></pre>");
@ -1641,7 +1649,7 @@ void readGreyscaleImage() {
// change camera back to JPG mode
esp_camera_deinit();
delay(50);
initialiseCamera(1); // reset settings
initialiseCamera(1); // reset settings (1=apply the cameras settings which includes JPG mode)
}

Wyświetl plik

@ -10,6 +10,7 @@ Note: There is a version of this sketch with OTA updates included here: https://
<table><tr>
<td><img src="/images/root.png" /></td>
<td><img src="/images/rgb.png" /></td>
<td><img src="/images/grey.png" /></td>
</tr></table>
This can be used as a starting point sketch for projects using the esp32cam development board, it has the following features.

BIN
images/grey.png 100644

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 131 KiB