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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance question for NodeJs #36

Open
bartbutenaers opened this issue Oct 22, 2017 · 4 comments
Open

Performance question for NodeJs #36

bartbutenaers opened this issue Oct 22, 2017 · 4 comments

Comments

@bartbutenaers
Copy link

Dear,

I started yesterday developing a Node-Red contribution, to allow OpenCv.js to be used in our dataflows. Must admit that I'm new to OpenCv, but I'm already very enthousiastic about this project!

I tried the Canny Edge Detection example from npm, but the performance was not really what I expected. I executed the tests on my Raspberry Pi 3 running NodeJs version 7.9.0.

Issue 1 - descending execution duration

I repeated the same test (on the same image) a couple of times, and the execution durations were descending (and becoming rather stable after about 3 tests):

  • 8631 millisecs
  • 1333 millisecs
  • 1103 millisecs
  • 591 millisecs
  • 568 millisecs

And even the CPU consumption was descending:

image

Does this make any sense?

Issue 2 - high execution duration

Don't know about native OpenCv performance, but for example on this forum I found following measurement:

A pure OpenCV VideoCapture vc(0) grabbing loop (no display, no waitKey) gets about 30 fps at 640x480 with nearly no CPU load. Adding a Canny edge filter, I still get 30 fps at 640x480 but CPU load increases to 250% (out of the 400% for all cores).

I realize that (w)asm is slower than native C++, but are my execution times normal? If not normal, is there any kind of troubleshooting I can do to find the root cause?

I would also have expected that more CPU would be used in this case, but it seems only a single core is being used. Hopefully somebody can help me out ...

Thanks a lot !!!
Bart Butenaers

@bartbutenaers
Copy link
Author

Hi,

forgot to mention that I used the same input image as in the tutorial, which has even a lower resolution (402x402) as in the forum link above.

Could the cause be:

  • My node js version doesn't support asm or wasm?
  • My node js doesn't detect that it is asm, and runs it as normal Javascript? Or is that not possible?
  • The native code uses some kind of hardwared acceleration, and OpenCv.js not?
  • ...

Kind regards,
Bart

@drhouse82
Copy link

Hi,

first off, I'm also not an expert.

Do you use the wasm or asm.js version? In this repo, there is only the asm.js version.
The wasm version can be found in njor's fork or in his pull request #20 . (Please up-vote his PR...)
There, you have to include cv-wasm.js instead of cv.js, otherwise it works identically.

Webassembly should be a bit faster than asm.js.
Moreover, asm.js is fully compatible with (slow) standard javascript. Hence, if you include the wasm version instead, you can be sure your node supports wasm, otherwise it wont work at all (wheras the asm.js version might work and be excecuted as standard js).

Best
Joe

@bartbutenaers
Copy link
Author

Hi Joe,

Thanks for your help!!
Indeed I have no idea if the asm.js version is executed by NodeJs as standard slow Js.

It seems a good suggestion to use the PR (which I have voted).
But when I replace my opencv.js file (which I have installed via 'npm install opencv.js') by the cv-wasm.js file (from the PR), the 'var cv = require('opencv.js');' statement in my code now results in following error:
ReferenceError: Module is not defined
Do you perhaps have any idea how I can get around this?

And I also don't understand why - in case of WebAssembly - the xxx.js need to be loaded instead of the xxx.wasm file, like they do here.

Thanks again,
Bart

@drhouse82
Copy link

Hi,

hm... I'm not sure about node. I have only used it on the clientside.
I used <script src="cv.js"></script> for the asm.js version. In addition, the file cv.data was required.
For the wasm version, I used <script src="cv-wasm.js"></script>, and additional files cv-wasm.data and cv-wasm.wasm were required.

I think you load the js because it contains the module structure.

I think, this will be different in node and I'm also not perfectly sure if the version you obtained via npm is the same as the one in this repo. I just realized, that now also in the official opencv repo there is a js build version and a js tutorial, which appear to be related to but maybe newer/more active than this repository.

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

2 participants