Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working with Electron #4

Closed
zcmgyu opened this issue Jan 20, 2022 · 28 comments
Closed

Working with Electron #4

zcmgyu opened this issue Jan 20, 2022 · 28 comments

Comments

@zcmgyu
Copy link

zcmgyu commented Jan 20, 2022

I know that this repo is not working with Electron. Do you have any suggestions to do that? I would like to join to contribute as well. Thank you in advance. 馃檱

@UrielCh
Copy link
Owner

UrielCh commented Jan 21, 2022

Hi,

After some test, I'm locked to electron V8.
the blocking breaking change is this one
Discussion about this change is here

I'm not a C++ expert, I have bad time trying to configure my .vscode/c_cpp_properties.json to be able to make heavy changes to the project.

If you have some expertise about that you're welcome.

@zcmgyu
Copy link
Author

zcmgyu commented Jan 22, 2022

@UrielCh

Timeline
Land the app.allowRendererProcessReuse option in Electron 6
Have the first deprecation warning land in Electron 7 for non-context aware native modules
Have a deprecation warning land in Electron 8 for the default value of app.allowRendererProcessReuse to switch
Switch the default value of app.allowRendererProcessReuse to true in Electron 9
Deprecate the ability to change app.allowRendererProcessReuse in Electron 10
Remove the ability to change app.allowRendererProcessReuse in Electron 14

Based on the above timeline, after explicit disable allowRendererProcessReuse in main.js. It worked on versions 9.x and 10.x. I have no idea why it doesn't work from version 11 while it will have been deleted from version 14.

app.allowRendererProcessReuse = false; 

I've not worked on C++, but I'm trying some suggestions got from this topic. electron/electron#18397

PS: Checking on macOS

@UrielCh
Copy link
Owner

UrielCh commented Jan 22, 2022

@u4/opencv4nodejs@6.0.9 is out and fix electron 9 issue.
and it works without setting allowRendererProcessReuse to false.
next breaking change

Another implication is that require() cannot be used in the renderer process unless nodeIntegration is true and contextIsolation is false.

I think you know electron better than me, I do not know anything about Electron rendering thread, and non-rendering thread.

@zcmgyu
Copy link
Author

zcmgyu commented Jan 22, 2022

@UrielCh I attempted @u4/opencv4nodejs@6.0.9 for opencv-electron@11.5.0. I got an error message while running electron-rebuild command.
Enable --vscode argument got weird output message, and opencv4nodejs.node is not generated.
https://gist.github.com/zcmgyu/2f09fefa3f6152a47508a41ac9f181bd

I will invest more time tomorrow. Thank you in advance.

@UrielCh
Copy link
Owner

UrielCh commented Jan 22, 2022

[--vscode] is only a helper to build a visual studio code C++ environment, and the generated config is still uncomplete.

so it's useless for your usage, I'm now diving into the C code of the project, I have started a new module Highgui.

