ppu-ocv
Version:
A type-safe, modular, chainable image processing library built on top of OpenCV.js with a fluent API leveraging pipeline processing.
1 lines • 957 B
JavaScript
export let webPlatform={createCanvas(width,height){if(typeof OffscreenCanvas!=="undefined"){return new OffscreenCanvas(width,height)}if(typeof document!=="undefined"){let c=document.createElement("canvas");c.width=width;c.height=height;return c}throw new Error("No canvas implementation available in this environment.")},async loadImage(source){let blob;if(source instanceof ArrayBuffer){blob=new Blob([source])}else if(typeof source==="string"){let res=await fetch(source);blob=await res.blob()}else{throw new Error("loadImage: unsupported source type")}let bitmap=await createImageBitmap(blob);let canvas=webPlatform.createCanvas(bitmap.width,bitmap.height);let ctx=canvas.getContext("2d");ctx.drawImage(bitmap,0,0);bitmap.close();return canvas},isCanvas(value){if(typeof HTMLCanvasElement!=="undefined"&&value instanceof HTMLCanvasElement){return true}if(typeof OffscreenCanvas!=="undefined"&&value instanceof OffscreenCanvas){return true}return false}};