{
if (photo instanceof HTMLCanvasElement){
console.log(photo)
let image = photo.toDataURL('image/jpeg')
let img= new Image();
img.src = image;
return new Promise( (resolve,reject) => {
img.onload = async function() {
let ogWidth = img.width;
let ogHeight = img.height;
let ctx = photo.getContext('2d');
console.log(`photo width: ${photo.width} height: ${photo.height}`)
console.log(`img width: ${img.width} height: ${img.height}`)
let output= await detector(image, { threshold: 0.9 });
output.forEach( o => {
console.log(o)
let scaleX = 0.5
let scaleY = 0.5
let xmin = Math.floor(o.box.xmin * scaleX);
let xmax = Math.floor(o.box.xmax * scaleX);
let ymin = Math.floor(o.box.ymin * scaleY);
let ymax = Math.floor(o.box.ymax * scaleY);
let bwid = xmax - xmin;
let bhei = ymax - ymin;
ctx.lineWidth = 2;
ctx.strokeStyle = 'red';
ctx.strokeRect(xmin, ymin, bwid, bhei);
console.log(`iw: ${img.width} ih: ${img.height}\nscaleX: ${scaleX} scaleY: ${scaleY}\nxmin: ${xmin} xmax: ${xmax} ymin: ${ymin} ymax:${ymax}\nwid: ${bwid} heoght: ${bhei}`)
})
resolve(output)
}
})
} else {
return "... waiting for photo ..."
}
}