TechStark / opencv-js

OpenCV JavaScript version for node.js or browser
Apache License 2.0
353 stars 31 forks source link

Does not work on electron main process. #69

Closed studentutu closed 5 days ago

studentutu commented 1 week ago

Good evening, I've tried to use it from the electron 25.0.1 ( Node.js v18.15.0) but every time openCVis initialized it dumps all of the js into console ( main console) and after all methods in openCV is not recognized ( probably failed to be loaded) Examples:

cv.getVersionString is not a function

Are there any workaround to skip dumping openCV logs into console? Should we initialize it separatly in Node environment?

studentutu commented 1 week ago

TypeError: cv.getAvailableBackends is not a function

Can't even initialize it using the actual openCv guide:

// Load opencv.js just like before but using Promise instead of callbacks:
function loadOpenCV() {
 return new Promise(resolve => {
 global.Module = {
 onRuntimeInitialized: resolve
 };
 global.cv = require("@techstark/opencv-js");
 });
}
studentutu commented 1 week ago

Changed import from import * as cv from to import cv from and now I receive different error: TypeError: opencv_js_1.default.getAvailableBackends is not a function

studentutu commented 1 week ago

If using directly without timeouts - I receive the following error:

Uncaught Error: Unhandled error. ({
  sender: EventEmitter {
    _events: [Object: null prototype] {},
    _eventsCount: 0,
    _maxListeners: undefined,
    send: [Function (anonymous)],
    sendSync: [Function (anonymous)],
    sendToHost: [Function (anonymous)],
    sendTo: [Function (anonymous)],
    invoke: [AsyncFunction (anonymous)],
    postMessage: [Function (anonymous)],
    [Symbol(kCapture)]: false
  },
  senderId: 0,
  ports: []
})
studentutu commented 1 week ago

same on the render process - cv is just not initialized

studentutu commented 1 week ago

@th-alexmak could you help find out why OpenCV is not initialized with electron? Both main and render process can't initialize opencv. I've even tried to build my own version - at the end - the same issue, opencv with wasm can't initialize for some reason.

Are there any debugging utilities to catch native initialization error? All i get is just missing functions....

studentutu commented 1 week ago

@UrielCh maybe you had a similar experience in the opencv4node? Could you help us find out the initialization error?

studentutu commented 6 days ago

@TechStark

studentutu commented 6 days ago

@ttt43ttt

ttt43ttt commented 6 days ago

@studentutu do you have an example project to reproduce the issue?

studentutu commented 5 days ago

@ttt43ttt here is https://github.com/studentutu/autoflow Feel free to ask questions. All you need is just node\npm\yarn

ttt43ttt commented 5 days ago

@studentutu There is no cv.getVersionString function (it should be removed from the TS declaration). Try cv.getBuildInformation().

studentutu commented 5 days ago
TypeError: Cannot convert "TypeError: opencv_js_1.default.getVersionString is not a function" to long
    at Object.toWireType (C:\Users\stude\Desktop\autoflow\node_modules\@techstark\opencv-js\dist\opencv.js:1:10183883)
    at Object.exceptionFromPtr (eval at new_ (C:\Users\stude\Desktop\autoflow\node_modules\@techstark\opencv-js\dist\opencv.js:1:10170916), <anonymous>:7:26)
    at Timeout._onTimeout (C:\Users\stude\Desktop\autoflow\src\dist\Main\testopencv.js:68:52)
    at listOnTimeout (node:internal/timers:569:17)
    at process.processTimers (node:internal/timers:512:7)

Node.js v18.15.0
error Command failed with exit code 7.
studentutu commented 5 days ago

oh yes it does work! Thank for pointing it out

studentutu commented 5 days ago

works in Main process