habbes / xaval

Interactive web-based playground for computer vision exploration and experimentation
https://xaval.habbes.xyz
5 stars 0 forks source link

Properly detect when OpenCV is ready #45

Open habbes opened 6 years ago

habbes commented 6 years ago

At the moment, the app detects when OpenCV is ready by passing a callback to the onload handler of the async script tag used to load opencv.js.

However, even though OpenCV is loaded, not all its APIs are ready for use, for example, cv.Mat may not be ready when the callback is called.

According to this post cv['onRuntimeInitialized'] can be used to assign a callback which will be fired when the APIs area ready for use:

cv.onRuntimeInitialized = () => {
   // cv is ready
};

No issue has occurred yet because of this, since by the time the editor is loaded and code executed, OpenCV will have had enough time to load, but I foresee it causing issues if we have code that is executed when the app is being setup.