简体   繁体   English

OpenCV.js 不工作 vue.js (electron-builder)

[英]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).我正在使用 electron 和 vuejs(我正在使用 vue-cli-plugin-electron-builder)进行一个项目,我需要实时人脸检测系统,到目前为止最快和最有效的解决方案是 OpenCV.js(我已经完成了我的研究).

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,我一直面临的问题是根据 OpenCV.js 文档,我们需要将脚本标记添加到 html 文件中,例如,

<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.我已经测试过它,只有当我在 electron window 中关闭 nodeIntegration 时它才能正常工作。但这是不可能的,因为 electron-builder 插件只有在打开 nodeIntegrations 时才能工作。

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.其次,我应该继续使用 electron 还是转移到 NW.js 我已经注意到 electron.js 的构建大小很大。

First of all, the following statement is not true:首先,下面的说法是不正确的:

electron-builder plugin works only if the nodeIntegrations are turned on. electron-builder 插件仅在打开 nodeIntegrations 时才有效。

In fact, nodeIntegration is going to be disabled in electron-builder v2.0 by default.事实上,默认情况下, nodeIntegrationelectron-builder v2.0中将被禁用。

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.不要使用<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 .要在 Electron 中使用 opencv,只需安装这个 npm 模块即可。 Check out the example on how to use it in Electron.查看 Electron 中有关如何使用它的示例

If that module doesn't work for you, try this npm module and follow the opencv docs if needed.如果该模块不适合您,请尝试使用此 npm 模块并在需要时遵循 opencv文档

And to answer your question about NW.js, it depends on your needs.并回答你关于 NW.js 的问题,这取决于你的需要。 Google the differences between Electron and NW.js and decide what you want to use for your app. Google 一下 Electron 和 NW.js 之间的区别,然后决定你想为你的应用使用什么。 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.简而言之,Electron 更强大,更安全,即使该应用程序在驱动器上多占用200mb ,它仍然是一个更好的选择。 Besides, who cares if the build is 400mb in size?此外,谁在乎构建大小是否为400mb 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.现在不是 2010 年,现在大多数首先要使用您的应用程序的人,最有可能在他们的驱动器上有 0.5 TB 的可用空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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