简体   繁体   中英

OpenCV.js is not working vue.js (electron-builder)

I am working on a project with electron and vuejs (i am using vue-cli-plugin-electron-builder) and I require real time face detection system the fastest and most effective solution so far is OpenCV.js (i have done my research).

The problem that i have been facing is according to the OpenCV.js Docs we need to add the script tag to the html file like,

<script async src="https://docs.opencv.org/master/opencv.js" onload="onOpenCvReady()" type="text/javascript"></script>

I have tested it and it works fine only if I turn off nodeIntegration in electron window. But this is not possible because the electron-builder plugin works only if the nodeIntegrations are turned on.

new BrowserWindow({
    webPreferences: {
        nodeIntegration: true // I need this but i also need opencv
                              // but opencv is not working if i turn it off.
    }
})

Secondly, should I keep using electron or move to NW.js i have noted that the build size of electron.js are huge.

First of all, the following statement is not true:

electron-builder plugin works only if the nodeIntegrations are turned on.

In fact, nodeIntegration is going to be disabled in electron-builder v2.0 by default.

Now let's get to the point. Do not download anything using a <script> tag, if you do this, every time a user opens the app, it will download the script. What you should do is to install all the node modules during development, so that everything comes with the app.

To use opencv in Electron, you can simply Install this npm module . Check out the example on how to use it in Electron.

If that module doesn't work for you, try this npm module and follow the opencv docs if needed.

And to answer your question about NW.js, it depends on your needs. Google the differences between Electron and NW.js and decide what you want to use for your app. In short, Electron is more powerful and more secure, even if the app takes up 200mb more on the drive, it's still a better option. Besides, who cares if the build is 400mb in size? It's not 2010, nowadays most people who's going to use your app in the first place, most likely have half a terrabyte of free space on their drives.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM