opencv-electron icon indicating copy to clipboard operation
opencv-electron copied to clipboard

opencv4nodejs with electron setup

Open komalpharate opened this issue 7 years ago • 16 comments

Hi, I need help on how to setup electron with opencv4nodejs. Scenario: I have some nodejs code using opencv4nodejs. Now I want to add electron on top of that. Can I know steps to do that?` Thanks

komalpharate avatar Feb 23 '18 06:02 komalpharate

Hi,

I am not sure if I get the question correctly. You should be able to do that, this repo gives you an example how to achieve that.

justadudewhohacks avatar Feb 23 '18 09:02 justadudewhohacks

I have nodejs code with some modules like opencv4nodejs,fs,etc. Now I want to do is, use electron, create an html page, submit some info, and start my nodejs server(I have done this part but want to combine with my nodejs code now). what are the changes or installations i need to do for that? like as mentioned on opencv4nodejs page Add the following script to your package.json:

"electron-rebuild": "electron-rebuild -w opencv4nodejs" Run the script:

$ npm run electron-rebuild Require it in the application:

const cv = require('opencv4nodejs');

these are the only steps?

komalpharate avatar Feb 26 '18 12:02 komalpharate

Yes these are the only steps. Well with electron you don't need a nodejs server, you can use the opencv4nodejs code directly in your electron application, like I did in this example.

If you want to keep your server which runs all the OpenCV related code then you don't need electron and can simply build a webpage, which interacts with your server via an API.

The point of using electron is to build desktop apps with html, css and js, similar to web development, but you are not limited to capabilities of a browser.

justadudewhohacks avatar Feb 26 '18 12:02 justadudewhohacks

Actually I'm restricted to use electron only. That is why. One more doubt is , performance of opencv4nodejs gets affetcted by using electron?

komalpharate avatar Feb 26 '18 12:02 komalpharate

There shouldn't be much of a difference in performance.

justadudewhohacks avatar Feb 26 '18 12:02 justadudewhohacks

Hi, I installed electron and done the implementation mentioned above. I'm getting VideoCapture Issue: Error: VideoCapture::New - failed to open capture at Timeout._onTimeout (...../liveStreamingController.js:59:24) at ontimeout (timers.js:386:14) at tryOnTimeout (timers.js:250:5) at Timer.listOnTimeout (timers.js:214:5)_

whereas, the same code works without using electron pretty well.

komalpharate avatar Feb 27 '18 08:02 komalpharate

Are you trying to open a webcam stream or a video file? In the latter case I would assume that the path to the file is simply wrong. Try to resolve the absolute path to your file using path.resolve.

justadudewhohacks avatar Feb 27 '18 08:02 justadudewhohacks

videosource is rtsp url camera

I didn't get this::

In the latter case I would assume that the path to the file is simply wrong. Try to resolve the absolute path to your file using path.resolve.

komalpharate avatar Feb 27 '18 09:02 komalpharate

Also.. I just want to mention.. Other node modules works fine with electron Just opencv4nodejs doesn't seem to work with electron in my case. And, the issue is with Videocapture function especially.

komalpharate avatar Feb 27 '18 11:02 komalpharate

Hm I see. Well as I said in the other issue, I am not familar with rtsp. So opening the stream works from a nodejs server, but not from electron. Did you try to open the stream from a simple script/ not from a nodejs server?

I tried to open a VideoCapture to an example endpoint in electron and atleast it does not fail opening the capture.

justadudewhohacks avatar Feb 28 '18 10:02 justadudewhohacks

Yes. I tried opening the stream using PythonOpenCV, CPP OpenCV, Gstreamer tools, ffmpeg, opencv4nodejs module, opencv-npm module. All works fine. Can I know the code you used to do open a VideoCapture?

komalpharate avatar Mar 01 '18 06:03 komalpharate

I simply did call the constructor with the rtsp endpoint of an example video file: var cap = new cv.VideoCapture('rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov'). However reading from this example endpoint gave me empty images, so not sure if there is something wrong with the endpoint or if I did something wrong. Didn't find a useful endpoint for testing in the hurry. But it did not crash in the constructor while opening the capture as in your case.

justadudewhohacks avatar Mar 01 '18 09:03 justadudewhohacks

@justadudewhohacks here's a test link, rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov my auto build opencv4nodejs cannot open this link but my VLC player can, could someone test this with var cap = new cv.VideoCapture('rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov') and let me know the results? thanks!

xyx2011 avatar Aug 16 '18 16:08 xyx2011

I too have the same issue when trying to open an RTSP stream through Video capture. Electron crashes. Any help in this regard will be very helpful.

bhupathyap avatar Sep 25 '18 07:09 bhupathyap

Hi, I couldnt solve the bug so had to remove electron.

komalpharate avatar Sep 25 '18 08:09 komalpharate

May this help someone, https://questnr.com/post/brijeshlakkad_this-will-cover-things-one--4941681633657222177-48908

I had so many errors during this. I have made this blog so that anyone who has trouble will be able to solve it.

Brijeshlakkad avatar Aug 05 '20 07:08 Brijeshlakkad