UNPKG

@biopassid/face-sdk

Version:

<h1 align="center"> <br> <a href="http://www.biopassid.com"><img src="https://uploads-ssl.webflow.com/5ec3d6d0293839cf102a656a/63a0d4cec83bbddea006d27a_biopassamarelo.svg" alt="BioPass ID" width="200"></a> <br>

2 lines (1 loc) 1.14 kB
import{detectAllFaces as y,loadTinyFaceDetectorModel as g,TinyFaceDetectorOptions as m,env as x}from"face-api.js";async function v(n="/models"){await g(n)}function D(){let n=typeof process<"u"&&process.versions&&process.versions.electron,s=typeof navigator=="object"&&navigator.userAgent.includes("Electron");return n||s}D()&&(console.log("Running in Electron"),x.monkeyPatch({createCanvasElement:()=>document.createElement("canvas"),createImageElement:()=>document.createElement("img")}));async function F(n,s,c,l){let e={detections:0,position:{x:0,y:0,z:0},dimensions:{width:0,height:0},rect:{x:0,y:0,width:0,height:0}},o=await y(n,new m({scoreThreshold:s}));if(e.detections=o.length,o.length>0){let t=o[0].relativeBox,i={x:t.x+t.width/2,y:t.y+t.height/2},r=o[0].imageWidth<o[0].imageHeight,d=r?.4:.45,a=r?.6:.55,f=.5,h=.6,p=c!=null?c:1,u=l!=null?l:.4;e.rect=t,t.height>p?e.dimensions.height=-1:t.height<u?e.dimensions.height=1:e.dimensions.height=0,i.x<d?e.position.x=1:i.x>a?e.position.x=-1:e.position.x=0,i.y<f?e.position.y=1:i.y>h?e.position.y=-1:e.position.y=0}return e}export{F as faceDetectionAdapter,v as loadFaceDetectorModels};