Page 1 of 1

ESP Eye to AWS Rekognition

Posted: Tue Jul 09, 2019 8:01 am
by mctosima
Hi guys, I'm a new comer here. Could u give me some reference to learning ESP32 (I currently using ESP-EYE) and its connection to AWS Rekognition for developing computer vision. Thank you before

Re: ESP Eye to AWS Rekognition

Posted: Sun Aug 11, 2019 1:13 am
by chegewara
Soem time ago ive been doing AWS rekognize with esp32. From esp32 ive been sending http request to api gateway which has been using aws lambda like this and send back response:

Code: Select all

const AWS = require('aws-sdk');
var rekognition = new AWS.Rekognition({apiVersion: '2016-06-27'});
var s3 = new AWS.S3();
var S3params;
var filePath;
var recoType = "text";

exports.handler = (event, context, callback) => {
    console.log(event.queryStringParameters);
    recoType = event.queryStringParameters.reco;
     let encodedImage = event.body;//JSON.parse(event.body).image;
     let decodedImage = Buffer.from(encodedImage, 'base64');
     filePath = "images/image.jpg";
     S3params = {
       "Body": decodedImage,
       "Bucket": "bucket_name",
       "Key": filePath  
    };
    s3.upload(S3params, function(err, data){
        if(err) {
            console.log("problem with saving to S3");
            callback(err, null);
        }
        else {
    
            var recoParams = {
              Image: { /* required */
                Bytes: decodedImage /* Strings will be Base-64 encoded on your behalf */,
              }
            };
            console.log(recoType);
            if(recoType == "text") {
                rekognition.detectText(recoParams, function(err, data) {
                    if (err) console.log(err, err.stack); // an error occurred
                    else     console.log(data);           // successful response
                    
                    if(err) {
                        callback(err, null);
                    } 
                    else {
                        let response = {
                            "statusCode": 200,
                            // "headers": {
                            // },
                            "body": JSON.stringify(data),
                            "isBase64Encoded": false
                        };
                        callback(null, response);
                    }
                });
            }
            else {
                rekognition.detectLabels(recoParams, function(err, data) {
                    if (err) console.log(err, err.stack); // an error occurred
                    else     console.log(data);           // successful response
                    
                    if(err) {
                        callback(err, null);
                    } 
                    else {
                        let response = {
                            "statusCode": 200,
                            // "headers": {
                            // },
                            "body": JSON.stringify(data),
                            "isBase64Encoded": false
                        };
                        callback(null, response);
                    }
                });
            }
        }
    });
};