From 1d22dbfa3a10e5095d3d9068c6243a0c973ad381 Mon Sep 17 00:00:00 2001 From: Bharath Sudharsan Date: Sat, 23 Jul 2022 04:25:28 +0100 Subject: [PATCH] image collection code --- README.md | 9 ++++--- [ino]-CameraWebServer.ino | 53 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 [ino]-CameraWebServer.ino diff --git a/README.md b/README.md index f55399d..7ed9cab 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,8 @@ Following can be observed from the video: - **Memory** Consumes only 1 kB of RAM - difference between the RAM calculated by Arduino IDE before and after adding the TinyML-CAM image recognition system. ### Code - -- [[ipynb]-TinyML-CAM-full-code-with-markdown.ipynb](https://github.com/bharathsudharsan/TinyML-CAM/blob/main/%5Bipynb%5D-TinyML-CAM-full-code-with-markdown.ipynb) -- [[h]-HOG-plus-RandomForest-classifier.h](https://github.com/bharathsudharsan/TinyML-CAM/blob/main/%5Bh%5D-HOG-plus-RandomForest-classifier.h) -- [[ino]-arduino-ESP32-code.ino](https://github.com/bharathsudharsan/TinyML-CAM/blob/main/%5Bino%5D-arduino-ESP32-code.ino) - upload to +- [[ino]-CameraWebServer.ino]() +- [[ipynb]-TinyML-CAM-full-code-with-markdown.ipynb](https://github.com/bharathsudharsan/TinyML-CAM/blob/main/%5Bipynb%5D-TinyML-CAM-full-code-with-markdown.ipynb) - +- [[h]-HogClassifier.h](https://github.com/bharathsudharsan/TinyML-CAM/blob/main/%5Bh%5D-HogClassifier.h) - Contains the RandomForestClassifier trained using the collected image data. +- [[h]-HogPipeline.h](https://github.com/bharathsudharsan/TinyML-CAM/blob/main/%5Bh%5D-HogPipeline.h) - Contains the HOG features extrator for image frames. +- [[ino]-arduino-ESP32-code.ino](https://github.com/bharathsudharsan/TinyML-CAM/blob/main/%5Bino%5D-arduino-ESP32-code.ino) - Upload to ESP32 along with the above two .h files. After upload, put your objects in front of the camera to see predicted labels. diff --git a/[ino]-CameraWebServer.ino b/[ino]-CameraWebServer.ino new file mode 100644 index 0000000..5ac27f5 --- /dev/null +++ b/[ino]-CameraWebServer.ino @@ -0,0 +1,53 @@ +#include "eloquent.h" +#include "eloquent/print.h" +#include "eloquent/tinyml/voting/quorum.h" + +// replace 'm5wide' with your own model +// possible values are 'aithinker', 'eye', 'm5stack', 'm5wide', 'wrover' +#include "eloquent/vision/camera/m5wide.h" + +#include "HogPipeline.h" +#include "HogClassifier.h" + +Eloquent::TinyML::Voting::Quorum<7> quorum; + + +void setup() { + Serial.begin(115200); + delay(3000); + Serial.println("Begin"); + + camera.qqvga(); + camera.grayscale(); + + while (!camera.begin()) + Serial.println("Cannot init camera"); +} + +void loop() { + if (!camera.capture()) { + Serial.println(camera.getErrorMessage()); + delay(1000); + return; + } + + // apply HOG pipeline to camera frame + hog.transform(camera.buffer); + + // get a stable prediction + // this is optional, but will improve the stability of predictions + uint8_t prediction = classifier.predict(hog.features); + int8_t stablePrediction = quorum.vote(prediction); + + if (quorum.isStable()) { + eloquent::print::printf( + Serial, + "Stable prediction: %s \t(DSP: %d ms, Classifier: %d us)\n", + classifier.getLabelOf(stablePrediction), + hog.latencyInMillis(), + classifier.latencyInMicros() + ); + } + + camera.free(); +} \ No newline at end of file