justadudewhohacks / justadudewhohacks/opencv4nodejs
VideoCapture::New - failed to open capture
- Dominant language
- C++
- Stars
- 5.1k
- Forks
- 826
- PR merge metrics
- No merged PRs in 30d
Description
I am unable to get the videocapture function to work. It always returns the error `VideoCapture::New - failed to open capture`. Using a device of 0 will not work. When I get the devices with `navigator.mediaDevices.enumerateDevices()` It shows my camera as an object.  When I do `lsusb` in terminal I also am able to see the camera (id 007)
I have tried to call use device ids 0 to 10 and none work. When I try and use the id from navigator.mediaDevices.enumerateDevices(), it also doesn't work. How am I suppose to set up video caputre using a camera? If it wasn't clear I am on linux and using electron.
I have also tried using navigator.mediaDevices.getUserMedia() with this code and it doesn't work:
```JavaScript
navigator.mediaDevices.getUserMedia({
video: {
// Is device id from navigator.mediaDevices.enumerateDevices()
deviceId: $('#cameraSelect').val()
},
audio: false,
}).then(stream =>{
let vidUrl = URL.createObjectURL(stream); // Outputs Blob Url
capDevice = cv.VideoCapture(vidUrl);
}
});
```
It says cv.VideoCapture() takes a url. I assume the url can't be a blob url because this also creates the same error.
Update: I tried doing it the way opencv.js does it with a object using this code:
```Javascript
navigator.mediaDevices.getUserMedia({
video: {
deviceId: $('#cameraSelect').val()
},
audio: false,
}).then(stream =>{
let video = document.getElementById("camera");
video.srcObject = stream;
video.play();
capDevice = cv.VideoCapture(video);
});
```
This also didn't work. Everything I try leads back to the error:
```
Uncaught (in promise) Error: VideoCapture::New - expected arg 0 to be path or device port
at Object.setCamera (/home/kol/Desktop/signLanguageDetection/js/camera.js:24)
at navigator.mediaDevices.getUserMedia.then.stream (main.js:25)
at
```
Contributor guide
Assessment
This issue has not been assessed yet.