-
-
Notifications
You must be signed in to change notification settings - Fork 55.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JS: npm package #15315
Comments
|
Is there a way to split the open.js file into modules so one can take advantage of tree-shaking? |
|
I have feedback I would like to work on. Initial slowdown because base 64 decoding of a string, not because of size.
WebAssembly output is polluted and there's no way to get the "clean" .wasm /asm.js output files
helpers.js and cv.imread
wasm build
Of course the final idea is to contribute all of this to this project but right now I prefer to play and see which concrete parts I can push or are blockers for this, Help is welcome |
|
Update: I implemented another Playground project but this time allowing users to experience TypeScript editor with autocompletion, type-checking and online docs (consuming the TS output of mirada) : https://cancerberosgx.github.io/demos/mirada-ts-playground (tested only in chrome and firefox so far) It uses monaco-editor (the same as vscode's) and consumes typescript declaration files that are automatically generated from opencv sources by this auxiliary tool of mine: https://github.com/cancerberoSgx/mirada/tree/master/doxygen2typescript It currently consumes doxygen xml output. The only hack I made was to filter the content using bindings.cpp since the docs are huge and the js biuld only support a fraction of it. The rest mostly is XML paring, templates and a a couple of TypeScript AST manipulations at the end. These are examples of the generated typescript declarations processed with jsdoc rendering tools - I didn't put much effort on them since I'm only interested in the editor/type checking experience but just for you to see the current status/quality:
Although there are some details still, (mostly with references, enum types and formula rendering) I'm quite happy with it and now I'm it'm using it successfully to learn the library's API since I'm actually totally new with it) . Probably in editor-consumable documentation/type-declarations (which is my target) I should use shorter descriptions, but for now (and for me) I'm dumping the whole thing.) I'm porting examples while I learn and use them library tests/ CI or in the playground and I must say the port of examples in general is quite straight forward (and surprisingly easier from C++) - I think I cover in most of the use cases shown in the tutorials. Nevertheless I will keep adding more as I learn. As I said, I have suggestions for the js build that I will try to translate to PRs, right now I prefer to learn and enjoy a little bit more before that, and wanted to give this update just in case anybody has some opinions / feedback. I'm sorry for taking this issue mostly to discuss with myself before I have a PR proposal or a concrete contribution. Thanks |
|
This is really awesome, do you think you could do an example with SolvePnP and maybe Aruco markers? It would also be really nice if we could use this in both the browser and React Native or Native Script. |
Sure if build supports them I will try. I recently attempted to add the module ml (machine learning) in the js build and although it is included by cmake it is not published in the global Module variable. I wonder if you know about any documentation about this topic since I'm kind lost here and would be awesome to try ml and other more training-oriented modules in the browser and node.js.
I'm running the tests in node.js - about those two technologies I don't really know them, but if they are oriented toward small devices (and performance/battery is important) I would use the c++/python versions not this one. Specially if you execute it as a command line since Also since this project has so little JS implementation it would be interesting to try https://docs.assemblyscript.org/ or similar to generate also compile the browse clue code r and user's as webassembly altogheter. I will try to test things like https://github.com/as2d/as2d to see how/if this kind of things can be (ever used them) although I don't know if these things are related to React Native or Native Script - will let you know, thanks |
Although I never tried, emcc has some support for dynamic linking, They say is still experimental and has some impact on the speed : * https://emscripten.org/docs/compiling/Building-Projects.html#dynamic-linking * https://github.com/emscripten-core/emscripten/wiki/Linking
Then, emcc also supports this, which again I have no experience with: https://emscripten.org/docs/optimizing/Optimizing-Code.html#very-large-codebases ? what's your concern ? code size ? Do you think tree shaking you mention could improve also speed in this case? I have previous experience but only with WASM before, and here I suspect parsing such a big JavaScript is expensive for the browser. I tried without luck to build the .wasm I think should improve parsing at least, but I didn't had much time. Also I notice emcc uses only -O2 and -NO_exceptions by default. I wonder why not -O3 and if somebody tried the other optimization flags. Do you now if there is some benchmark that makes sense in JS to compare ? Also a question, ImageMagick which targets a similar area, has two important compile flags that let you trade off between processing speed, memory and image output quality / match precision. The first flag impacts memory while this second flag impacts speed. just in case I want to know if there are any similar settings in opencv build ? Thanks |
There is an issue working through adding new modules to the build. That is about SolvePnP and some other calib modules, but if one is able to add those, then the ML modules shouldn't be that much different. |
|
Considering there hasn't been any change in the linked projects in ~15 months, I feel like it would be better to simplify the scope and just use what is already available, instead of trying to make everything perfect from the start. Considering people do use the pre-built opencv.js directly, we could start with that, so the contents would be
This setup doesn't really add anything extra (other than types which don't impact runtime or when using just JS). Then at later time other things mentioned in the comments here can be addressed:
So the current questions I have are:
|
|
I think you're right @peteruhnak if we could get something, that's better than nothing. What you have sounds good. I would say let's just put the JS files in a release, all the other files are just extra and not really needed. In the next releases, we can focus on Tree-Shaking and the other optimizations above. |
|
Completely agree: we could cut development times making it available as it is. |
|
I don't think this was mentioned above already. I don't know much about it, but stumbled across this npm package + this issue while searching for a solution myself. Last release was 10 months ago, so may not be maintained, but might provide some solutions aligned to this thread:
https://github.com/echamudi/opencv-wasm seems to have been updated in January
Though echamudi/opencv-wasm#9 suggests that it's not currently optimised for a web environment. |
|
https://github.com/CezaryDanielNowak/fast-opencv-wasm |
|
@CezaryDanielNowak sadly doesn't run in Electron ( neither main or render process, opencv is just not initialized) ( same as https://github.com/echamudi/opencv-wasm) |
I see there's no package for opencv.js so JavaScript users can install it using
npm installas is accustomed by JS users.The benefits of this would be also that is better integrated with web bundlers like webpack, parcel, browserify which simplify development workflow used in generally for web development.
I think for supporting this, the .wasm version could be better. BTW the current open.js file, although it works since it supports UMD, it would not be the best since it will be combined by bundlers (so the resulting .js file will contain it and will be huge bloking the user's apps). Instead it should be downloaded separately optionally allowing users to define an alternative url for it (like a CDN).
I'm working on a proof f concept for this, and also to support / tests for node.js as API and a little CLI tool too, and I wonder if something like this would be accepted as a PR to at least start the discussion.
Thanks
The text was updated successfully, but these errors were encountered: