module.exports = async function (context, req) { context.log('JavaScript HTTP trigger function processed a request.'); const { createCanvas, loadImage } = require('canvas'); const fs = require('fs'); const rawImage = req.body.image; const w = rawImage.width; const h = rawImage.height; console.log(w, h); const predictions = req.body.predictions.filter(e => e.probability > MIN_CONFIDENCE); console.log(predictions); // Confidence threshold for the analysis const MIN_CONFIDENCE = 0.75; const canvas = createCanvas(w, h); const ctx = canvas.getContext('2d'); ctx.drawImage(img, 0, 0, w, h); ctx.strokeStyle = 'red'; ctx.lineWidth = 2; for (const e of predictions) { const left = e.boundingBox.left * w; const top = e.boundingBox.top * h; const width = e.boundingBox.width * w; const height = e.boundingBox.height * h; ctx.strokeRect(left, top, width, height); }; const buffer = await canvas.toBuffer("image/png"); // send back bounded image context.res = { status: 200, body: buffer }; }