opencv: OpenCV does not work with new Raspberry Pi MIPI camera software stack
openCv python version 4.5.5. Camera module waveshare OV9281-110 I am working with raspberry-pi model 4-B with latest bullseye OS.
I am able to capture image using libcamera-still -o test.png command but when I try to read an image with opencv it returns None. The output for cam.isOpened() is true but cam.grab() and cam.read() return false and (false,None) respectively.
Code:
import cv2
cam_port = 0
cam = cv2.VideoCapture(cam_port)
print(cam.isOpened())
print(cam.grab())
print(cam.read())
cam.release()
Output:
True
False
(False, None)
camera info
~ $ v4l2-ctl --device /dev/video0 --all
Driver Info:
Driver name : unicam
Card type : unicam
Bus info : platform:fe801000.csi
Driver version : 5.15.56
Capabilities : 0xa5a00001
Video Capture
Metadata Capture
Read/Write
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x25200001
Video Capture
Read/Write
Streaming
Extended Pix Format
Media Driver Info:
Driver name : unicam
Model : unicam
Serial :
Bus info : platform:fe801000.csi
Media version : 5.15.56
Hardware revision: 0x00000000 (0)
Driver version : 5.15.56
Interface Info:
ID : 0x03000005
Type : V4L Video
Entity Info:
ID : 0x00000003 (3)
Name : unicam-image
Function : V4L2 I/O
Flags : default
Pad 0x01000004 : 0: Sink
Link 0x02000007: from remote pad 0x1000002 of entity 'ov9281 10-0060': Data, Enabled, Immutable
Priority: 2
Video input : 0 (unicam-image: ok)
Format Video Capture:
Width/Height : 640/480
Pixel Format : 'BGR3' (24-bit BGR 8-8-8)
Field : None
Bytes per Line : 1920
Size Image : 921600
Colorspace : sRGB
Transfer Function : sRGB
YCbCr/HSV Encoding: ITU-R 601
Quantization : Full Range
Flags
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 22 (9 by maintainers)
Hi! I am a contributor. I have a far shot to try if you want. Depending on the capabilities of the v4l2-device it might be possible to use the FFMPEG backend for capturing and that brings the ability to specify stream details via environment variable. There is an easy test:
If ffplay can read your video device like that, than It should be possible to use the FFMPEG backend like this:
Not yet for now. Please switch to legacy camera mode as work around till the issue is not fixed on our side.
I try to record a video cheese gets stuck - it’s expected behavior. Cheese uses CPU codec to encode video. It’s not capable to encode video on pi in real time. I just tried couple of my boards:
你们可以尝试使用 picamera2,请参考https://blog.csdn.net/zhangmou_9008/article/details/134047114上面的3.1 you kan try to use picamera2,please show the blog’s 3.1 :https://blog.csdn.net/zhangmou_9008/article/details/134047114
I found the same behaviour. Trying to fix the issue to have cv::VideoCapture usable without tricks.