Decreasing size of opencv.js

asked 2018-01-08 11:20:25 -0500

Hello there.

I'm trying to use Vue.js and webpack with opencv. I followed the tutorial in the docs to compile to js from sources. However, when I try to integrate the resulting js file, I'm getting a "javascript heap out of memory" error. The file works when used in a very simple server environment though. I tried increasing the heap, but the build won't ever finish. I have no idea how to resolve this issue, but to maybe decrease the size of the file. is there a way to pick which classes to compile into the js file? for example, I personally only need the image preprocessing stack. Besides that: Do i have to compile opencv to js or is there another source for a js implementation?

Any help would be greatly appreciated. Thx.

edit retag flag offensive close merge delete


btw, you can also use the prebuilt opencv.js and utils.js from the master docs

(it's still huge ! (~11mb))

berak gravatar imageberak ( 2018-01-09 03:24:53 -0500 )edit

Wow, thx! How did you find that? I can't find any path there other than your direct link.

ChrisMSurix gravatar imageChrisMSurix ( 2018-01-09 03:44:57 -0500 )edit

by following the js tutorial src code (there's an iframe for each example, and that has the links)

i also found an older, 3.3.0 version of opencv.js on my box, that only had 6.8 mb, so it has grown significantly with latest version !

berak gravatar imageberak ( 2018-01-09 03:53:32 -0500 )edit

@berak could you upload the older version of opencv.js, and send me download link please ?

Mustafa gravatar imageMustafa ( 2018-06-22 07:24:17 -0500 )edit

sorry, but i can't. (don't have any older version)

berak gravatar imageberak ( 2018-06-22 08:22:46 -0500 )edit

anyone got ant useful ideas on how to reduce the size of opencv.js? it's very big to be used on a mobile. I'm using very little of the total set of features so could cut down on it? it is minified though so pretty unintelligible on my end. thanks

GJ gravatar imageGJ ( 2018-10-19 10:39:02 -0500 )edit

Use a CDN like DropBox and cache repeated requests.

Newer versions may have improvements.

kpachinger gravatar imagekpachinger ( 2018-11-04 07:31:57 -0500 )edit

Interested to know if there is an answer to this. I am also using opencv.js in Vue, specifically single file components. There is also the problem with the emscripten runtime not loading but that’s another issue. (I got around that by including opencv in the index.html as opposed to importing it locally in the .vue file) In any case, once you got passed that, you still have the minor issue that your smallish app is now > 8MB in size

pfjf20 gravatar imagepfjf20 ( 2020-06-27 02:44:51 -0500 )edit

Harsh reality? Recently, another thread mentioned they compiled it at 2MB. You could run your own server and make a request if you must solve a filesize bottleneck... but Google and AWS also offer cloud services. It's not meant to be trivial or a one-liner!

kpachinger gravatar imagekpachinger ( 2020-07-01 03:11:49 -0500 )edit