I'm using Raspberry Pi 4 Model B with Pi camera module v3, I'm trying to launch an RTSP stream server that streams camera feed, I've been using this RTSP library, when I run the server script :
import cv2
from zephyr import Stream
if __name__ == "__main__":
stream = Stream(
url="rtsp://localhost:8554/test",
resolution=(1280, 720),
fps=30,
bitrate="2M"
)
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
stream.send(frame)
I get :
Traceback (most recent call last):
File "/home/pi/testserver1.py", line 15, in <module>
stream.send(frame)
File "/home/pi/innov/venv/lib/python3.11/site-packages/zephyr/stream/stream.py", line 174, in send
frame = cv2.resize(frame, self.resolution)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cv2.error: OpenCV(4.8.1) /io/opencv/modules/imgproc/src/resize.cpp:4062: error: (-215:Assertion failed) !ssize.empty() in function 'resize'
even though my camera is detected :
(venv) pi@YassinePi:~ $ libcamera-still --list-cameras
Available cameras
-----------------
0 : imx708 [4608x2592 10-bit RGGB] (/base/soc/i2c0mux/i2c@1/imx708@1a)
Modes: 'SRGGB10_CSI2P' : 1536x864 [120.13 fps - (768, 432)/3072x1728 crop]
2304x1296 [56.03 fps - (0, 0)/4608x2592 crop]
4608x2592 [14.35 fps - (0, 0)/4608x2592 crop]
I've tried changing the index from 1,-1,2 didn't work
I think it may be because this code is designed for desktop computers, or I didn't install the required packages correctly
For the second reason since I don't have experience with Raspbian OS, I reinstalled the OS and installed the packages all over again, still doesn't work.
Any idea how to solve this issue? Or there is an alternative way to do this?
OpenCV expects proper V4L devices.
libcameradoes not do that.libcamerais special. You need to uselibcamerainstead of OpenCV to read from your camera.There is at least one library that provides libcamera access in Python.