justadudewhohacks / justadudewhohacks/opencv4nodejs

Imencode - OpenCV Error: (!image.empty()) in imencode, in file... RPI4

Open
#859 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
5.1k
Forks
826
PR merge metrics
No merged PRs in 30d

Description

Hello. I'm trying to get a video stream behind the cameras on the RPI 4, but I'm getting the following error:
![photo_2022-10-30_14-31-08](https://user-images.githubusercontent.com/62442744/198878630-a28162d3-1c7f-4d75-9240-c056623b00a9.jpg)

Using the libcamera-hello command, the image is displayed. I suspect there may be an error in the camera's image format.
![photo_2022-10-30_14-34-31](https://user-images.githubusercontent.com/62442744/198878754-c3a63af4-afdb-4641-b60f-a4968d6ebebe.jpg)

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'));

Contributor guide

Open the contributing guide

Research direction

Start with the VideoCapture setup, Vcap.read(), and the cv2.imencode('.jpg', frame) call shown in the issue. Compare the captured frame behavior with the working libcamera-hello command and verify whether read() returns a usable image before encoding. Done means identifying the cause of the empty image and documenting or confirming a reproducible fix for the RPI4 setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, linux, node.js
Domain
computer-vision
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.