currently, my c_cpp_properties.json is:

        {
            "name": "opencv4nodejs",
            "includePath": [
              // "${workspaceFolder}/cc/**",
              "C:/Users/uriel/AppData/Local/node-gyp/Cache/16.13.1/include/node",
              "C:/0/openCV/opencv-4.5.5/build/",
              "C:/0/openCV/opencv-4.5.5/build/include",
              "${workspaceFolder}/node_modules/nan",
              "${workspaceFolder}/node_modules/native-node-utils/src",
              "${workspaceFolder}/cc",
              "${workspaceFolder}/cc/core",
              "C:/0/openCV/opencv-4.5.5/opencv/modules/calib3d/include",
              "C:/0/openCV/opencv-4.5.5/opencv/modules/core/include",
              "C:/0/openCV/opencv-4.5.5/opencv/modules/dnn/include",
              "C:/0/openCV/opencv-4.5.5/opencv/modules/features2d/include",
              "C:/0/openCV/opencv-4.5.5/opencv/modules/flann/include",
              "C:/0/openCV/opencv-4.5.5/opencv/modules/gapi/include",
              "C:/0/openCV/opencv-4.5.5/opencv/modules/highgui/include",
              "C:/0/openCV/opencv-4.5.5/opencv/modules/imgcodecs/include",
              "C:/0/openCV/opencv-4.5.5/opencv/modules/imgproc/include",
              "C:/0/openCV/opencv-4.5.5/opencv/modules/ml/include",
              "C:/0/openCV/opencv-4.5.5/opencv/modules/objdetect/include",
              "C:/0/openCV/opencv-4.5.5/opencv/modules/photo/include",
              "C:/0/openCV/opencv-4.5.5/opencv/modules/stitching/include",
              "C:/0/openCV/opencv-4.5.5/opencv/modules/ts/include",
              "C:/0/openCV/opencv-4.5.5/opencv/modules/video/include",
              "C:/0/openCV/opencv-4.5.5/opencv/modules/videoio/include",
              "C:/0/openCV/opencv-4.5.5/opencv/modules/world/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/alphamat/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/aruco/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/barcode/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/bgsegm/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/bioinspired/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/ccalib/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/cnn_3dobj/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/cudaarithm/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/cudabgsegm/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/cudacodec/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/cudafeatures2d/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/cudafilters/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/cudaimgproc/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/cudalegacy/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/cudaobjdetect/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/cudaoptflow/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/cudastereo/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/cudawarping/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/cudev/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/cvv/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/datasets/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/dnn_objdetect/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/dnn_superres/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/dpm/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/face/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/freetype/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/fuzzy/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/hdf/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/hfs/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/img_hash/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/intensity_transform/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/julia/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/line_descriptor/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/matlab/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/mcc/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/optflow/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/ovis/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/phase_unwrapping/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/plot/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/quality/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/rapid/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/reg/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/rgbd/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/saliency/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/sfm/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/shape/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/stereo/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/structured_light/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/superres/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/surface_matching/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/text/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/tracking/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/videostab/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/viz/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/wechat_qrcode/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/xfeatures2d/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/ximgproc/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/xobjdetect/include",
              "C:/0/openCV/opencv-4.5.5/opencv_contrib/modules/xphoto/include"
            ],
            "defines": [
              "CV_VERSION_MAJOR=4",
              "CV_VERSION_MINOR=5",
              "CV_VERSION_REVISION=5",
              "OPENCV4NODEJS_FOUND_LIBRARY_CORE",
              "OPENCV4NODEJS_FOUND_LIBRARY_HIGHGUI",
              "OPENCV4NODEJS_FOUND_LIBRARY_IMGCODECS",
              "OPENCV4NODEJS_FOUND_LIBRARY_IMGPROC",
              "OPENCV4NODEJS_FOUND_LIBRARY_FEATURES2D",
              "OPENCV4NODEJS_FOUND_LIBRARY_CALIB3D",
              "OPENCV4NODEJS_FOUND_LIBRARY_PHOTO",
              "OPENCV4NODEJS_FOUND_LIBRARY_OBJDETECT",
              "OPENCV4NODEJS_FOUND_LIBRARY_ML",
              "OPENCV4NODEJS_FOUND_LIBRARY_VIDEO",
              "OPENCV4NODEJS_FOUND_LIBRARY_VIDEOIO",
              "OPENCV4NODEJS_FOUND_LIBRARY_DNN",
              "OPENCV4NODEJS_FOUND_LIBRARY_FACE",
              "OPENCV4NODEJS_FOUND_LIBRARY_TEXT",
              "OPENCV4NODEJS_FOUND_LIBRARY_TRACKING",
              "WIN",
              "_HAS_EXCEPTIONS=1"
            ],
            "windowsSdkVersion": "10.0.19041.0",
            "compilerPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30133\\bin\\Hostx64\\x64\\cl.exe",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "intelliSenseMode": "windows-msvc-x64"
          }

It looks to works on my Windows Desktop.

@UrielCh
Copy link
Owner

UrielCh commented Jan 22, 2022

I will invest more time tomorrow. Thank you in advance.

Are you really a code addict?

@zcmgyu
Copy link
Author

zcmgyu commented Jan 24, 2022

@UrielCh LMAO, pretty addict.
I still figure out the issue for electron-rebuild on electron@11

@zcmgyu
Copy link
Author

zcmgyu commented Jan 24, 2022

Error output:

