i have a problem with using video streams in node js with the use of opencv4nodejs my code looks like this:
const cv = require('opencv4nodejs');
const { spawn } = require('child_process');
async function detectPersons() {
const camera = new cv.VideoCapture(0); // Anpassen je nach Kameraquelle
const window = new cv.Window('Person Detection', 0);
const pipelineString = `nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)640, height=(int)480, format=(string)NV12, framerate=(fraction)30/1 ! nvvidconv ! video/x-raw, width=(int)640, height=(int)480, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink`;
const detectProcess = spawn('gst-launch-1.0', ['-e', pipelineString]);
detectProcess.stdout.on('data', (data) => {
const detectionOutput = data.toString();
console.log(detectionOutput);
if (detectionOutput.includes('person')) {
// Hier kannst du Code hinzufügen, um auf die Erkennung zu reagieren.
console.log('Person erkannt!');
}
});
detectProcess.stderr.on('data', (data) => {
console.error(`Fehler: ${data}`);
});
detectProcess.on('close', (code) => {
console.log(`Prozess beendet mit Code ${code}`);
});
while (true) {
const cameraFrame = camera.read();
if (cameraFrame.empty) {
break;
}
const classifier = new cv.CascadeClassifier(cv.HAAR_FRONTALFACE_ALT2);
const detectedObjects = classifier.detectMultiScale(cameraFrame);
detectedObjects.forEach(obj => {
const { x, y, width, height } = obj;
cameraFrame.drawRectangle(new cv.Rect(x, y, width, height), new cv.Vec(0, 255, 0), 2);
});
window.imshow(cameraFrame);
const key = cv.waitKey(10);
if (key === 27) {
// Press ESC to exit
break;
}
}
camera.release();
window.destroy();
}
detectPersons();
and my error message looks like this:
(node:23722): GStreamer-CRITICAL **: 10:31:02.124: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed
(node:23722) UnhandledPromiseRejectionWarning: TypeError: cv.Window is not a constructor
at detectPersons (/home/xadmin/nodetrackig/index.js:7:20)
at Object.<anonymous> (/home/xadmin/nodetrackig/index.js:62:1)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
(node:23722) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:23722) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
it would be a great help if someone can help me get a video stream. As info I have with an elgato cam link a gopro connected to a usb port and can in the browser me also display the only in node js I have problems. and when I with ls -l /dev/video* look three pieces of 0 -2 although I have only one camera connected. you to add that it was not possible for me to install a higher node version than 8.5.
LG ZERO