import{a as e}from"./ocr-difficulty-CjQvA3aZ.js";import*as t from"onnxruntime-web/wasm";const n=new URL(`./assets/ocr_router_efficientnet_b0_threshold_0.15.onnx`,import.meta.url).href,r=new URL(`./assets/ort-wasm-simd-threaded.mjs`,import.meta.url).href,i=new URL(`./assets/ort-wasm-simd-threaded.wasm`,import.meta.url).href,a=[1,3,224,224],o=[.485,.456,.406],s=[.229,.224,.225];let c=null;async function l(){return c||(t.env.wasm.wasmPaths={mjs:r,wasm:i},t.env.wasm.numThreads=1,c=t.InferenceSession.create(n,{executionProviders:[`wasm`],graphOptimizationLevel:`all`}).catch(e=>{throw c=null,e})),c}async function u(t){let n=await l(),r=await f(t);try{let t=m(r),i=n.inputNames[0]??`x`,a=n.outputNames[0]??`linear`,o=performance.now(),s=await n.run({[i]:t}),c=performance.now()-o,l=s[a];if(!l)throw Error(`Model output "${a}" was not returned.`);let u=Array.from(l.data).map(d);return{scores:u,prediction:e(u),inferenceMs:c}}finally{r.dispose()}}function d(e){return 1/(1+Math.exp(-e))}async function f(e){if(typeof createImageBitmap==`function`){let t=await createImageBitmap(e,{imageOrientation:`from-image`});return{source:t,width:t.width,height:t.height,dispose:()=>t.close()}}let t=URL.createObjectURL(e);try{let e=await p(t);return{source:e,width:e.naturalWidth,height:e.naturalHeight,dispose:()=>URL.revokeObjectURL(t)}}catch(e){throw URL.revokeObjectURL(t),e}}function p(e){return new Promise((t,n)=>{let r=new Image;r.decoding=`async`,r.onload=()=>t(r),r.onerror=()=>n(Error(`Unable to decode the canvas image.`)),r.src=e})}function m(e){let[,n,r,i]=a,c=256/Math.min(e.width,e.height),l=Math.round(e.width*c),u=Math.round(e.height*c),d=h(l,u);g(d).drawImage(e.source,0,0,l,u);let f=Math.max(0,Math.floor((l-i)/2)),p=Math.max(0,Math.floor((u-r)/2)),m=g(h(i,r));m.drawImage(d,f,p,i,r,0,0,i,r);let _=m.getImageData(0,0,i,r).data,v=i*r,y=new Float32Array(n*v);for(let e=0;e<v;e+=1){let t=e*4,n=(_[t]??0)/255,r=(_[t+1]??0)/255,i=(_[t+2]??0)/255;y[e]=(n-o[0])/s[0],y[v+e]=(r-o[1])/s[1],y[v*2+e]=(i-o[2])/s[2]}return new t.Tensor(`float32`,y,Array.from(a))}function h(e,t){let n=document.createElement(`canvas`);return n.width=e,n.height=t,n}function g(e){let t=e.getContext(`2d`,{willReadFrequently:!0});if(!t)throw Error(`Could not acquire a 2D canvas context for image preprocessing.`);return t}export{l as loadOcrClassifier,u as runOcrClassifier};
//# sourceMappingURL=onnx-classifier-mb_6hJ1l.js.map