Hi,
I tried to run a small script using OpenCV.JS work on Observablehq. The details of the script are mentioned in the below link: OpenCV: Image Thresholding
I havenāt seen any successful attempt at loading opencv in Observable. The most important blocker is that you need to compile it to wasm, then load the wasm file through observable. There is an example with a pre-compiled wasm in codepen https://codepen.io/huningxin/pen/gxRKdo ; but Iām at a loss when it comes to porting it to obs.
d3-require registers window.define, which causes the opencv package to register itself via define instead of in addition to registering a global cv object.
The cv object is a thenable, meaning it has a then function that again returns the object. When one attempts to load opencv via d3-require (i.e., Observableās require()), the promise resolution gets stuck in an infinite loop.
I fear thereās no good solution here. Presumably one would have to replace and wrap require's define(), so that it can still work for other libraries, but wonāt end up in an infinite cycle when returning cv.
Iām aware, but I donāt know of any other (semi-)official sources. The source is already minified, and afaik youād have to hand-pick and create your own build if you want to push the size down further.
The unofficial opencv.js package hasnāt been updated in over four years (stuck at 1.2.1), which is likely the only reason for its smaller size.
Super cool, @mootari! Might I suggest replacing the Lena image with something else since its usage can be considered sexist and the model herself has said itās time to ditch it as a sample image? (Hereās a nifty interactive about it.)
Good point, thanks! I had used the image despite knowing its history to stick closer to the original example, a rather weak argument in hindsight. Iāve now replaced the image.