ERR! install electron-rebuild failed and return Error Command failed: electron-rebuild rebuild --jobs max
ERR! install - Searching dependency tree
ERR! install In file included from ../cc/opencv4nodejs.cc:1:
ERR! install In file included from /Users/hc499/.electron-gyp/11.5.0/include/node/node.h:67:
ERR! install In file included from /Users/hc499/.electron-gyp/11.5.0/include/node/v8.h:30:
ERR! install /Users/hc499/.electron-gyp/11.5.0/include/node/v8-internal.h:418:38: error: no template named 'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'?
ERR! install             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
ERR! install                                 ~~~~~^~~~~~~~~~~
ERR! install                                      remove_cv
ERR! install /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/type_traits:710:50: note: 'remove_cv' declared here
ERR! install template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
ERR! install                                                  ^
ERR! install In file included from ../cc/opencv4nodejs.cc:2:
ERR! install In file included from ../cc/ExternalMemTracking.h:1:
ERR! install In file included from ../cc/macros.h:1:
ERR! install In file included from /Users/hc499/Documents/LongWorkSpace/Dockyard/research/opencv4nodejs/node_modules/native-node-utils/src/NativeNodeUtils.h:1:
ERR! install In file included from /Users/hc499/Documents/LongWorkSpace/Dockyard/research/opencv4nodejs/node_modules/native-node-utils/src/AbstractConverter.h:1:
ERR! install In file included from /Users/hc499/Documents/LongWorkSpace/Dockyard/research/opencv4nodejs/node_modules/native-node-utils/src/utils.h:3:
ERR! install In file included from ../node_modules/nan/nan.h:2884:
ERR! install ../node_modules/nan/nan_typedarray_contents.h:34:43: warning: 'GetContents' is deprecated: Use GetBackingStore. See http://crbug.com/v8/9908. [-Wdeprecated-declarations]
ERR! install       data   = static_cast<char*>(buffer->GetContents().Data()) + byte_offset;
ERR! install                                           ^
ERR! install /Users/hc499/.electron-gyp/11.5.0/include/node/v8.h:5349:3: note: 'GetContents' has been explicitly marked deprecated here
ERR! install   V8_DEPRECATE_SOON("Use GetBackingStore. See http://crbug.com/v8/9908.")
ERR! install   ^
ERR! install /Users/hc499/.electron-gyp/11.5.0/include/node/v8config.h:411:41: note: expanded from macro 'V8_DEPRECATE_SOON'
ERR! install #   define V8_DEPRECATE_SOON(message) [[deprecated(message)]]
ERR! install                                         ^
ERR! install 1 warning and 1 error generated.
ERR! install make: *** [Release/obj.target/opencv4nodejs/cc/opencv4nodejs.o] Error 1

Current research

nodejs/nan#892

I attempted to downgrade nan to v2.14.0 but not help.

Maybe the main issue came from native-node-utils

@zcmgyu
Copy link
Author

zcmgyu commented Jan 24, 2022

Updated:

Upgrade native-node-utils to the latest version (2.15.0) solved the issue. Got another error messages.

ERR! install electron-rebuild failed and return Error Command failed: electron-rebuild rebuild --jobs max
ERR! install - Searching dependency tree
ERR! install In file included from ../cc/opencv4nodejs.cc:1:
ERR! install In file included from /Users/hc499/.electron-gyp/11.5.0/include/node/node.h:67:
ERR! install In file included from /Users/hc499/.electron-gyp/11.5.0/include/node/v8.h:30:
ERR! install /Users/hc499/.electron-gyp/11.5.0/include/node/v8-internal.h:418:38: error: no template named 'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'?
ERR! install             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
ERR! install                                 ~~~~~^~~~~~~~~~~
ERR! install                                      remove_cv
ERR! install /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/type_traits:710:50: note: 'remove_cv' declared here
ERR! install template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
ERR! install                                                  ^
ERR! install 1 error generated.
ERR! install make: *** [Release/obj.target/opencv4nodejs/cc/opencv4nodejs.o] Error 1

@UrielCh
Copy link
Owner

UrielCh commented Jan 24, 2022

native-node-utils I miss this one ...

will I need to fork it to ...

@UrielCh
Copy link
Owner

UrielCh commented Jan 24, 2022

In my environment, the plain-js sample has no compilation issue.

It' also work using a local @u4/opencv4nodejs git project

mkdir workdir
cd workdir
clone git@github.com:UrielCh/opencv4nodejs.git
cd opencv4nodejs
npm install
npm run do-install
cd ..
clone git@github.com:UrielCh/opencv-electron.git
cd opencv-electron/plain-js
npm install ../../opencv4nodejs
npm install electron@11-x-y
npm install
npm run install
npm run start

