Imencode - OpenCV Error: (!image.empty()) in imencode, in file... RPI4
evgeniy-bondarenk0 opened this issue · 1 comments
Hello. I'm trying to get a video stream behind the cameras on the RPI 4, but I'm getting the following error:
Using the libcamera-hello command, the image is displayed. I suspect there may be an error in the camera's image format.
Platform: Raspbian Bullseye 11 (32-bit)
OpenCV: v4.5.5
NodeJS: v16
My code:
const cv2 = require('@u4/opencv4nodejs');
const path = require('path');
const express = require('express');
const app = express();
const server = require('http').Server(app);
const io = require('socket.io')(server);
app.set('view engine', 'ejs');
const FPS = 30;
const Vcap = new cv2.VideoCapture(0);
Vcap.set(cv2.CAP_PROP_FRAME_WIDTH, 300);
Vcap.set(cv2.CAP_PROP_FRAME_HEIGHT, 300);
app.get('/', async(req, res, next) => {
res.render('index');
});
let frame;
setInterval(() => {
frame = Vcap.read()
const image = cv2.imencode('.jpg', frame).toString('base64')
io.emit('image', image);
}, 1000 / FPS);
server.listen(3030, () => console.log('open up your browser'));
This repository is not maintained anymore, please use @u4/opencv4nodejs for a more active fork