opencv4nodejs icon indicating copy to clipboard operation
opencv4nodejs copied to clipboard

`@u4/opencv4nodejs` cannot be used in worker threads

Open mf-mitchelrydzynski opened this issue 1 year ago • 2 comments

Environment

  • opencv4nodejs: 6.5.2
  • openvc: 4.9.0
  • nodejs: 18.16.1
  • macos: sonoma 14.4.1

Description of Issue

I'm attempting to offload image processing to workers using the native worker_threads library. The first time my application starts up a worker, runs the computation, and cleans up the worker, things work great. However, the second attempt to do so causes my whole app to crash silently. I noticed that commenting out any imports of @u4/opencv4nodejs in the worker files allows them to start and terminate as often as I like without issue. Upon investigating, I found the below resources related to context aware c++ addons.

Additional Resources

  • https://github.com/justadudewhohacks/opencv4nodejs/issues/555 - same open issue in the upstream repo
  • https://github.com/nodejs/node/issues/21481 - closed issue in nodejs further describing the problem
  • https://nodejs.org/docs/latest-v10.x/api/addons.html#addons_context_aware_addons - relevant nodejs documentation
  • https://github.com/UrielCh/opencv4nodejs/issues/43 - open issue in this library, same fundamental problem showing up there because electron runs multiple node instances

Given the computationally intensive nature of image processing, supporting workers in order to not block the main thread seems like it should be a requirement for this library. Creating a long running subprocess is not an option for me due to memory constraints. Happy to provide any more info/help land on a solution. Thanks!

mf-mitchelrydzynski avatar May 07 '24 19:05 mf-mitchelrydzynski

Any news on this? Electron.js also dropped support for non-context-aware models, so I don't think opencv4nodejs can still run on current electron versions.

stoefln avatar Oct 14 '24 06:10 stoefln

Same question !! hope to support, after all, imwrite blocking is too long

https://github.com/UrielCh/opencv4nodejs/issues/148

rambo-panda avatar Oct 15 '24 14:10 rambo-panda