my setup failed with npm install electron@12-x-y but only at runtime.

@zcmgyu
Copy link
Author

zcmgyu commented Jan 25, 2022

@UrielCh I've checked on 2 Macbooks (Intel chipset). The same issue, let me figure out.
https://gist.github.com/zcmgyu/a1590fdd9262097055386143e0f6d3c9

Could you please give me your version of Node?
I'm using

Node v14.18.1
npm 8.3.2

@zcmgyu
Copy link
Author

zcmgyu commented Jan 25, 2022

@UrielCh After changed "-std=c++11" to "-std=c++14" in _binding.gyp, it worked on NodeJS 14.

https://github.com/UrielCh/opencv4nodejs/blob/master/_binding.gyp

@zcmgyu
Copy link
Author

zcmgyu commented Jan 25, 2022

@UrielCh Now, get the new error on Electron 12

Output in Console:

Uncaught ReferenceError: require is not defined
at index.html:135

It may be related to this problem. I will check tomorrow.

electron/electron-quick-start#463 (comment)

@UrielCh
Copy link
Owner

UrielCh commented Jan 25, 2022

Uncaught ReferenceError: require is not defined
that is the error I have.
so we are synced now.

@UrielCh
Copy link
Owner

UrielCh commented Jan 25, 2022

So I should upgrade C++ build standard to C++14 ?
I stopped C++ in ... 2004, I'm outdated in C++.

@zcmgyu
Copy link
Author

zcmgyu commented Jan 25, 2022

@UrielCh Maybe I know how to fix it. Please wait for my Pull Request.

@zcmgyu
Copy link
Author

zcmgyu commented Jan 25, 2022

@UrielCh I've never ever worked on C++ before 馃槄

@UrielCh
Copy link
Owner

UrielCh commented Jan 25, 2022

@UrielCh Maybe I know how to fix it. Please wait for my Pull Request.

Okey, I switch to some VueJS project :)

@zcmgyu
Copy link
Author

zcmgyu commented Jan 26, 2022

@UrielCh Upgrade to C++14 standard in opencv4nodejs
#5

Also need to update version of opencv4nodejs in below repository before migrated as well.
UrielCh/opencv-electron#1

@UrielCh
Copy link
Owner

UrielCh commented Jan 26, 2022

6.0.10 is out.

@zcmgyu
Copy link
Author

zcmgyu commented Jan 27, 2022

@UrielCh I so appreciate your support. 馃檱 I hope that the community will be grown and you carry on to improve this great library.

@zcmgyu zcmgyu closed this as completed Jan 27, 2022
@UrielCh
Copy link
Owner

UrielCh commented Jan 28, 2022

As you may have noticed I only work in Typescript, So I tried to make webpack-reactjs-typescript work.

but I'm not familiar with React. I try to update the project:

  • update all the dependences.
  • update webpack.config

But I'm stuck with an Webpack Error:

You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| import * as OpenCV from '../..';

changes to webpack:
replace :
loader: ['react-hot-loader/webpack', 'ts-loader?configFile=tsconfig.json']
by
use: 'ts-loader',

replace:

   contentBase: path.join(__dirname, 'public'),

by

    static: {
      directory: path.join(__dirname, 'public'),
    },

replace:

  target: 'electron',

by

  target: 'electron-main',

@UrielCh UrielCh reopened this Jan 28, 2022
@zcmgyu
Copy link
Author

zcmgyu commented Jan 28, 2022

I'm working on ReactJS right now. Maybe I can help. I will deep dive in next week.

@UrielCh
Copy link
Owner

UrielCh commented Jan 28, 2022

did you find all the methods you need in opencv4nodejs?
Most of the methods I want are not been bound, and less than have of openCV are available.

and a lot's of method change from V3 to V4, so lots of methods are incorrectly mapped.

@zcmgyu
Copy link
Author

zcmgyu commented Jan 28, 2022

@UrielCh Currently, I'm working on templateMatching API. Everything almost worked now.

@UrielCh
Copy link
Owner

UrielCh commented Feb 21, 2022

since current electron versions Working.
it' time to close the issue

@UrielCh UrielCh closed this as completed Feb 21, 2022
@stoefln
Copy link

stoefln commented Nov 21, 2022

So is this fork of opencv4nodejs context-aware by now?
As stated here, Electron is not going to support non context-aware modules anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants